From 4a2a1aab4ff08634829da264d45d86ea0b30b122 Mon Sep 17 00:00:00 2001 From: Alex Baker <70726455+alexbakervr@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:37:46 +0000 Subject: [PATCH 1/5] Adding new Dockerfile, puma.rb and ci.yaml files --- .github/ci.yaml | 19 +++++++++++++++++ Dockerfile | 54 ++++++++++++++++++++++++++++++++++--------------- config/puma.rb | 2 ++ 3 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 .github/ci.yaml create mode 100644 config/puma.rb diff --git a/.github/ci.yaml b/.github/ci.yaml new file mode 100644 index 000000000..125bf760a --- /dev/null +++ b/.github/ci.yaml @@ -0,0 +1,19 @@ +name: Build and publish to ECR + +on: + workflow_dispatch: + branches: + - main + push: + branches: + - main + paths-ignore: + - "Jenkinsfile" + - ".git**" + +jobs: + build-publish-image-to-ecr: + uses: alphagov/govuk-infrastructure/.github/workflows/ci-ecr.yaml@main + secrets: + AWS_GOVUK_ECR_ACCESS_KEY_ID: ${{ secrets.AWS_GOVUK_ECR_ACCESS_KEY_ID }} + AWS_GOVUK_ECR_SECRET_ACCESS_KEY: ${{ secrets.AWS_GOVUK_ECR_SECRET_ACCESS_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ff3b4a32f..4f0ad1ff3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,46 @@ -FROM ruby:2.7.2 -RUN apt-get update -qq && apt-get upgrade -y -RUN apt-get install -y build-essential nodejs && apt-get clean -RUN gem install foreman +ARG base_image=ruby:2.7.2 -ENV GOVUK_APP_NAME government-frontend -ENV PORT 3090 -ENV RAILS_ENV development +FROM $base_image AS builder -ENV APP_HOME /app -RUN mkdir $APP_HOME +ENV RAILS_ENV=production -WORKDIR $APP_HOME -ADD Gemfile* $APP_HOME/ -ADD .ruby-version $APP_HOME/ -RUN bundle install +RUN apt-get update -qy && \ + apt-get upgrade -y && \ + apt-get install -y build-essential nodejs && \ + apt-get clean + +RUN bundle config set force_ruby_platform true -ADD . $APP_HOME +RUN mkdir /app -RUN GOVUK_WEBSITE_ROOT=https://www.gov.uk GOVUK_APP_DOMAIN=www.gov.uk RAILS_ENV=production bundle exec rails assets:precompile +WORKDIR /app + +COPY Gemfile Gemfile.lock .ruby-version /app/ + +RUN bundle config set deployment 'true' && \ + bundle config set without 'development test' && \ + bundle install --jobs 4 --retry=2 + +COPY . /app + +RUN GOVUK_APP_DOMAIN=www.gov.uk \ + GOVUK_WEBSITE_ROOT=https://www.gov.uk \ + bundle exec rails assets:precompile + +FROM $base_image + +ENV RAILS_ENV=production GOVUK_APP_NAME=government-frontend GOVUK_APP_DOMAIN=www.gov.uk GOVUK_WEBSITE_ROOT=https://www.gov.uk PORT=3090 + +RUN apt-get update -qy && \ + apt-get upgrade -y && \ + apt-get install -y nodejs && \ + apt-get clean + +WORKDIR /app HEALTHCHECK CMD curl --silent --fail localhost:$PORT/healthcheck/ready || exit 1 -CMD foreman run web +COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ +COPY --from=builder /app ./ + +CMD bundle exec puma \ No newline at end of file diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 000000000..47ad61da8 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,2 @@ +require "govuk_app_config/govuk_puma" +GovukPuma.configure_rails(self) \ No newline at end of file From 646ac7090b9426acada1fe8d4c8bdb18a0d3a3a4 Mon Sep 17 00:00:00 2001 From: Alex Baker <70726455+alexbakervr@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:52:12 +0000 Subject: [PATCH 2/5] Test Syntax --- config/puma.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/puma.rb b/config/puma.rb index 47ad61da8..d08b16a62 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,2 +1,2 @@ require "govuk_app_config/govuk_puma" -GovukPuma.configure_rails(self) \ No newline at end of file +GovukPuma.configure_rails(self) From 7c5e061592e46f6278ef63fbe83362377c1fa44c Mon Sep 17 00:00:00 2001 From: Alex Baker <70726455+alexbakervr@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:53:38 +0000 Subject: [PATCH 3/5] Making a few changes as per Chris's comments --- .github/ci.yaml | 2 +- Dockerfile | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ci.yaml b/.github/ci.yaml index 125bf760a..0600f8296 100644 --- a/.github/ci.yaml +++ b/.github/ci.yaml @@ -16,4 +16,4 @@ jobs: uses: alphagov/govuk-infrastructure/.github/workflows/ci-ecr.yaml@main secrets: AWS_GOVUK_ECR_ACCESS_KEY_ID: ${{ secrets.AWS_GOVUK_ECR_ACCESS_KEY_ID }} - AWS_GOVUK_ECR_SECRET_ACCESS_KEY: ${{ secrets.AWS_GOVUK_ECR_SECRET_ACCESS_KEY }} \ No newline at end of file + AWS_GOVUK_ECR_SECRET_ACCESS_KEY: ${{ secrets.AWS_GOVUK_ECR_SECRET_ACCESS_KEY }} diff --git a/Dockerfile b/Dockerfile index 4f0ad1ff3..c623d171e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -ARG base_image=ruby:2.7.2 +ARG base_image=ruby:2.7.2-slim FROM $base_image AS builder ENV RAILS_ENV=production - +# TODO: have a separate build image which already contains the build-only deps. RUN apt-get update -qy && \ apt-get upgrade -y && \ apt-get install -y build-essential nodejs && \ @@ -22,7 +22,7 @@ RUN bundle config set deployment 'true' && \ bundle install --jobs 4 --retry=2 COPY . /app - +# TODO: We probably don't want assets in the image; remove this once we have a proper deployment process which uploads to (e.g.) S3. RUN GOVUK_APP_DOMAIN=www.gov.uk \ GOVUK_WEBSITE_ROOT=https://www.gov.uk \ bundle exec rails assets:precompile @@ -43,4 +43,4 @@ HEALTHCHECK CMD curl --silent --fail localhost:$PORT/healthcheck/ready || exit 1 COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ COPY --from=builder /app ./ -CMD bundle exec puma \ No newline at end of file +CMD bundle exec puma From 0e2b735f0d5a4712b96a4a88fdc4828f6ceecbcd Mon Sep 17 00:00:00 2001 From: Alex Baker <70726455+alexbakervr@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:46:22 +0000 Subject: [PATCH 4/5] Testing Dockerfile without healthcheck --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c623d171e..94eed96d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,8 +38,6 @@ RUN apt-get update -qy && \ WORKDIR /app -HEALTHCHECK CMD curl --silent --fail localhost:$PORT/healthcheck/ready || exit 1 - COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ COPY --from=builder /app ./ From 8b9c4c400da08bf67590b5396383c622fb998284 Mon Sep 17 00:00:00 2001 From: Alex Baker <70726455+alexbakervr@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:56:19 +0000 Subject: [PATCH 5/5] Update ruby version --- .ruby-version | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 37c2961c2..a603bb50a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.2 +2.7.5 diff --git a/Dockerfile b/Dockerfile index 94eed96d2..63967435b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG base_image=ruby:2.7.2-slim +ARG base_image=ruby:2.7.5-slim FROM $base_image AS builder