-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (53 loc) · 2.03 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Build compilation image
FROM ruby:3.3.4-alpine3.20 as builder
# The application runs from /app
WORKDIR /app
# build-base: compilation tools for bundle
# git: used to pull gems from git
# yarn: node package manager
RUN apk add --update --no-cache build-base git yarn tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone
# Install gems defined in Gemfile
COPY .ruby-version Gemfile Gemfile.lock /app/
RUN bundle config set without 'development test'
RUN bundle install --jobs=4 --no-binstubs
# Install node packages defined in package.json, including webpack
COPY package.json yarn.lock /app/
RUN yarn install --frozen-lockfile
# Copy all files to /app (except what is defined in .dockerignore)
COPY . /app/
ENV GOVUK_APP_DOMAIN=localhost \
GOVUK_WEBSITE_ROOT=http://localhost/ \
RAILS_ENV=production \
NODE_OPTIONS="--openssl-legacy-provider"
RUN bundle exec rails assets:precompile
# Cleanup to save space in the production image
RUN rm -rf node_modules log tmp && \
rm -rf /usr/local/bundle/cache && \
rm -rf .env && \
find /usr/local/bundle/gems -name "*.c" -delete && \
find /usr/local/bundle/gems -name "*.h" -delete && \
find /usr/local/bundle/gems -name "*.o" -delete && \
find /usr/local/bundle/gems -name "*.html" -delete
# Build runtime image
FROM ruby:3.3.4-alpine3.20 as production
RUN apk add --update --no-cache tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone
# The application runs from /app
WORKDIR /app
ENV RAILS_SERVE_STATIC_FILES=true \
RAILS_ENV=production \
PORT=8080
RUN bundle config set without 'development test'
# Copy files generated in the builder image
COPY --from=builder /app /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
RUN addgroup -S tariff && \
adduser -S tariff -G tariff && \
chown -R tariff:tariff /app && \
chown -R tariff:tariff /usr/local/bundle
HEALTHCHECK CMD nc -z 0.0.0.0 $PORT
USER tariff
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]