-
-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (52 loc) · 1.62 KB
/
Dockerfile
File metadata and controls
68 lines (52 loc) · 1.62 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
ARG RUBY_VERSION=3
FROM ruby:$RUBY_VERSION-slim AS base
WORKDIR /app
# Common environment for all stages
ENV BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_WITHOUT="development,test" \
RAILS_ENV="production" \
RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="1"
# Build stage with build dependencies
FROM base AS build
# Install build dependencies
RUN apt-get update -q && \
apt-get install -y --no-install-recommends \
libyaml-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy Bundler files
COPY .ruby-version Gemfile Gemfile.lock ./
# Run Bundler
RUN bundle install --retry 3
# Copy application code
COPY . .
# Precompile Tailwind CSS and other assets
RUN export GITHUB_KEY=stub GITHUB_SECRET=stub && \
bin/rails tailwindcss:build && \
bin/rails assets:precompile
# Exclude Sorbet RBI files and setup clean Bootsnap cache
RUN rm -rf sorbet/rbi tmp/bootsnap* && \
bin/bootsnap precompile app/
# Final runtime stage
FROM base AS runtime
# Setup curl for healthcheck
RUN apt-get update -q && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Copy bundled gems from build stage
COPY --from=build /usr/local/bundle /usr/local/bundle
# Copy application code
COPY --from=build /app /app
# Create dedicated user
RUN groupadd -r strap && useradd -r -g strap -m -d /home/strap strap
RUN chown -R strap:strap /app /home/strap
ENV HOME=/home/strap
USER strap
# Setup healthcheck route
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f "http://localhost:3000/up" || exit 1
# Expose port
EXPOSE 3000
CMD ["bin/rails", "server"]