diff --git a/.github/workflows/build_baseimage_with_gems.yml b/.github/workflows/build_baseimage_with_gems.yml new file mode 100644 index 000000000..3487e838c --- /dev/null +++ b/.github/workflows/build_baseimage_with_gems.yml @@ -0,0 +1,32 @@ +name: build baseimage with gems + +on: + + push: + branches: + - master + paths: + - "Gemfile" + - "Gemfile.lock" + +jobs: + + build: + + runs-on: ubuntu-20.04 + + steps: + + - uses: actions/checkout@v2 + + - name: Login to container registry + env: + PASSWORD: ${{ secrets.GHCR }} + run: | + echo $PASSWORD | docker login ghcr.io -u eisbot --password-stdin + + - name: Build new image with gems + run: | + docker build --no-cache -t ghcr.io/internetee/registry:gems-latest -f Dockerfile.gems . + docker push ghcr.io/internetee/registry:gems-latest + diff --git a/.github/workflows/build_deploy_staging.yml b/.github/workflows/build_deploy_staging.yml index 8698cf3ab..5ca406f50 100644 --- a/.github/workflows/build_deploy_staging.yml +++ b/.github/workflows/build_deploy_staging.yml @@ -26,6 +26,32 @@ jobs: - uses: actions/checkout@v2 + - name: Check if there are gem updates + id: gem-updates-check + uses: tj-actions/changed-files@aae164d51be780a235cdeea89752bbacbbfee3c3 + with: + files: | + Gemfile + Gemfile.lock + + - name: Login to container registry + env: + PASSWORD: ${{ secrets.GHCR }} + run: | + echo $PASSWORD | docker login ghcr.io -u eisbot --password-stdin + + - name: No changes in gems + # feature branch has no changes in gems + if: steps.gem-updates-check.outputs.any_changed == 'false' + run: | + echo "DOCKERFILE=Dockerfile.preinstalled_gems" >> $GITHUB_ENV + + - name: Gems are changed + # feature branch has new/updated gems + if: steps.gem-updates-check.outputs.any_changed == 'true' + run: | + echo "DOCKERFILE=Dockerfile.generic" >> $GITHUB_ENV + - name: Set image tag run: | SHORT_SHA=$(echo $GITHUB_SHA | cut -c 1-7) #pr-s test commit of merged state @@ -55,7 +81,7 @@ jobs: env: KEY_BASE: ${{ secrets.KEY_BASE}} run: | - docker build -t $TAG --build-arg RAILS_ENV=staging --build-arg SECRET_KEY_BASE="$KEY_BASE" -f Dockerfile.generic . + docker build -t $TAG --build-arg RAILS_ENV=staging --build-arg SECRET_KEY_BASE="$KEY_BASE" -f $DOCKERFILE . - name: Clone epp_proxy project run: | @@ -82,10 +108,7 @@ jobs: docker build -t $PROXY_TAG -f Dockerfile.release . - name: Push Docker image to gh container registry - env: - PASSWORD: ${{ secrets.GHCR }} run: | - echo $PASSWORD | docker login ghcr.io -u eisbot --password-stdin docker push $TAG docker push $PROXY_TAG diff --git a/Dockerfile.gems b/Dockerfile.gems new file mode 100644 index 000000000..86068c56f --- /dev/null +++ b/Dockerfile.gems @@ -0,0 +1,5 @@ +FROM internetee/ruby_base:3.0 +LABEL org.opencontainers.image.source=https://github.com/internetee/registry + +COPY Gemfile Gemfile.lock ./ +RUN gem install bundler && bundle config set without 'development test' && bundle install --jobs 20 --retry 5 diff --git a/Dockerfile.preinstalled_gems b/Dockerfile.preinstalled_gems new file mode 100644 index 000000000..ad36b6cb3 --- /dev/null +++ b/Dockerfile.preinstalled_gems @@ -0,0 +1,19 @@ +FROM ghcr.io/internetee/registry:gems-latest +LABEL org.opencontainers.image.source=https://github.com/internetee/registry +ARG YARN_VER='1.22.10' +ARG RAILS_ENV +ARG SECRET_KEY_BASE + +ENV RAILS_ENV "$RAILS_ENV" +ENV SECRET_KEY_BASE "$SECRET_KEY_BASE" + +RUN npm install -g yarn@"$YARN_VER" + +RUN mkdir -p /opt/webapps/app/tmp/pids +WORKDIR /opt/webapps/app + +COPY . . + +RUN bundle exec rails assets:precompile + +EXPOSE 3000 \ No newline at end of file