From 38cf7e3603f929443029b759c202d1b6d6e5c0b6 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 16 Oct 2023 10:51:37 +0800 Subject: [PATCH] DEV: Add job for building Discourse dev release image for arm64 --- .github/workflows/arm64-build.yml | 36 +++++++++++++++++++++++++++++-- image/auto_build.rb | 12 +++++------ image/discourse_test/Dockerfile | 3 ++- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.github/workflows/arm64-build.yml b/.github/workflows/arm64-build.yml index bfc74451df..58f3675104 100644 --- a/.github/workflows/arm64-build.yml +++ b/.github/workflows/arm64-build.yml @@ -13,6 +13,11 @@ env: jobs: base: runs-on: ubuntu-20.04 + services: + registry: + image: registry + ports: + - 5000:5000 steps: - uses: actions/checkout@v3 with: @@ -34,17 +39,19 @@ jobs: echo "tag=$(echo $TAG)" >> $GITHUB_OUTPUT docker tag discourse/base:build_slim_arm64 discourse/base:2.0.$TAG-slim-arm64 docker tag discourse/base:build_slim_arm64 discourse/base:slim-arm64 + docker push localhost:5000/discourse/base:build_slim_arm64 - name: build release image run: | - cd image && ruby auto_build.rb base_arm64 + cd image && ruby auto_build.rb base_arm64 --build-arg from=localhost:5000/discourse/base - name: tag release images run: | TAG=${{ steps.tag-images.outputs.tag }} docker tag discourse/base:build_arm64 discourse/base:2.0.$TAG-arm64 docker tag discourse/base:build_arm64 discourse/base:release-arm64 + docker push localhost:5000/discourse/base:build_arm64 - name: build test_build image run: | - cd image && ruby auto_build.rb discourse_test_build_arm64 + cd image && ruby auto_build.rb discourse_test_build_arm64 --build-arg from=localhost:5000/discourse/base - 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_arm64 @@ -111,3 +118,28 @@ jobs: docker push discourse/discourse_test:slim-arm64 docker push discourse/discourse_test:slim-browsers-arm64 docker push discourse/discourse_test:release-arm64 + dev: + runs-on: ubuntu-20.04 + needs: base + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: build discourse/discourse_dev:release-arm64 image + run: | + cd image && ruby auto_build.rb discourse_dev_arm64 + - name: push to dockerhub + if: success() && (github.ref == 'refs/heads/main') + env: + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + run: | + docker tag discourse/discourse_dev:build_arm64 discourse/discourse_dev:release-arm64 + docker login --username discoursebuild --password $DOCKERHUB_PASSWORD + docker push discourse/discourse_dev:release-arm64 diff --git a/image/auto_build.rb b/image/auto_build.rb index df92617df3..8332a9e57f 100644 --- a/image/auto_build.rb +++ b/image/auto_build.rb @@ -22,7 +22,7 @@ base_arm64: { name: "base", tag: "discourse/base:build_arm64", - extra_args: "-f release.Dockerfile --platform linux/arm64", + extra_args: "-f release.Dockerfile --platform linux/arm64 --build-arg tag=build_slim_arm64", }, discourse_test_build: { name: "discourse_test", @@ -31,7 +31,7 @@ discourse_test_build_arm64: { name: "discourse_test", tag: "discourse/discourse_test:build_arm64", - extra_args: "--platform linux/arm64", + extra_args: "--platform linux/arm64 --build-arg from_tag=build_arm64", }, discourse_dev: { name: "discourse_dev", @@ -63,10 +63,10 @@ def run(command) lines end -def build(image) +def build(image, extra_args: "") lines = run( - "cd #{image[:name]} && docker buildx build . --load --no-cache --tag #{image[:tag]} #{image[:extra_args] ? image[:extra_args] : ""}", + "cd #{image[:name]} && docker buildx build . --load --no-cache --tag #{image[:tag]} #{image[:extra_args] ? image[:extra_args] : ""} #{extra_args}", ) if lines[-1] =~ /successfully built/ raise "Error building the image for #{image[:name]}: #{lines[-1]}" @@ -80,7 +80,7 @@ def dev_deps() run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml") end -if ARGV.length != 1 +if ARGV.length < 1 puts <<~TEXT Usage: ruby auto_build.rb IMAGE @@ -100,5 +100,5 @@ def dev_deps() puts "Building #{images[image]}" dev_deps() if image == :discourse_dev - build(images[image]) + build(images[image], extra_args: ARGV.length > 1 ? ARGV[1..-1].join(" ") : "") end diff --git a/image/discourse_test/Dockerfile b/image/discourse_test/Dockerfile index c4f06fc8b8..22c6de84c8 100644 --- a/image/discourse_test/Dockerfile +++ b/image/discourse_test/Dockerfile @@ -1,6 +1,7 @@ ARG from_tag=build +ARG from=discourse/base -FROM discourse/base:$from_tag AS base +FROM $from:$from_tag AS base ENV RAILS_ENV test WORKDIR /var/www/discourse