File tree 2 files changed +33
-9
lines changed
2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -61,19 +61,32 @@ RUN apt-get update -qq && \
61
61
apt-get install --no-install-recommends -y curl libpq-dev libvips libjemalloc2 && \
62
62
apt-get clean
63
63
64
+ ENV USERNAME rails_api_base
65
+ ENV USER_UID 1000
66
+ ENV USER_GID 1000
67
+
68
+ # Create a rootless user.
69
+ RUN groupadd --gid $USER_GID $USERNAME && \
70
+ useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
71
+
64
72
# Create app directory.
65
- RUN mkdir -p $APP_HOME
73
+ RUN mkdir -p $APP_HOME && chown -R $USERNAME:$USERNAME $APP_HOME && chmod -R 700 $APP_HOME
74
+
75
+ # Change to the rootless user.
76
+ USER $USERNAME
66
77
67
78
# Setup work directory.
68
79
WORKDIR $APP_HOME
69
80
70
81
# Copy everything from the builder image
71
- COPY --link . .
72
- COPY --from=builder $APP_HOME/public/ $APP_HOME/public/
73
- COPY --from=builder $APP_HOME/tmp/ $APP_HOME/tmp/
74
- COPY --from=builder $APP_HOME/vendor/ $APP_HOME/vendor/
82
+ COPY --link --chown=$USERNAME:$USERNAME --chmod=700 . .
83
+ COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/public/ $APP_HOME/public/
84
+ COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/tmp/ $APP_HOME/tmp/
85
+ COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/vendor/ $APP_HOME/vendor/
75
86
87
+ USER root
76
88
RUN ln -s /usr/lib/*-linux-gnu/libjemalloc.so.2 /usr/lib/libjemalloc.so.2
89
+ USER $USERNAME
77
90
78
91
# Deployment options
79
92
ENV RAILS_LOG_TO_STDOUT true
Original file line number Diff line number Diff line change @@ -21,22 +21,33 @@ ENV WORK_ROOT /src
21
21
ENV APP_HOME $WORK_ROOT/app/
22
22
ENV LANG C.UTF-8
23
23
24
+ ENV USERNAME rails_api_base
25
+ ENV USER_UID 1000
26
+ ENV USER_GID 1000
27
+
28
+ # Create a rootless user.
29
+ RUN groupadd --gid $USER_GID $USERNAME && \
30
+ useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
31
+
24
32
# Create app directory.
25
- RUN mkdir -p $APP_HOME
33
+ RUN mkdir -p $APP_HOME && chown -R $USERNAME:$USERNAME $APP_HOME && chmod -R 700 $APP_HOME
34
+
35
+ # Change to the rootless user.
36
+ USER $USERNAME
26
37
27
38
# Setup work directory.
28
39
WORKDIR $APP_HOME
29
40
30
41
RUN gem install foreman bundler
31
42
32
43
# Copy dependencies files and install libraries.
33
- COPY --link package.json yarn.lock ./
44
+ COPY --link --chown=$USERNAME:$USERNAME --chmod=700 package.json yarn.lock ./
34
45
RUN yarn install --frozen-lockfile
35
46
36
- COPY --link Gemfile Gemfile.lock ./
47
+ COPY --link --chown=$USERNAME:$USERNAME --chmod=700 Gemfile Gemfile.lock ./
37
48
RUN bundle install -j 4
38
49
39
- COPY --link . .
50
+ COPY --link --chown=$USERNAME:$USERNAME --chmod=700 . .
40
51
41
52
RUN yarn build
42
53
You can’t perform that action at this time.
0 commit comments