Skip to content

Commit a4835dc

Browse files
committed
Run rails generate dockerfile
1 parent 6466368 commit a4835dc

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

.dockerignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
# Ignore bundler config.
88
/.bundle
99

10-
# Ignore all environment files (except templates).
10+
# Ignore all environment files.
1111
/.env*
12-
!/.env*.erb
1312

1413
# Ignore all default key files.
1514
/config/master.key
@@ -40,6 +39,10 @@
4039
# Ignore CI service files.
4140
/.github
4241

42+
# Ignore Kamal files.
43+
/config/deploy*.yml
44+
/.kamal
45+
4346
# Ignore development files
4447
/.devcontainer
4548

Dockerfile

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1-
# syntax = docker/dockerfile:1
1+
# syntax=docker/dockerfile:1
2+
# check=error=true
23

3-
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
45
ARG RUBY_VERSION=3.4.2
5-
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-jemalloc-slim as base
6+
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-jemalloc-slim AS base
67

78
LABEL fly_launch_runtime="rails"
89

910
# Rails app lives here
1011
WORKDIR /rails
1112

13+
# Update gems and bundler
14+
RUN gem update --system --no-document && \
15+
gem install -N bundler
16+
17+
# Install base packages
18+
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
19+
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
20+
apt-get update -qq && \
21+
apt-get install --no-install-recommends -y curl sqlite3
22+
1223
# Set production environment
1324
ENV BUNDLE_DEPLOYMENT="1" \
1425
BUNDLE_PATH="/usr/local/bundle" \
1526
BUNDLE_WITHOUT="development:test" \
1627
RAILS_ENV="production"
1728

18-
# Update gems and bundler
19-
RUN gem update --system --no-document && \
20-
gem install -N bundler
21-
2229

2330
# Throw-away build stages to reduce size of final image
24-
FROM base as prebuild
31+
FROM base AS prebuild
2532

2633
# Install packages needed to build gems and node modules
2734
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
2835
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
2936
apt-get update -qq && \
30-
apt-get install --no-install-recommends -y build-essential curl libpq-dev libyaml-dev node-gyp pkg-config python-is-python3
37+
apt-get install --no-install-recommends -y build-essential libffi-dev libyaml-dev node-gyp pkg-config python-is-python3
3138

3239

33-
FROM prebuild as node
40+
FROM prebuild AS node
3441

3542
# Install JavaScript dependencies
36-
ARG NODE_VERSION=20.10.0
43+
ARG NODE_VERSION=20.12.2
3744
ARG YARN_VERSION=1.22.22
3845
ENV PATH=/usr/local/node/bin:$PATH
3946
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
@@ -42,15 +49,15 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz
4249
rm -rf /tmp/node-build-master
4350

4451
# Install node modules
45-
COPY --link package.json yarn.lock ./
52+
COPY package.json yarn.lock ./
4653
RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
4754
YARN_CACHE_FOLDER=/root/.yarn yarn install --frozen-lockfile
4855

4956

50-
FROM prebuild as build
57+
FROM prebuild AS build
5158

5259
# Install application gems
53-
COPY --link Gemfile Gemfile.lock ./
60+
COPY Gemfile Gemfile.lock ./
5461
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
5562
bundle config set app_config .bundle && \
5663
bundle config set path /srv/vendor && \
@@ -67,7 +74,7 @@ COPY --from=node /usr/local/node /usr/local/node
6774
ENV PATH=/usr/local/node/bin:$PATH
6875

6976
# Copy application code
70-
COPY --link . .
77+
COPY . .
7178

7279
# Precompile bootsnap code for faster boot times
7380
RUN bundle exec bootsnap precompile app/ lib/
@@ -79,27 +86,26 @@ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
7986
# Final stage for app image
8087
FROM base
8188

82-
# Install packages needed for deployment
83-
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
84-
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
85-
apt-get update -qq && \
86-
apt-get install --no-install-recommends -y curl postgresql-client
8789

8890
# Copy built artifacts: gems, application
89-
COPY --from=build /usr/local/bundle /usr/local/bundle
91+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
9092
COPY --from=build /rails /rails
9193

9294
# Run and own only the runtime files as a non-root user for security
9395
RUN groupadd --system --gid 1000 rails && \
9496
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
95-
chown -R 1000:1000 db log storage tmp
97+
mkdir /data && \
98+
chown -R 1000:1000 db log storage tmp /data
9699
USER 1000:1000
97100

98101
# Deployment options
99-
ENV RUBY_YJIT_ENABLE="1"
102+
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
103+
RUBY_YJIT_ENABLE="1"
100104

101105
# Entrypoint sets up the container.
102106
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
103107

104108
# Start the server by default, this can be overwritten at runtime
105109
EXPOSE 3000
110+
VOLUME /data
111+
CMD ["./bin/rails", "server"]

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ GEM
139139
factory_bot (~> 6.5)
140140
railties (>= 5.0.0)
141141
ffi (1.17.1)
142+
ffi (1.17.1-aarch64-linux-gnu)
142143
ffi (1.17.1-x86_64-linux-gnu)
143144
ffi-compiler (1.3.2)
144145
ffi (>= 1.15.5)
@@ -207,6 +208,8 @@ GEM
207208
nokogiri (1.18.3)
208209
mini_portile2 (~> 2.8.2)
209210
racc (~> 1.4)
211+
nokogiri (1.18.3-aarch64-linux-gnu)
212+
racc (~> 1.4)
210213
nokogiri (1.18.3-x86_64-linux-gnu)
211214
racc (~> 1.4)
212215
parallel (1.26.3)
@@ -344,6 +347,7 @@ GEM
344347
spring (>= 4)
345348
sqlite3 (2.6.0)
346349
mini_portile2 (~> 2.8.0)
350+
sqlite3 (2.6.0-aarch64-linux-gnu)
347351
sqlite3 (2.6.0-x86_64-linux-gnu)
348352
stimulus-rails (1.3.4)
349353
railties (>= 6.0.0)
@@ -375,6 +379,7 @@ GEM
375379
zeitwerk (2.7.2)
376380

377381
PLATFORMS
382+
aarch64-linux
378383
ruby
379384
x86_64-linux
380385

bin/docker-entrypoint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash -e
22

3+
# Enable jemalloc for reduced memory usage and latency.
4+
if [ -z "${LD_PRELOAD+x}" ]; then
5+
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
6+
export LD_PRELOAD
7+
fi
8+
39
# Add any container initialization steps here
410

511
exec "${@}"

config/dockerfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
options:
55
cache: true
66
fullstaq: true
7-
jemalloc: true
87
label:
98
fly_launch_runtime: rails
109
parallel: true
1110
prepare: false
11+
sqlite3: true
1212
yjit: true

0 commit comments

Comments
 (0)