-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (69 loc) · 2.19 KB
/
Dockerfile
File metadata and controls
87 lines (69 loc) · 2.19 KB
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
ARG RUBY_VERSION=3.4.4
ARG ALPINE_VERSION=3.22
ARG BUNDLER_VERSION=2.6.9
# Defines base image which builder and final stage use
FROM ruby:$RUBY_VERSION-alpine$ALPINE_VERSION AS base
ENV DIR=/usr/src/app
RUN apk add --update --no-cache \
bash \
coreutils \
git \
nodejs \
tzdata \
procps \
&& gem update --system
# for Bundler
ARG BUNDLER_VERSION
RUN echo "Bundler version ${BUNDLER_VERSION}"
RUN gem install bundler:$BUNDLER_VERSION
# installs the required gems
FROM base AS gems
RUN apk add --update build-base yaml-dev && gem update --system
COPY bin bin
COPY Gemfile Gemfile.lock ./
# .bundle/config contains the information required to access rubygems.pkg.github.com/epimorphics/
COPY .bundle/config /root/.bundle/config
RUN bundle config set --local without 'development test' \
&& bundle config set --local frozen 1 \
&& bundle install
# runs build to compile assets
FROM base AS builder
RUN apk add --update build-base && gem update --system
WORKDIR ${DIR}
# Copy the builds from the previous stages
COPY --from=gems --chown=app /usr/local/bundle /usr/local/bundle
# Copy the rest of the application code
COPY config.ru Gemfile Gemfile.lock Rakefile ./
COPY app app
COPY bin bin
COPY config config
COPY lib lib
COPY public public
ARG RAILS_RELATIVE_URL_ROOT
RUN echo "RAILS_RELATIVE_URL_ROOT set to: ${RAILS_RELATIVE_URL_ROOT}"
# Precompile assets
RUN RAILS_ENV=production \
bundle exec rake assets:precompile \
&& mkdir -m 777 ${DIR}/coverage \
&& mkdir -m 777 ${DIR}/log
# Start a new build stage to minimise the final image size
FROM base
ARG image_name
ARG git_branch
ARG git_commit_hash
ARG github_run_number
ARG VERSION
LABEL com.epimorphics.name=$image_name \
com.epimorphics.branch=$git_branch \
com.epimorphics.build=$github_run_number \
com.epimorphics.commit=$git_commit_hash \
com.epimorphics.version=$VERSION
RUN addgroup -S app && adduser -S -G app app
EXPOSE 3000
WORKDIR ${DIR}
COPY --from=builder --chown=app /usr/local/bundle /usr/local/bundle
COPY --from=builder --chown=app ${DIR} .
USER app
# Add a script to be executed every time the container starts.
COPY entrypoint.sh "/app/entrypoint.sh"
ENTRYPOINT ["sh", "/app/entrypoint.sh"]