.github/workflows/build.yml #3035
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| concurrency: | |
| group: build-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} | |
| cancel-in-progress: true | |
| env: | |
| BUILDKIT_PROGRESS: plain | |
| jobs: | |
| timestamp: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| timestamp: ${{ steps.timestamp.outputs.timestamp }} | |
| steps: | |
| - id: timestamp | |
| run: | | |
| timestamp=`date +%Y%m%d-%H%M` | |
| echo "timestamp=$timestamp" | |
| echo "timestamp=$timestamp" >> $GITHUB_OUTPUT | |
| base: | |
| # `debian-12-8core` for amd64 builds | |
| # `ubuntu-24.04-8core-arm` for arm64 builds | |
| runs-on: ${{ (matrix.arch == 'amd64' && 'debian-12-8core') || 'ubuntu-24.04-8core-arm' }} | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| timeout-minutes: ${{ (github.event_name == 'schedule' && 90) || 45 }} | |
| needs: timestamp | |
| env: | |
| TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }} | |
| services: | |
| registry: | |
| image: registry:2 | |
| ports: | |
| - 5000:5000 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: build deps image | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_deps_${{ matrix.arch }} | |
| - name: build slim image for `main` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_slim_main_${{ matrix.arch }} | |
| - name: tag slim image for `main` branch | |
| run: | | |
| docker tag discourse/base:build_slim_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | |
| - name: build slim image for `stable` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_slim_stable_${{ matrix.arch }} | |
| - name: build web_only images for `main` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_web_only_main_${{ matrix.arch }} | |
| - name: build web_only images for `stable` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_web_only_stable_${{ matrix.arch }} | |
| - name: build release images for `main` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_release_main_${{ matrix.arch }} | |
| # Temporarily build images with PG 15 so that we can ship the changes to the postgres templates in the same PR. | |
| - name: build release images for `main` branch with PG 15 | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_release_main_${{ matrix.arch }}_pg_15 | |
| - name: build release images for `stable` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb base_release_stable_${{ matrix.arch }} | |
| - name: tag release images | |
| run: | | |
| docker tag discourse/base:build_web_only_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-${{ matrix.arch }} | |
| docker tag discourse/base:build_web_only_stable_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-${{ matrix.arch }} | |
| docker tag discourse/base:build_release_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | |
| docker tag discourse/base:build_release_main_${{ matrix.arch }}_pg_15 discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}-pg-15 | |
| docker tag discourse/base:build_release_stable_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-stable-${{ matrix.arch }} | |
| - name: build test_build image for `main` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb discourse_test_build_${{ matrix.arch }} | |
| - name: run specs for `main` branch | |
| run: | | |
| docker run --rm -e RUBY_ONLY=1 -e USE_TURBO=1 -e SKIP_PLUGINS=1 -e SKIP_LINT=1 -e DISCOURSE_TURBO_RSPEC_RETRY_AND_LOG_FLAKY_TESTS=1 discourse/discourse_test:build_${{ matrix.arch }} | |
| - name: build & tag dev image for `main` branch | |
| working-directory: image | |
| run: | | |
| ruby auto_build.rb discourse_dev_${{ matrix.arch }} | |
| docker tag discourse/discourse_dev:build_${{ matrix.arch }} discourse/discourse_dev:${{ env.TIMESTAMP }}-${{ matrix.arch }} | |
| - name: Print summary | |
| run: | | |
| docker images discourse/base | |
| - name: Print `docker history` summary for main branch image | |
| run: | | |
| docker history discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | |
| - name: Print compressed summary | |
| if: github.event_name == 'pull_request' && matrix.arch == 'amd64' | |
| run: | | |
| # Push to local repo to compare sizes | |
| docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | |
| docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | |
| docker push --quiet localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | |
| docker push --quiet localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | |
| # multi-arch manifest is an array of schemas - [0] is amd64, [1] is arch64: Compare amd64. | |
| CURRENT_SLIM=$(docker manifest inspect -v discourse/base:slim | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1) | |
| CURRENT_RELEASE=$(docker manifest inspect -v discourse/base:release | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1) | |
| NEW_SLIM=$(docker manifest inspect -v --insecure localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1) | |
| NEW_RELEASE=$(docker manifest inspect -v --insecure localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1) | |
| echo "current slim: ${CURRENT_SLIM}MB release: ${CURRENT_RELEASE}MB. new slim: ${NEW_SLIM}MB release: ${NEW_RELEASE}MB" | |
| - name: Login to Docker Hub | |
| if: github.ref == 'refs/heads/main' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: discoursebuild | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: push to dockerhub | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-${{ matrix.arch }} | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-${{ matrix.arch }} | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}-pg-15 | |
| docker push discourse/base:2.0.${{ env.TIMESTAMP }}-stable-${{ matrix.arch }} | |
| docker push discourse/discourse_dev:${{ env.TIMESTAMP }}-${{ matrix.arch }} | |
| - name: Push discourse/base:aarch64 image for backwards compatibility | |
| if: (github.ref == 'refs/heads/main') && (matrix.arch == 'arm64') | |
| run: | | |
| docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} discourse/base:aarch64 | |
| docker push discourse/base:aarch64 | |
| ruby_3_4: | |
| runs-on: debian-12-8core | |
| timeout-minutes: 30 | |
| needs: base | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: build slim image | |
| run: | | |
| cd image && ruby auto_build.rb base_slim_main_amd64 --build-arg="RUBY_VERSION=3.4.7" | |
| - name: build release image | |
| run: | | |
| cd image && ruby auto_build.rb base_release_main_amd64 --build-arg="RUBY_VERSION=3.4.7" | |
| - name: build test_build image | |
| run: | | |
| cd image && ruby auto_build.rb discourse_test_build_amd64 --build-arg="RUBY_VERSION=3.4.7" | |
| - name: run specs | |
| run: | | |
| docker run --rm -e RUBY_ONLY=1 -e USE_TURBO=1 -e SKIP_PLUGINS=1 -e SKIP_LINT=1 discourse/discourse_test:build_amd64 | |
| - name: Print summary | |
| run: | | |
| docker images discourse/base | |
| - name: Login to Docker Hub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| uses: docker/login-action@v3 | |
| with: | |
| username: discoursebuild | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: push to dockerhub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| run: | | |
| docker tag discourse/base:build_release_main_amd64 discourse/base:release-ruby-3.4.7 | |
| docker push discourse/base:release-ruby-3.4.7 | |
| multi_rubies: | |
| runs-on: debian-12-8core | |
| timeout-minutes: 30 | |
| needs: base | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: build slim image | |
| run: | | |
| cd image && ruby auto_build.rb base_slim_main_amd64 --build-arg="FROM_DOCKER_IMAGE_TAG=3.3.8-and-3.4.7-bookworm-slim" | |
| - name: build release image | |
| run: | | |
| cd image && ruby auto_build.rb base_release_main_amd64 --build-arg="FROM_DOCKER_IMAGE_TAG=3.3.8-and-3.4.7-bookworm-slim" | |
| - name: build test_build image | |
| run: | | |
| cd image && ruby auto_build.rb discourse_test_build_amd64 --build-arg="FROM_DOCKER_IMAGE_TAG=3.3.8-and-3.4.7-bookworm-slim" | |
| - name: run specs | |
| run: | | |
| docker run --rm -e RUBY_ONLY=1 -e USE_TURBO=1 -e SKIP_PLUGINS=1 -e SKIP_LINT=1 discourse/discourse_test:build_amd64 | |
| - name: Print summary | |
| run: | | |
| docker images discourse/base | |
| - name: Login to Docker Hub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| uses: docker/login-action@v3 | |
| with: | |
| username: discoursebuild | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: push to dockerhub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| run: | | |
| docker tag discourse/base:build_release_main_amd64 discourse/base:release-ruby-3.3.8-and-3.4.7 | |
| docker push discourse/base:release-ruby-3.3.8-and-3.4.7 | |
| push_multi_arch_manifests: | |
| runs-on: ubuntu-latest | |
| needs: [base, timestamp] | |
| env: | |
| TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }} | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: discoursebuild | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: create and push multi-arch manifests | |
| run: | | |
| # Slim timestamped | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }}-slim \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64 | |
| # Slim release | |
| docker buildx imagetools create -t discourse/base:slim \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64 | |
| # Web-Only `main` timestamped | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }}-web-only \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-arm64 | |
| # Web-Only `main` release | |
| docker buildx imagetools create -t discourse/base:web-only \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-main-arm64 | |
| # Web-Only `stable` timestamped | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-arm64 | |
| # Web-Only `stable` release | |
| docker buildx imagetools create -t discourse/base:web-only-stable \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-web-only-stable-arm64 | |
| # Full Discourse `main` branch timestamped | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }} \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64 | |
| # Full Discourse `main` branch timestamped with PG 15 | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }}-pg-15 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64-pg-15 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64-pg-15 | |
| # Full Discourse `stable` branch timestamped | |
| docker buildx imagetools create -t discourse/base:2.0.${{ env.TIMESTAMP }}-stable \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64 | |
| # Full Discourse `main` branch release | |
| docker buildx imagetools create -t discourse/base:release \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64 | |
| # Full Discourse `stable` branch release | |
| docker buildx imagetools create -t discourse/base:release-stable \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \ | |
| discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64 | |
| # Dev timestamped | |
| docker buildx imagetools create -t discourse/discourse_dev:${{ env.TIMESTAMP }} \ | |
| discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \ | |
| discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64 | |
| # Dev release | |
| docker buildx imagetools create -t discourse/discourse_dev:release \ | |
| discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \ | |
| discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64 | |
| test: | |
| runs-on: debian-12-8core | |
| timeout-minutes: 30 | |
| needs: base | |
| defaults: | |
| run: | |
| working-directory: image/discourse_test | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: build discourse_test:slim | |
| run: | | |
| docker buildx build . --load \ | |
| --build-arg from_tag=slim \ | |
| --target base \ | |
| --tag discourse/discourse_test:slim | |
| - name: build discourse_test:slim-browsers | |
| run: | | |
| docker buildx build . --load \ | |
| --build-arg from_tag=slim \ | |
| --target with_browsers \ | |
| --tag discourse/discourse_test:slim-browsers | |
| - name: build discourse_test:release | |
| run: | | |
| docker buildx build . --load \ | |
| --build-arg from_tag=release \ | |
| --target release \ | |
| --tag discourse/discourse_test:release | |
| - name: Print summary | |
| run: | | |
| docker images discourse/discourse_test | |
| - name: Login to Docker Hub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| uses: docker/login-action@v3 | |
| with: | |
| username: discoursebuild | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: push to dockerhub | |
| if: success() && (github.ref == 'refs/heads/main') | |
| run: | | |
| docker push discourse/discourse_test:slim | |
| docker push discourse/discourse_test:slim-browsers | |
| docker push discourse/discourse_test:release |