-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
61 lines (45 loc) · 1.79 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
# Build compilation image
FROM ruby:3.3.5-alpine3.20 as builder
# The application runs from /app
WORKDIR /app
# build-base: compilation tools for bundle
# git: used to pull gems from git
# yarn: node package manager
RUN apk add --update --no-cache build-base git postgresql-dev shared-mime-info tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone
# Install gems defined in Gemfile
RUN bundle config set without 'development test'
COPY .ruby-version Gemfile Gemfile.lock /app/
RUN bundle install --jobs=4 --no-binstubs
# Copy all files to /app (except what is defined in .dockerignore)
COPY . /app/
# Cleanup to save space in the production image
RUN rm -rf node_modules log tmp && \
rm -rf /usr/local/bundle/cache && \
rm -rf .env && \
find /usr/local/bundle/gems -name "*.c" -delete && \
find /usr/local/bundle/gems -name "*.h" -delete && \
find /usr/local/bundle/gems -name "*.o" -delete && \
find /usr/local/bundle/gems -name "*.html" -delete
# Build runtime image
FROM ruby:3.3.5-alpine3.20 as production
RUN apk add --update --no-cache postgresql-dev curl shared-mime-info tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone
RUN bundle config set without 'development test'
# The application runs from /app
WORKDIR /app
ENV RAILS_ENV=production \
PORT=8080
# Copy files generated in the builder image
COPY --from=builder /app/ /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
RUN bundle config set without 'development test'
RUN addgroup -S tariff && \
adduser -S tariff -G tariff && \
chown -R tariff:tariff /app && \
chown -R tariff:tariff /usr/local/bundle
HEALTHCHECK CMD nc -z 0.0.0.0 $PORT
USER tariff
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]