1
- FROM ruby:3.2.3-alpine as builder
1
+ FROM ruby:3.3.4-alpine as base
2
+
3
+ WORKDIR /app
4
+
5
+ # postgresql-client: to run postgres, tzdata: required to set timezone, nodejs: JS runtime
6
+ RUN apk add --no-cache \
7
+ postgresql-client \
8
+ tzdata \
9
+ nodejs
10
+
11
+ # Ensure latest rubygems is installed
12
+ RUN gem update --system
13
+
14
+ FROM base as builder
2
15
3
16
# build dependencies:
4
17
RUN apk add --no-cache \
18
+ ruby-dev \
5
19
build-base \
6
20
postgresql-dev \
7
- tzdata \
8
21
yarn
9
22
10
- WORKDIR /app
11
-
12
- COPY Gemfile* .ruby-version ./
23
+ COPY Gemfile* .ruby-version package.json yarn.lock ./
13
24
14
- RUN gem install bundler -v 2.4.19
15
25
RUN bundle config deployment true && \
16
26
bundle config without development test && \
17
- bundle install --jobs 4 --retry 3
18
-
19
- # Install node packages defined in package.json
20
- COPY package.json yarn.lock ./
21
- RUN yarn install --frozen-lockfile --check-files
27
+ bundle install --jobs 4 --retry 3 && \
28
+ yarn install --frozen-lockfile
22
29
23
30
# Copy all files to /app
24
31
COPY . .
25
32
26
- # The following are ENV variables that need to be present by the time
27
- # the assets pipeline run, but doesn't matter their value.
28
- #
29
- ENV EXTERNAL_URL replace_this_at_build_time
30
- ENV SECRET_KEY_BASE replace_this_at_build_time
31
- ENV GOVUK_NOTIFY_API_KEY replace_this_at_build_time
32
-
33
- ENV RAILS_ENV production
34
- RUN bundle exec rake assets:precompile
33
+ RUN RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 \
34
+ bundle exec rails assets:precompile
35
35
36
36
# Copy fonts and images (without digest) along with the digested ones,
37
37
# as there are some hardcoded references in the `govuk-frontend` files
38
38
# that will not be able to use the rails digest mechanism.
39
39
RUN cp -r node_modules/govuk-frontend/dist/govuk/assets/. public/assets/
40
40
41
- # tidy up installation
42
- RUN rm -rf log/* tmp/* /tmp && \
43
- rm -rf /usr/local/bundle/cache && \
44
- find /usr/local/bundle/gems -name "*.c" -delete && \
45
- find /usr/local/bundle/gems -name "*.h" -delete && \
46
- find /usr/local/bundle/gems -name "*.o" -delete && \
47
- find /usr/local/bundle/gems -name "*.html" -delete
41
+ # Cleanup to save space in the production image
42
+ RUN rm -rf node_modules log/* tmp/* /tmp && \
43
+ rm -rf /usr/local/bundle/cache
48
44
49
45
# Build runtime image
50
- FROM ruby:3.2.3-alpine
51
-
52
- # The application runs from /app
53
- WORKDIR /app
54
-
55
- # libpq: required to run postgres, tzdata: required to set timezone, nodejs: JS runtime
56
- RUN apk add --no-cache libpq tzdata nodejs
46
+ FROM base
57
47
58
48
# add non-root user and group with alpine first available uid, 1000
59
49
RUN addgroup -g 1000 -S appgroup && \
@@ -65,21 +55,14 @@ COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
65
55
66
56
# Create log and tmp
67
57
RUN mkdir -p log tmp
68
- RUN chown -R appuser:appgroup db log tmp
58
+ RUN chown -R appuser:appgroup ./*
69
59
70
- ARG APP_BUILD_DATE
71
- ENV APP_BUILD_DATE ${APP_BUILD_DATE}
60
+ # Set user
61
+ USER 1000
72
62
63
+ ARG APP_BUILD_DATE
73
64
ARG APP_BUILD_TAG
74
- ENV APP_BUILD_TAG ${APP_BUILD_TAG}
75
-
76
65
ARG APP_GIT_COMMIT
66
+ ENV APP_BUILD_DATE ${APP_BUILD_DATE}
67
+ ENV APP_BUILD_TAG ${APP_BUILD_TAG}
77
68
ENV APP_GIT_COMMIT ${APP_GIT_COMMIT}
78
-
79
- ENV APPUID 1000
80
- USER $APPUID
81
-
82
- ENV PUMA_PORT 3000
83
- EXPOSE $PUMA_PORT
84
-
85
- ENTRYPOINT ["./run.sh" ]
0 commit comments