-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
59 lines (46 loc) · 1.2 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
######################
# Stage: Builder
FROM ruby:3.2.2-alpine as Builder
ARG BUNDLER_VERSION
RUN apk add --update --no-cache \
build-base \
gcompat \
postgresql-dev \
libpq-dev \
git \
imagemagick \
tzdata
# Remove bundle config if exist
RUN rm -f .bundle/config
RUN gem install bundler:$BUNDLER_VERSION
WORKDIR /app
# Install gems
ARG BUNDLE_WITHOUT
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
RUN bundle config set without ${BUNDLE_WITHOUT}
COPY . /app/
RUN bundle install -j4 --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
# Remove folders not needed in resulting image
ARG FOLDERS_TO_REMOVE
RUN rm -rf $FOLDERS_TO_REMOVE
###############################
# Stage Final
FROM ruby:3.2.2-alpine as Final
# Add Alpine packages
RUN apk add --update --no-cache \
build-base \
gcompat \
postgresql-client \
libpq-dev \
imagemagick \
tzdata \
file \
git
# Copy app with gems from former build stage
COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=Builder /app/ /app/
WORKDIR /app