Skip to content

Commit

Permalink
Rewrite dockerfile (#2430)
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism authored Aug 2, 2024
1 parent 13711d3 commit fdc5104
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 167 deletions.
13 changes: 9 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
work
*.log
*.dev
.git*
.local-dev
log
tmp
.idea
doc
dumps
coverage
.github
node_modules
spec
README.md
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
env:
RAILS_ENV: test
DATABASE_URL: "postgresql://postgres:[email protected]"
AWS_ACCESS_KEY_ID: 123
AWS_SECRET_ACCESS_KEY: 456
COVERAGE: true
CI: true
CI_TOTAL_JOBS: ${{ matrix.ci_total_jobs }}
Expand Down
6 changes: 0 additions & 6 deletions .yardopts

This file was deleted.

61 changes: 35 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
FROM ruby:3.1.4-alpine
LABEL key="Ministry of Justice, Track a Query <[email protected]>"
RUN set -ex
FROM ruby:3.1.4-alpine as builder

RUN addgroup --gid 1000 --system appgroup && \
adduser --uid 1000 --system appuser --ingroup appgroup
WORKDIR /app

# Some app dependencies
RUN apk add libreoffice clamav clamav-daemon freshclam ttf-freefont
RUN apk --no-cache add \
build-base \
ruby-dev \
postgresql-dev \
git \
yarn

# Note: .ruby-gemdeps libc-dev gcc libxml2-dev libxslt-dev make postgresql-dev build-base - these help with bundle install issues
RUN apk add --no-cache --virtual .ruby-gemdeps libc-dev gcc libxml2-dev libxslt-dev make postgresql-dev build-base git nodejs zip postgresql-client yarn
COPY .ruby-version Gemfile* package.json yarn.lock ./

RUN apk --update add less && apk -U upgrade && apk --no-cache upgrade musl
# Install gems and node packages
RUN bundle config deployment true && \
bundle config without development test && \
bundle install --jobs 4 --retry 3 && \
yarn install --frozen-lockfile --production

WORKDIR /usr/src/app/
COPY . .

COPY Gemfile* ./
RUN RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 \
bundle exec rake assets:precompile

RUN gem install bundler -v '~> 2.4.19'
# Cleanup to save space in the production image
RUN rm -rf node_modules log/* tmp/* /tmp && \
rm -rf /usr/local/bundle/cache

RUN bundle config deployment true && \
bundle config without development test && \
bundle install --jobs 4 --retry 3
# Build runtime image
FROM ruby:3.1.4-alpine

COPY . .
# The application runs from /app
WORKDIR /app

RUN yarn install --pure-lockfile
RUN apk --no-cache add \
nodejs \
postgresql-client

RUN mkdir -p log tmp tmp/pids
RUN chown -R appuser:appgroup /usr/src/app/
USER appuser
USER 1000
RUN addgroup -g 1000 -S appgroup && \
adduser -u 1000 -S appuser -G appgroup

RUN RAILS_ENV=production AWS_ACCESS_KEY_ID=not_real AWS_SECRET_ACCESS_KEY=not_real bundle exec rake assets:clean assets:precompile assets:non_digested SECRET_KEY_BASE=required_but_does_not_matter_for_assets 2> /dev/null
# Copy files generated in the builder image
COPY --from=builder /app /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/

ENV PUMA_PORT 3000
EXPOSE $PUMA_PORT
RUN mkdir -p log tmp tmp/pids
RUN chown -R appuser:appgroup log tmp

RUN chown -R appuser:appgroup ./*
RUN chmod +x /usr/src/app/config/docker/*
USER 1000

# expect/add ping environment variables
ARG APP_GIT_COMMIT
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby file: ".ruby-version"

gem "activerecord-session_store"
gem "acts_as_tree", "~> 2.9"
# Gems to help generating with Excel spreadsheets
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -705,5 +705,8 @@ DEPENDENCIES
turbolinks (~> 5)
tzinfo-data

RUBY VERSION
ruby 3.1.4p223

BUNDLED WITH
2.4.19
129 changes: 0 additions & 129 deletions coffeelint.json

This file was deleted.

Empty file modified config/docker/entrypoint-anonymizer-jobs.sh
100644 → 100755
Empty file.
Empty file modified config/docker/entrypoint-migrations.sh
100644 → 100755
Empty file.
Empty file modified config/docker/entrypoint-quick-jobs.sh
100644 → 100755
Empty file.

0 comments on commit fdc5104

Please sign in to comment.