diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..b5390bb --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,88 @@ +name: Build and push image from ref + +on: + workflow_call: + inputs: + ref: + description: "A ref from this repository, CirclesUBI/pathfinder2" + required: true + type: string + image: + description: "The desired name of the image to build" + default: 'pathfinder2' + required: false + type: string + workflow_dispatch: + inputs: + ref: + description: "A ref from this repository, CirclesUBI/pathfinder2" + required: true + type: string + image: + description: "The desired name of the image to build" + default: 'pathfinder2' + required: false + type: string + +jobs: + + build-and-push-image: + + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + + - + name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ vars.GC_REGISTRY }}/${{ vars.GC_PROJECT_ID }}/${{ inputs.image }} + labels: | + org.opencontainers.image.title=${{ inputs.image }} + org.opencontainers.image.vendor=CirclesUBI + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{version}} + {{ tag }} + {{ base_ref }} + {{ branch }} + type=sha,prefix={{branch}}- + {{ sha }} + + - + name: Authenticate to Google Cloud + id: auth + uses: google-github-actions/auth@v1 + with: + workload_identity_provider: "${{ vars.GC_WLI_PROVIDER }}" + service_account: "${{ vars.GC_WLI_SA }}" + token_format: 'access_token' + + - + name: Login to Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ vars.GC_REGISTRY }} + username: 'oauth2accesstoken' + password: '${{ steps.auth.outputs.access_token }}' + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..9d62173 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,17 @@ +name: Build and push the dev image + +on: + push: + branches: [ feature/dockerfile ] + +jobs: + call-build-and-push: + name: Trigger container build and push + permissions: + contents: read + id-token: write + uses: ./.github/workflows/build-and-push.yml + with: + ref: "${{ github.ref }}" + image: "pathfinder2" + secrets: inherit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ab8283 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM rust:latest AS build + +WORKDIR /build +COPY . . + +RUN cargo install --path . +RUN cargo build --release + +FROM rust AS app + +WORKDIR /app +COPY --from=build /build/target/release . +RUN chmod +x ./server + +ENTRYPOINT ["./server"]