From 3ef754f4ca305298bf46f31fdf917fb82c14902b Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 13 Dec 2021 21:03:00 +0000 Subject: [PATCH] Introduce a discourse/base:slim image (#588) The base-slim image doesn't run `yarn install` or `bundle install`, so it is much more lightweight. This is intended for use by systems which do their own dependency caching (e.g. GitHub Actions) The image will be released under the `:slim` tag, and also `:v2.0.{timestamp}-slim` --- .github/workflows/build.yml | 26 +++++++++++++++++----- image/auto_build.rb | 3 ++- image/base/release.Dockerfile | 10 +++++++++ image/base/{Dockerfile => slim.Dockerfile} | 8 +------ 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 image/base/release.Dockerfile rename image/base/{Dockerfile => slim.Dockerfile} (94%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9309d7f..3e2d657 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,10 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 1 - - name: build base image + - name: build slim image + run: | + cd image && ruby auto_build.rb base_slim + - name: build release image run: | cd image && ruby auto_build.rb base - name: build test_build image @@ -27,17 +30,26 @@ jobs: - 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 + - name: tag images + run: + TAG=`date +%Y%m%d-%H%M` + docker tag discourse/base:build discourse/base:2.0.$TAG-slim + docker tag discourse/base:build discourse/base:slim + docker tag discourse/base:build discourse/base:2.0.$TAG + docker tag discourse/base:build discourse/base:release + - name: Print summary + run: | + docker images discourse/base - name: push to dockerhub if: success() && (github.ref == 'refs/heads/main') env: DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} run: | - TAG=`date +%Y%m%d-%H%M` - docker tag discourse/base:build discourse/base:2.0.$TAG - docker tag discourse/base:build discourse/base:release docker login --username discoursebuild --password $DOCKERHUB_PASSWORD - docker push discourse/base:release + docker push discourse/base:2.0.$TAG-slim + docker push discourse/base:slim docker push discourse/base:2.0.$TAG + docker push discourse/base:release test: runs-on: [ubuntu-20.04] needs: base @@ -92,7 +104,9 @@ jobs: uses: docker/setup-buildx-action@v1 - name: build base image for aarch64 run: | - cd image/base && docker buildx build . --platform linux/arm64 --load --tag discourse/base:aarch64 + cd image/base + docker buildx build . -f slim.Dockerfile --platform linux/arm64 --load --tag discourse/base:aarch64-slim + docker buildx build . -f release.Dockerfile --platform linux/arm64 --load --tag discourse/base:aarch64 --build-arg tag=aarch64-slim - name: push to dockerhub if: success() && (github.ref == 'refs/heads/main') env: diff --git a/image/auto_build.rb b/image/auto_build.rb index 814f86e..e81e8f3 100644 --- a/image/auto_build.rb +++ b/image/auto_build.rb @@ -4,7 +4,8 @@ require 'pty' require 'optparse' images = { - base: { name: 'base', tag: "discourse/base:build", squash: true }, + base_slim: { name: 'base', tag: "discourse/base:build_slim", squash: true, extra_args: '-f slim.Dockerfile' }, + base: { name: 'base', tag: "discourse/base:build", extra_args: '-f release.Dockerfile' }, discourse_test_build: { name: 'discourse_test', tag: "discourse/discourse_test:build", squash: false}, discourse_test_public: { name: 'discourse_test', tag: "discourse/discourse_test:release", squash: true, extra_args: ' --build-arg tag=release '}, discourse_dev: { name: 'discourse_dev', tag: "discourse/discourse_dev:build", squash: false }, diff --git a/image/base/release.Dockerfile b/image/base/release.Dockerfile new file mode 100644 index 0000000..c087bde --- /dev/null +++ b/image/base/release.Dockerfile @@ -0,0 +1,10 @@ +ARG tag=build_slim + +FROM discourse/base:$tag + +RUN cd /var/www/discourse &&\ + sudo -u discourse bundle install --deployment --jobs 4 --without test development &&\ + sudo -u discourse yarn install --production &&\ + sudo -u discourse yarn cache clean &&\ + bundle exec rake maxminddb:get &&\ + find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + diff --git a/image/base/Dockerfile b/image/base/slim.Dockerfile similarity index 94% rename from image/base/Dockerfile rename to image/base/slim.Dockerfile index 9d38ce7..dce758e 100644 --- a/image/base/Dockerfile +++ b/image/base/slim.Dockerfile @@ -144,10 +144,4 @@ RUN useradd discourse -s /bin/bash -m -U &&\ git clone --depth 1 https://github.com/discourse/discourse.git &&\ cd discourse &&\ git remote set-branches --add origin tests-passed &&\ - chown -R discourse:discourse /var/www/discourse &&\ - cd /var/www/discourse &&\ - sudo -u discourse bundle install --deployment --jobs 4 --without test development &&\ - sudo -u discourse yarn install --production &&\ - sudo -u discourse yarn cache clean &&\ - bundle exec rake maxminddb:get &&\ - find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + + chown -R discourse:discourse /var/www/discourse -- 2.25.1