-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
64 lines (49 loc) · 1.73 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
# https://docs.docker.com/develop/develop-images/multistage-build/
# ===== Stage: Base
FROM ruby:2.6.1-alpine AS Base
# Add gems installation requirements
RUN apk add --no-cache build-base git postgresql-dev
# ===== Stage: App
FROM ruby:2.6.1-alpine AS App
# Add Alpine runtime packages
RUN apk add --no-cache postgresql-client tzdata
# ===== Stage: Builder
FROM Base AS Builder
WORKDIR /tmp
COPY Gemfile* *.gemspec /tmp/
COPY lib/authenticator/version.rb /tmp/lib/authenticator/
# bundle for production by default
ARG BUNDLE_WITHOUT=test:development
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
RUN bundle config --global frozen 1 \
# Parallel donwload and install jobs
&& bundle install --jobs 4 --retry 3 \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete
# ===== Stage: Final
FROM App AS Final
# Metadata
LABEL maintainer='Hugo Armenta <[email protected]>' \
name='Authenticator' \
description='JWT Authentication solution'
# Add user: authenticator(default)
ARG UID=1000
ARG USER=authenticator
RUN addgroup -g ${UID} -S ${USER} \
&& adduser -u ${UID} -S ${USER} -G ${USER}
USER ${USER}
WORKDIR /app
# Copy app with gems from former build stage BUNDLE_PATH=/usr/local/bundle
COPY --chown=${USER}:${USER} --from=Builder $BUNDLE_PATH $BUNDLE_PATH
# Add app files
COPY --chown=${USER}:${USER} . .
ARG RAILS_ENV=production
ENV RAILS_ENV ${RAILS_ENV}
ENV RAILS_LOG_TO_STDOUT true
# Expose Puma port
EXPOSE 3000
# CMD runs once an image is prepared, make sure you have your dependencies
# already configured so application executes correclty.
CMD ["./docker-entrypoint.sh"]