-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
94 lines (74 loc) · 3.43 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# To use or update to a ruby version, change {BASE_RUBY_IMAGE}
ARG BASE_RUBY_IMAGE=ruby:3.3.5-alpine3.20
# Stage 1: gems-node-modules, build gems and node modules.
FROM ${BASE_RUBY_IMAGE} AS gems-node-modules
RUN apk -U upgrade && \
apk add --update --no-cache git gcc libc-dev make postgresql-dev build-base \
libxml2-dev libxslt-dev nodejs yarn tzdata libpq libxml2 libxslt graphviz chromium gcompat \
'aom>=3.9.1-r0'
RUN echo "Europe/London" > /etc/timezone && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime
ENV RAILS_ENV=production \
GOVUK_NOTIFY_API_KEY=TestKey \
AUTHORISED_HOSTS=127.0.0.1 \
SECRET_KEY_BASE=TestKey \
BLAZER_DATABASE_URL=testURL \
GOVUK_NOTIFY_CALLBACK_API_KEY=TestKey \
REDIS_CACHE_URL=redis://127.0.0.1:6379 \
NODE_OPTIONS=--openssl-legacy-provider \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN gem update --system && \
bundler -v && \
bundle config set no-cache 'true' && \
bundle config set no-binstubs 'true' && \
bundle --retry=5 --jobs=4 --without=development && \
rm -rf /usr/local/bundle/cache
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . .
RUN bundle exec rake assets:precompile
RUN rm -rf tmp/* log/* /tmp/*
# Stage 2: production, copy application code and compiled assets to base ruby image.
# Depends on assets-precompile stage which can be cached from a pre-built image
# by specifying a fully qualified image name or will default to packages-prod thereby rebuilding all 3 stages above.
# If a existing base image name is specified Stage 1 & 2 will not be built and gems and dev packages will be used from the supplied image.
FROM ${BASE_RUBY_IMAGE} AS production
ENV LANG=en_GB.UTF-8 \
RAILS_ENV=production \
GOVUK_NOTIFY_API_KEY=TestKey \
AUTHORISED_HOSTS=127.0.0.1 \
SECRET_KEY_BASE=TestKey \
GOVUK_NOTIFY_CALLBACK_API_KEY=TestKey \
REDIS_CACHE_URL=redis://127.0.0.1:6379 \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN apk -U upgrade && \
apk add --update --no-cache tzdata libpq libxml2 libxslt graphviz \
ttf-dejavu ttf-droid ttf-liberation libx11 openssl nodejs chromium gcompat \
'aom>=3.9.1-r0' && \
echo "Europe/London" > /etc/timezone && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime
WORKDIR /app
RUN echo export PATH=/usr/local/bin:\$PATH > /root/.ashrc
ENV ENV="/root/.ashrc"
COPY --from=gems-node-modules /app /app
COPY --from=gems-node-modules /usr/local/bundle/ /usr/local/bundle/
ARG SHA
ENV SHA=${SHA}
RUN echo ${SHA} > public/check
# Use this for development testing
# CMD bundle exec rails db:migrate && bundle exec rails server -b 0.0.0.0
# We migrate and ignore concurrent_migration_exceptions because we deploy to
# multiple instances at the same time.
#
# Under these conditions each instance will try to run migrations. Rails uses a
# database lock to prevent them stepping on each another. If they happen to,
# a ConcurrentMigrationError exception is thrown, the command exits 1, and
# the server will not start thanks to the shell &&.
#
# We swallow the exception and run the server anyway, because we prefer running
# new code on an old schema (which will be updated a moment later) to running
# old code on the new schema (which will require another deploy or other manual
# intervention to correct).
CMD bundle exec rails db:migrate:ignore_concurrent_migration_exceptions && bundle exec rails server -b 0.0.0.0