Skip to content

.github/workflows/build.yml #2264

.github/workflows/build.yml

.github/workflows/build.yml #2264

Workflow file for this run

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
DISCOURSE_TURBO_RSPEC_RETRY_AND_LOG_FLAKY_TESTS: true
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:
# `unbuntu-22.04-8core` for arch amd64 non-scheduled builds
# `unbuntu-22.04` for arch amd64 scheduled builds
# `unbuntu-22.04-8core-arm` for arch arm64 non-scheduled builds
# `unbuntu-22.04-2core-arm` for arch arm64 scheduled builds
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || (( matrix.arch == 'arm64' && '-2core' ) || '') }}${{ (matrix.arch == 'arm64') && '-arm' || '' }}
strategy:
matrix:
arch: [amd64, arm64]
timeout-minutes: ${{ (github.event_name == 'schedule' && 90) || ((matrix.arch == 'arm64' && 45) || 30) }}
needs: timestamp
env:
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/checkout@v3
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 release images for `main` branch
working-directory: image
run: |
ruby auto_build.rb base_release_main_${{ matrix.arch }}
- 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_release_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
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 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 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 }}
# multiarch 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: push to dockerhub
if: github.ref == 'refs/heads/main'
env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
docker login --username discoursebuild --password $DOCKERHUB_PASSWORD
docker push discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
docker push discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
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
push_multiarch_manifests:
runs-on: ubuntu-latest
needs: [base, timestamp]
env:
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
if: github.ref == 'refs/heads/main'
steps:
- name: create and push multiarch manifests
run: |
docker login --username discoursebuild --password ${{ secrets.DOCKERHUB_PASSWORD }}
# Slim timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }}-slim \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64
# Slim release
docker manifest create discourse/base:slim \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64
# Full Discourse `main` branch timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }} \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64
# Full Discourse `stable` branch timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }}-stable \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64
# Full Discourse `main` branch release
docker manifest create discourse/base:release \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64
# Full Discourse `stable` branch release
docker manifest create discourse/base:release-stable \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64
# Dev timestamped
docker manifest create discourse/discourse_dev:${{ env.TIMESTAMP }} \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64
# Dev release
docker manifest create discourse/discourse_dev:release \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}-slim
docker manifest push discourse/base:slim
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}-stable
docker manifest push discourse/base:release
docker manifest push discourse/base:release-stable
docker manifest push discourse/discourse_dev:${{ env.TIMESTAMP }}
docker manifest push discourse/discourse_dev:release
test:
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || '' }}
timeout-minutes: 30
needs: base
defaults:
run:
working-directory: image/discourse_test
steps:
- uses: actions/checkout@v3
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: push to dockerhub
if: success() && (github.ref == 'refs/heads/main')
env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
docker login --username discoursebuild --password $DOCKERHUB_PASSWORD
docker push discourse/discourse_test:slim
docker push discourse/discourse_test:slim-browsers
docker push discourse/discourse_test:release