|
| 1 | +name: Build Container Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - '*' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-image: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + # Local registry needed to share the build-env image between steps when |
| 15 | + # using the docker-container buildkit driver |
| 16 | + services: |
| 17 | + registry: |
| 18 | + image: registry:2 |
| 19 | + ports: |
| 20 | + - 5000:5000 |
| 21 | + steps: |
| 22 | + - uses: docker/login-action@v3 |
| 23 | + with: |
| 24 | + registry: ghcr.io |
| 25 | + username: ${{ github.repository_owner }} |
| 26 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Gather information |
| 31 | + id: info |
| 32 | + run: | |
| 33 | + echo "toolchain_version=$(yq '.toolchain.channel' --output-format=yaml rust-toolchain.toml)" >> $GITHUB_OUTPUT |
| 34 | + echo "crate_version=$(yq '.package.version' --output-format=yaml Cargo.toml)" >> $GITHUB_OUTPUT |
| 35 | + echo "git_timestamp=$(git log -1 --pretty=%ct)" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + echo "## Build information" >> $GITHUB_STEP_SUMMARY |
| 38 | + echo "| | |" >> $GITHUB_STEP_SUMMARY |
| 39 | + echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY |
| 40 | + cat $GITHUB_OUTPUT | sed 's/\(.*\)=\(.*\)/| \1 | \2 |/' >> $GITHUB_STEP_SUMMARY |
| 41 | +
|
| 42 | + - uses: docker/setup-buildx-action@v3 |
| 43 | + with: |
| 44 | + # network=host driver-opt needed to push to local registry |
| 45 | + driver-opts: network=host |
| 46 | + |
| 47 | + - name: Prepare build environment image |
| 48 | + uses: docker/build-push-action@v6 |
| 49 | + with: |
| 50 | + context: ./build/build-image |
| 51 | + build-args: RUST_TOOLCHAIN=${{ steps.info.outputs.toolchain_version }} |
| 52 | + cache-from: type=gha,scope=build-env |
| 53 | + cache-to: type=gha,mode=max,scope=build-env |
| 54 | + push: true |
| 55 | + tags: localhost:5000/build-env:latest |
| 56 | + |
| 57 | + - name: Gather image metadata |
| 58 | + id: meta |
| 59 | + uses: docker/metadata-action@v5 |
| 60 | + with: |
| 61 | + images: | |
| 62 | + ghcr.io/embarkstudios/quilkin |
| 63 | + tags: | |
| 64 | + type=ref,event=tag |
| 65 | + type=sha,prefix=${{ steps.info.outputs.crate_version }}- |
| 66 | +
|
| 67 | + - name: Build container image |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + # build.rs runs git commands, need to preserve .git directory |
| 71 | + # https://docs.docker.com/reference/dockerfile/#buildkit-built-in-build-args |
| 72 | + build-args: BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 |
| 73 | + file: image/Dockerfile.ghaction |
| 74 | + build-contexts: | |
| 75 | + build-env=docker-image://localhost:5000/build-env:latest |
| 76 | + cache-from: type=gha,scope=quilkin |
| 77 | + cache-to: type=gha,mode=max,scope=quilkin |
| 78 | + push: true |
| 79 | + tags: ${{ steps.meta.outputs.tags }} |
| 80 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 81 | + env: |
| 82 | + # Set the build timestamp to the commit timestamp, so we can |
| 83 | + # hopefully get reproducible builds when built from the same commit |
| 84 | + # https://github.com/moby/buildkit/blob/master/docs/build-repro.md#source_date_epoch |
| 85 | + SOURCE_DATE_EPOCH: ${{ steps.info.outputs.git_timestamp }} |
0 commit comments