-
Notifications
You must be signed in to change notification settings - Fork 18
/
Dockerfile
217 lines (168 loc) · 5.04 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#################################
# Variables #
#################################
# Versioning
ARG RUBY_VERSION="3.2.1"
ARG BUNDLER_VERSION="2.4.6"
# Packages
# ARG BUILD_PACKAGES="nodejs build-essential libc6"
ARG BUILD_PACKAGES
ARG RUN_PACKAGES="bash libpq5 libvips42 libvips-dev"
# Scripts
ARG PRE_INSTALL_SCRIPT
ARG INSTALL_SCRIPT
ARG PRE_BUILD_SCRIPT
ARG BUILD_SCRIPT="bundle exec rake assets:precompile"
ARG POST_BUILD_SCRIPT="echo \"(built at: $(date '+%Y-%m-%d %H:%M:%S'))\" > /app-src/BUILD_INFO"
# Bundler specific
ARG BUNDLE_WITHOUT="development:metrics:test"
# App specific
ARG RAILS_ENV="production"
ARG RACK_ENV="production"
ARG RAILS_HOST_NAME="unused.example.net"
ARG SECRET_KEY_BASE="needs-to-be-set"
ARG RAILS_DB_ADAPTER="nulldb"
# If you want to directly specify build infos
ARG BUILD_COMMIT
ARG BUILD_REPO
ARG BUILD_REPO_URL
ARG BUILD_REF
# Github specific
ARG GITHUB_SHA
ARG GITHUB_REPOSITORY
ARG GITHUB_REPOSITORY_URL
ARG GITHUB_REF_NAME
# # Gitlab specific
# ARG CI_COMMIT_SHA
# ARG CI_REPOSITORY_URL
# ARG CI_COMMIT_REF_NAME
# ARG BUILD_COMMIT="$CI_COMMIT_SHA"
# ARG BUILD_REPO="$CI_REPOSITORY_URL"
# ARG BUILD_REF="$CI_COMMIT_REF_NAME"
# # Openshift specific
# ARG OPENSHIFT_BUILD_COMMIT
# ARG OPENSHIFT_BUILD_SOURCE
# ARG OPENSHIFT_BUILD_REFERENCE
# ARG BUILD_COMMIT="$OPENSHIFT_BUILD_COMMIT"
# ARG BUILD_REPO="$OPENSHIFT_BUILD_SOURCE"
# ARG BUILD_REF="$OPENSHIFT_BUILD_REFERENCE"
# Runtime ENV vars
ARG SENTRY_CURRENT_ENV
ARG PS1="$SENTRY_CURRENT_ENV > "
ARG TZ="Europe/Zurich"
# Custom ARGs for Puzzletime
ARG SKIP_MEMCACHE_CHECK=true
#################################
# Build Stage #
#################################
FROM ruby:${RUBY_VERSION} AS build
# arguments for steps
ARG PRE_INSTALL_SCRIPT
ARG BUILD_PACKAGES
ARG INSTALL_SCRIPT
ARG BUNDLER_VERSION
ARG PRE_BUILD_SCRIPT
ARG BUNDLE_WITHOUT
ARG BUILD_SCRIPT
ARG POST_BUILD_SCRIPT
# arguments potentially used by steps
ARG RACK_ENV
ARG RAILS_ENV
ARG RAILS_HOST_NAME
ARG SECRET_KEY_BASE
ARG TZ
# Custom ARGs
ARG SKIP_MEMCACHE_CHECK
# Set build shell
SHELL ["/bin/bash", "-c"]
# Use root user
USER root
RUN bash -vxc "${PRE_INSTALL_SCRIPT:-"echo 'no PRE_INSTALL_SCRIPT provided'"}"
# Install dependencies
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends ${BUILD_PACKAGES}
RUN bash -vxc "${INSTALL_SCRIPT:-"echo 'no INSTALL_SCRIPT provided'"}"
# Install specific versions of dependencies
RUN gem install bundler:${BUNDLER_VERSION} --no-document
# Install nulldb adapter
ARG RAILS_DB_ADAPTER
RUN gem install activerecord-nulldb-adapter --no-document
# TODO: Load artifacts
# set up app-src directory
COPY . /app-src
WORKDIR /app-src
RUN bash -vxc "${PRE_BUILD_SCRIPT:-"echo 'no PRE_BUILD_SCRIPT provided'"}"
# install gems and build the app
RUN bundle config set --local deployment 'true' \
&& bundle config set --local without ${BUNDLE_WITHOUT} \
&& bundle package \
&& bundle install \
&& bundle clean
RUN bash -vxc "${BUILD_SCRIPT:-"echo 'no BUILD_SCRIPT provided'"}"
RUN bash -vxc "${POST_BUILD_SCRIPT:-"echo 'no POST_BUILD_SCRIPT provided'"}"
# TODO: Save artifacts
RUN rm -rf vendor/cache/ .git spec/ node_modules/
#################################
# Run Stage #
#################################
# This image will be replaced by Openshift
FROM ruby:${RUBY_VERSION}-slim AS app
# Set runtime shell
SHELL ["/bin/bash", "-c"]
# Add user
RUN adduser --disabled-password --uid 1001 --gid 0 --gecos "" app
# arguments for steps
ARG RUN_PACKAGES
ARG BUNDLER_VERSION
ARG BUNDLE_WITHOUT
# arguments potentially used by steps
ARG RACK_ENV
ARG RAILS_ENV
# data persisted in the image
ARG PS1
ARG TZ
ARG GITHUB_SHA
ARG GITHUB_REPOSITORY
ARG GITHUB_REPOSITORY_URL
ARG GITHUB_REF_NAME
ARG BUILD_COMMIT
ARG BUILD_REPO
ARG BUILD_REPO_URL
ARG BUILD_REF
# Custom ARGs
ARG SKIP_MEMCACHE_CHECK
ENV PS1="${PS1}" \
TZ="${TZ}" \
BUILD_REPO="${BUILD_REPO:-${GITHUB_REPOSITORY}}" \
BUILD_REPO_URL="${BUILD_REPO_URL:-${GITHUB_REPOSITORY_URL}}" \
BUILD_REF="${BUILD_REF:-${GITHUB_REF_NAME}}" \
BUILD_COMMIT="${BUILD_COMMIT:-${GITHUB_SHA}}" \
RAILS_ENV="${RAILS_ENV}" \
RACK_ENV="${RACK_ENV}"
# Install dependencies, remove apt!
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y ${RUN_PACKAGES} vim curl less \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& truncate -s 0 /var/log/*log
# Copy deployment ready source code from build
COPY --from=build /app-src /app-src
WORKDIR /app-src
# Set group permissions to app folder
RUN chgrp -R 0 /app-src \
&& chmod -R u+w,g=u /app-src
# support bin-stubs
ENV HOME=/app-src \
PATH=/app-src/bin:$PATH
# Install specific versions of dependencies
RUN gem install bundler:${BUNDLER_VERSION} --no-document
# Use cached gems
RUN bundle config set --local deployment 'true' \
&& bundle config set --local without ${BUNDLE_WITHOUT} \
&& bundle install
USER 1001
CMD ["bundle", "exec", "puma", "-t", "8"]