-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathDockerfile
More file actions
89 lines (72 loc) · 2.16 KB
/
Dockerfile
File metadata and controls
89 lines (72 loc) · 2.16 KB
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
# Stage 1: Build stage
FROM ruby:3.3.7-slim AS builder
# Set environment variables
ARG RACK_ENV=production
ENV RACK_ENV=$RACK_ENV
# Install system dependencies: runtime and build dependencies
RUN set -x \
&& apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
curl \
git \
libffi-dev \
libpq-dev \
libsqlite3-dev \
libxml2-dev \
libxslt-dev \
libyaml-dev \
tzdata \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /app
# Copy Gemfile and Gemfile.lock
COPY Gemfile Gemfile.lock ./
# Install Ruby gems
RUN set -x \
&& bundle config set --local without 'development test' \
&& bundle install --jobs $(nproc) --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
# Copy the rest of the application
COPY . ./
# Precompile assets
RUN set -x \
&& SECRET_KEY_BASE=foo bundle exec rake assets:precompile \
# Remove folders not needed in resulting image
&& rm -rf \
/tmp/* \
app/assets \
lib/assets \
spec \
tmp/cache \
vendor/assets
# Stage 2: Final stage
FROM ruby:3.3.7-slim
# Set environment variables
ARG RACK_ENV=production
ENV RACK_ENV=$RACK_ENV
# Set the working directory
WORKDIR /app
# Copy the bundle from the builder stage
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
# Copy the application with precompiled assets from the builder stage
COPY --from=builder /app /app
# Create non-root user
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER rails:rails
# Set environment variables for production
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_SERVE_STATIC_FILES=true
ENV EXECJS_RUNTIME=Disabled
# Expose port 3000
EXPOSE 3000
# Define volume for SQLite database
VOLUME /app/db/sqlite
# Set the startup command
CMD ["./start.sh"]