-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
155 lines (118 loc) · 4.1 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Global Build Args ----------------------------------
# Bundle home
ARG BUNDLE_HOME=vendor/bundle
# Image tag
ARG IMAGE_TAG=3.1.2-alpine3.16
# The root of our app
ARG PROJECT_ROOT=/home/app
# Rails env
ARG RAILS_ENV=development
# Build Stage ----------------------------------------
FROM ruby:${IMAGE_TAG} AS base
ARG BUNDLE_HOME
ENV BUNDLE_HOME=${BUNDLE_HOME}
ARG PROJECT_ROOT
ENV PROJECT_ROOT=${PROJECT_ROOT}
ARG RAILS_ENV=development
ENV RAILS_ENV=${RAILS_ENV}
ENV BUNDLE_APP_CONFIG="${PROJECT_ROOT}/.bundle"
WORKDIR ${PROJECT_ROOT}
COPY Gemfile* ./
# Install build packages
RUN apk add --no-cache --virtual build-dependencies \
build-base \
git \
postgresql-dev && \
bundle config path ${PROJECT_ROOT}/${BUNDLE_HOME} && \
set -eux; \
if [ "${RAILS_ENV}" = "development" ]; then \
bundle config set with "development:test:assets"; \
else \
bundle config set without "development:test:assets"; \
fi && \
bundle install -j$(nproc) --retry 3 && \
rm -rf ${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/cache/*.gem && \
find ${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete && \
apk del build-dependencies
COPY . .
# Development Stage ----------------------------------
FROM ruby:${IMAGE_TAG} as development
ARG BUNDLE_HOME
ENV BUNDLE_HOME=${BUNDLE_HOME}
ARG PROJECT_ROOT
ENV PROJECT_ROOT=${PROJECT_ROOT}
ARG RAILS_ENV=development
ENV RAILS_ENV=${RAILS_ENV}
# Set Rails env
ENV BUNDLE_APP_CONFIG="${PROJECT_ROOT}/.bundle"
ENV GEM_HOME="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/"
ENV GEM_PATH="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/"
ENV NLS_LANG=$LANG
ENV PATH="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/bin:${PATH}"
WORKDIR ${PROJECT_ROOT}
COPY ./docker-entrypoint.sh /usr/local/bin/
COPY --from=base ${PROJECT_ROOT} ${PROJECT_ROOT}
RUN apk add --no-cache \
build-base \
curl \
git \
libc6-compat \
nodejs \
postgresql-dev \
shadow \
su-exec \
tzdata \
yarn && \
chmod +x /usr/local/bin/docker-entrypoint.sh && \
addgroup -S app && adduser -S app -G app -h ${PROJECT_ROOT} -s /bin/ash && \
mkdir -p ${PROJECT_ROOT}/tmp/pids && \
find . -type d -exec chmod 755 {} + && \
find . -type f -exec chmod 644 {} + && \
find bin -type f -exec chmod 744 {} + && \
chmod +x -R ${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/bin/ && \
chown -R app:app .
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 3000
VOLUME ${PROJECT_ROOT}
CMD ["bundle", "exec", "puma", "-b", "tcp://0.0.0.0:3000"]
# Production Stage -----------------------------------
FROM ruby:${IMAGE_TAG} as production
ARG BUNDLE_HOME
ENV BUNDLE_HOME=${BUNDLE_HOME}
ARG PROJECT_ROOT
ENV PROJECT_ROOT=${PROJECT_ROOT}
ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}
# Set Rails env
ENV BUNDLE_APP_CONFIG="${PROJECT_ROOT}/.bundle"
ENV GEM_HOME="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/"
ENV GEM_PATH="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/"
ENV NLS_LANG=$LANG
ENV PATH="${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/bin:${PATH}"
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_SERVE_STATIC_FILES=true
WORKDIR ${PROJECT_ROOT}
COPY ./docker-entrypoint.sh /usr/local/bin/
COPY --from=base ${PROJECT_ROOT} ${PROJECT_ROOT}
RUN apk add --no-cache \
curl \
libc6-compat \
nodejs \
postgresql-dev \
shadow \
su-exec \
tzdata \
yarn && \
chmod +x /usr/local/bin/docker-entrypoint.sh && \
addgroup -S app && adduser -S app -G app -h ${PROJECT_ROOT} -s /bin/ash && \
SECRET_KEY_BASE=x FINDING_AID_DISCOVERY_URL=x rails assets:precompile && \
mkdir -p ${PROJECT_ROOT}/tmp/pids && \
find . -type d -exec chmod 755 {} + && \
find . -type f -exec chmod 644 {} + && \
find bin -type f -exec chmod 744 {} + && \
chmod +x -R ${PROJECT_ROOT}/${BUNDLE_HOME}/ruby/${RUBY_MAJOR}.0/bin/ && \
chown -R app:app .
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 3000
VOLUME ${PROJECT_ROOT}
CMD ["bundle", "exec", "puma", "-b", "tcp://0.0.0.0:3000"]