-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
101 lines (65 loc) · 2.27 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
ARG BASE_VERSION=latest
ARG IMAGE_NAME
ARG RUBY_VERSION=3.0.2-alpine3.13
FROM ruby:${RUBY_VERSION} AS base
ARG RAILS_ROOT=/app
ARG RUNTIME_PACKAGES="tzdata postgresql-libs"
WORKDIR $RAILS_ROOT
RUN apk update \
&& apk upgrade \
&& apk add --update --no-cache $RUNTIME_PACKAGES
RUN addgroup -S appgroup \
&& adduser -S appuser -G appgroup
RUN mkdir -p $RAILS_ROOT && chown appuser:appgroup $RAILS_ROOT
USER appuser
############### Build step ###############
FROM ${IMAGE_NAME}:base-${BASE_VERSION} AS build-env
ARG RAILS_ROOT=/app
ARG BUILD_PACKAGES="build-base curl-dev git"
ARG DEV_PACKAGES="postgresql-dev yaml-dev zlib-dev yarn nodejs"
ENV RAILS_ENV=production
ENV NODE_ENV=production
ENV BUNDLE_APP_CONFIG="$RAILS_ROOT/.bundle"
USER root
RUN apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES
USER appuser
COPY --chown=appuser:appgroup Gemfile* .
RUN bundle config --global frozen 1 \
&& bundle config --local path vendor/bundle \
&& bundle config deployment "true" \
&& bundle config without "development test" \
&& bundle install --retry 3 \
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
COPY --chown=appuser:appgroup package.json yarn.lock .
RUN yarn install --frozen-lockfile
COPY --chown=appuser:appgroup . .
RUN set -a \
&& bundle exec rails assets:precompile \
&& yarn run build
RUN rm -rf tmp/cache spec node_modules
############### Dev step ###############
FROM ${IMAGE_NAME}:base-${BASE_VERSION} AS dev
ARG RAILS_ROOT=/app
ARG BUILD_PACKAGES="build-base curl-dev git"
ARG DEV_PACKAGES="postgresql-dev yaml-dev zlib-dev yarn nodejs bash"
ENV RAILS_ENV=development
ENV NODE_ENV=development
USER root
RUN apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES
USER appuser
ENTRYPOINT ["./entrypoint.sh"]
############### Prod step ###############
FROM ${IMAGE_NAME}:base-${BASE_VERSION} AS web
ARG RAILS_ROOT=/app
ENV RAILS_ENV=production
ENV BUNDLE_APP_CONFIG="$RAILS_ROOT/.bundle"
COPY --chown=appuser:appgroup --from=build-env $RAILS_ROOT $RAILS_ROOT
USER root
RUN chown -R appuser:appgroup $RAILS_ROOT \
&& chmod +x ./entrypoint.sh
USER appuser
ENTRYPOINT ["./entrypoint.sh"]
EXPOSE 3000
CMD bin/rails server -b 0.0.0.0