From 9ddb5f6f9a72503f4753aaea4c5daddd1d1dd527 Mon Sep 17 00:00:00 2001 From: delbertbeta Date: Sat, 28 Sep 2024 23:20:59 +0800 Subject: [PATCH] feat: add docker file and github actions --- .github/workflows/build.yaml | 46 ++++++++++++++++++++++++++++++++++++ Dockerfile | 13 ++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3dee03c --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,46 @@ +name: build-and-publish + +on: + push: + branches: + - "main" + - "feat/docker-build" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ vars.DOCKERHUB_USERNAME }}/sso-rs + + - name: Build and push + uses: docker/build-push-action@v6 + id: push + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ vars.DOCKERHUB_USERNAME }}/sso-rs + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6ce52a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM rust:1.77 AS builder +WORKDIR /app +COPY . . +RUN cargo build --release +RUN ls -al +RUN pwd +COPY ./target/release/sso-rs /sso-rs + +FROM alpine:3.20.3 +COPY --from=builder /sso-rs /sso-rs +EXPOSE 3000 +EXPOSE 2999 +CMD ["/sso-rs"]