-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathDockerfile
More file actions
107 lines (87 loc) · 2.89 KB
/
Dockerfile
File metadata and controls
107 lines (87 loc) · 2.89 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
96
97
98
99
100
101
102
103
104
105
106
107
# Build stage - includes devDependencies for asset compilation
FROM ruby:3.4.3-slim as builder
ENV RAILS_ENV production
WORKDIR /app
# Update rubygems
RUN gem update --system
RUN printf "install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri" > ~/.gemrc
RUN gem install --no-document --force bundler -v 2.4.21
# Install build dependencies with minimal footprint
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
build-essential \
git \
postgresql-client \
libpq-dev \
tzdata \
curl \
gnupg2 \
libyaml-dev \
ca-certificates \
libvips-dev && \
rm -rf /var/lib/apt/lists/*
# Install Node.js 22.x
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get update && \
apt-get install -y --no-install-recommends nodejs && \
rm -rf /var/lib/apt/lists/*
# Set timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
# Install ALL npm packages (including devDependencies for asset compilation)
COPY package.json package-lock.json ./
RUN npm install
# Install gems
COPY Gemfile Gemfile.lock ./
RUN bundle install -j4
# Copy application code
COPY . ./
# Compile assets (now with devDependencies available)
ENV RAILS_LOG_TO_STDOUT true
ENV SHAKAPACKER_NODE_MODULES_BIN_PATH ./node_modules/.bin
RUN SECRET_KEY_BASE=dummy bundle exec rails assets:precompile
# Production stage - minimal runtime image
FROM ruby:3.4.3-slim as production
ENV RAILS_ENV production
WORKDIR /app
# Update rubygems
RUN gem update --system
RUN printf "install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri" > ~/.gemrc
RUN gem install --no-document --force bundler -v 2.4.21
# Install runtime and build dependencies
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
build-essential \
postgresql-client \
libpq-dev \
libyaml-dev \
tzdata \
curl \
gnupg2 \
git \
ca-certificates \
libvips && \
rm -rf /var/lib/apt/lists/*
# Set timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
# Install Node.js 22.x (runtime only)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get update && \
apt-get install -y --no-install-recommends nodejs && \
rm -rf /var/lib/apt/lists/*
# Copy gems configuration
COPY Gemfile Gemfile.lock ./
RUN bundle install -j4
# Install only production npm packages
COPY package.json package-lock.json ./
RUN npm install --omit=dev
# Copy application code from builder (excluding large directories)
COPY --from=builder /app/app ./app
COPY --from=builder /app/bin ./bin
COPY --from=builder /app/config ./config
COPY --from=builder /app/db ./db
COPY --from=builder /app/lib ./lib
COPY --from=builder /app/public ./public
COPY --from=builder /app/Rakefile ./Rakefile
COPY --from=builder /app/config.ru ./config.ru
ENV PORT 3000
ENV RAILS_LOG_TO_STDOUT true
EXPOSE 3000
CMD bin/rails server -p $PORT -e $RAILS_ENV