-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathDockerfile.production
More file actions
95 lines (76 loc) · 2.54 KB
/
Dockerfile.production
File metadata and controls
95 lines (76 loc) · 2.54 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
89
90
91
92
93
94
95
# syntax=docker/dockerfile:1
FROM ruby:4.0.1-slim AS base
# Install runtime dependencies
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
libpq-dev \
postgresql-client \
curl \
gnupg \
ca-certificates \
libvips \
imagemagick \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
npm install -g pnpm@9.15.5 && \
rm -rf /var/lib/apt/lists/*
# Build stage
FROM base AS builder
# Install build dependencies
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy Gemfile and install gems
COPY Gemfile Gemfile.lock ./
RUN bundle config set --local deployment 'true' && \
bundle config set --local without 'development test' && \
bundle install --jobs 4 --retry 3
# Copy package files and install node modules
COPY package.json pnpm-lock.yaml ./
RUN NODE_ENV=production pnpm install --frozen-lockfile --ignore-scripts
# Copy application code
COPY . .
# Precompile assets
RUN SECRET_KEY_BASE=dummy RAILS_ENV=production bundle exec rails assets:precompile
# Clean up unnecessary files
RUN rm -rf node_modules tmp/cache vendor/bundle/ruby/*/cache/*.gem && \
find vendor/bundle/ruby/*/gems/ -name "*.c" -delete 2>/dev/null || true && \
find vendor/bundle/ruby/*/gems/ -name "*.o" -delete 2>/dev/null || true
# Production stage
FROM base AS production
# Create rails user
RUN useradd -m -s /bin/bash rails && \
mkdir -p /app && \
chown -R rails:rails /app
WORKDIR /app
# Copy application with precompiled assets (includes vendor/bundle)
COPY --from=builder --chown=rails:rails /app /app
# Set environment
ARG RUBY_ABI_VERSION=4.0.0
ENV RAILS_ENV=production \
NODE_ENV=production \
RAILS_SERVE_STATIC_FILES=true \
RAILS_LOG_TO_STDOUT=true \
BUNDLE_GEMFILE=/app/Gemfile \
BUNDLE_PATH=/app/vendor/bundle \
BUNDLE_BIN=/app/vendor/bundle/ruby/${RUBY_ABI_VERSION}/bin \
BUNDLE_APP_CONFIG=/app/.bundle \
GEM_HOME=/app/vendor/bundle \
PATH="/app/vendor/bundle/ruby/${RUBY_ABI_VERSION}/bin:${PATH}" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT=true
# Switch to rails user
USER rails
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Start server
CMD ["bundle", "exec", "falcon", "host"]