From 1b2c026c2a23fde04a87d565c5d7650e44f14cbb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 14 Dec 2021 14:53:20 +0000 Subject: [PATCH] DEV: Provide slim versions of the discourse_test image (#586) Also moves the discourse_test image to use a multi-stage build --- .github/workflows/build.yml | 32 +++++++++++++++++++------ image/auto_build.rb | 1 - image/discourse_test/Dockerfile | 41 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ccf0a96..1e5279d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,24 +56,42 @@ jobs: test: runs-on: [ubuntu-20.04] needs: base + defaults: + run: + working-directory: image/discourse_test steps: - - name: enable experimental docker features - run: | - sudo bash -c 'echo "{ \"cgroup-parent\": \"/actions_job\",\"experimental\":true}" > /etc/docker/daemon.json' - sudo service docker restart - docker version -f '{{.Server.Experimental}}' - uses: actions/checkout@v2 with: fetch-depth: 1 - - name: build discourse_test image + - 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: | - cd image && ruby auto_build.rb discourse_test_public + 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 dev: runs-on: [ubuntu-20.04] diff --git a/image/auto_build.rb b/image/auto_build.rb index e81e8f3..f996640 100644 --- a/image/auto_build.rb +++ b/image/auto_build.rb @@ -7,7 +7,6 @@ images = { 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/discourse_test/Dockerfile b/image/discourse_test/Dockerfile index f1eceac..2477856 100644 --- a/image/discourse_test/Dockerfile +++ b/image/discourse_test/Dockerfile @@ -1,36 +1,37 @@ -# NAME: discourse/discourse_test -# VERSION: release -ARG tag=build -FROM discourse/base:$tag +ARG from_tag=build + +FROM discourse/base:$from_tag AS base ENV RAILS_ENV test -MAINTAINER Sam Saffron "https://twitter.com/samsaffron" +WORKDIR /var/www/discourse +ENV LANG en_US.UTF-8 +ENTRYPOINT sudo -E -u discourse -H ruby script/docker_test.rb # configure Git to suppress warnings RUN sudo -E -u discourse -H git config --global user.email "you@example.com" &&\ sudo -E -u discourse -H git config --global user.name "Your Name" -RUN gem update bundler --force &&\ - cd /var/www/discourse &&\ - chown -R discourse . &&\ - bundle config unset deployment &&\ - bundle config unset without &&\ - sudo -u discourse git pull &&\ - sudo -u discourse bundle install --jobs=4 +RUN chown -R discourse . &&\ + chown -R discourse /var/run/postgresql &&\ + bundle config unset deployment &&\ + bundle config unset without + +FROM base AS with_browsers RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - &&\ echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list &&\ apt update &&\ apt install -y libgconf-2-4 libxss1 google-chrome-stable firefox-esr &&\ - npm install -g eslint babel-eslint &&\ cd /tmp && wget "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=en-US" -O firefox.tar.bz2 &&\ tar xjvf firefox.tar.bz2 && mv /tmp/firefox /opt/firefox-evergreen &&\ - cd /var/www/discourse && sudo -E -u discourse -H yarn install + apt clean -RUN cd /var/www/discourse && sudo -E -u discourse -H bundle exec rake plugin:install_all_official &&\ - sudo -E -u discourse -H bundle exec rake plugin:install_all_gems &&\ - chown -R discourse /var/run/postgresql +FROM with_browsers AS release -WORKDIR /var/www/discourse -ENV LANG en_US.UTF-8 -ENTRYPOINT sudo -E -u discourse -H ruby script/docker_test.rb +RUN cd /var/www/discourse &&\ + sudo -u discourse bundle install --jobs=4 &&\ + sudo -E -u discourse -H yarn install &&\ + sudo -u discourse yarn cache clean + +RUN cd /var/www/discourse && sudo -E -u discourse -H bundle exec rake plugin:install_all_official &&\ + sudo -E -u discourse -H bundle exec rake plugin:install_all_gems -- 2.25.1