Skip to content

Commit abc9d6a

Browse files
update Dockerfile
1 parent e1b36c7 commit abc9d6a

File tree

7 files changed

+55
-58
lines changed

7 files changed

+55
-58
lines changed

.dockerignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# Ignore bundler config.
77
/.bundle
88

9+
# Ignore all environment files (except templates).
10+
/.env*
11+
!/.env*.erb
12+
913
# Ignore all default key files.
1014
/config/master.key
1115
/config/credentials/*.key
1216

13-
# Ignore all environment files.
14-
/.env*
15-
!/.env.example
16-
1717
# Ignore all logfiles and tempfiles.
1818
/log/*
1919
/tmp/*
@@ -31,6 +31,7 @@
3131
!/tmp/storage/.keep
3232

3333
# Ignore assets.
34+
/node_modules/
3435
/app/assets/builds/*
3536
!/app/assets/builds/.keep
3637
/public/assets

Dockerfile

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ FROM ruby:$RUBY_VERSION-slim as base
88
WORKDIR /rails
99

1010
# Set production environment
11-
ENV RAILS_ENV="production" \
12-
BUNDLE_WITHOUT="development:test" \
13-
BUNDLE_DEPLOYMENT="1"
11+
ENV BUNDLE_DEPLOYMENT="1" \
12+
BUNDLE_PATH="/usr/local/bundle" \
13+
BUNDLE_WITHOUT="development:test" \
14+
RAILS_ENV="production"
1415

1516
# Update gems and bundler
1617
RUN gem update --system --no-document && \
17-
gem install -N bundler
18+
gem install -N bundler
1819

19-
# Throw-away build stages to reduce size of final image
20-
FROM base as prebuild
20+
21+
# Throw-away build stage to reduce size of final image
22+
FROM base as build
2123

2224
# Install packages needed to build gems
2325
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
24-
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
25-
apt-get update -qq && \
26-
apt-get install --no-install-recommends -y build-essential curl libpq-dev pkg-config python-is-python3 libyaml-dev
27-
28-
FROM prebuild as build
26+
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
27+
apt-get update -qq && \
28+
apt-get install --no-install-recommends -y build-essential libpq-dev libyaml-dev pkg-config
2929

3030
# Install application gems
3131
COPY --link Gemfile Gemfile.lock ./
3232
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
33-
bundle config set app_config .bundle && \
34-
bundle config set path /srv/vendor && \
35-
bundle install && \
36-
bundle exec bootsnap precompile --gemfile && \
37-
bundle clean && \
38-
mkdir -p vendor && \
39-
bundle config set path vendor && \
40-
cp -ar /srv/vendor .
33+
bundle config set app_config .bundle && \
34+
bundle config set path /srv/vendor && \
35+
bundle install && \
36+
bundle exec bootsnap precompile --gemfile && \
37+
bundle clean && \
38+
mkdir -p vendor && \
39+
bundle config set path vendor && \
40+
cp -ar /srv/vendor .
4141

4242
# Copy application code
4343
COPY --link . .
@@ -46,36 +46,37 @@ COPY --link . .
4646
RUN bundle exec bootsnap precompile app/ lib/
4747

4848
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
49-
# We need to run precompile twice so Propshaft sees the newly compiled assets
50-
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5149
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5250

51+
5352
# Final stage for app image
5453
FROM base
5554

5655
# Install packages needed for deployment
5756
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
58-
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
59-
apt-get update -qq && \
60-
apt-get install --no-install-recommends -y curl postgresql-client ruby-foreman sudo unzip
57+
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
58+
apt-get update -qq && \
59+
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 libyaml-dev postgresql-client ruby-foreman sudo
6160

6261
# Copy built artifacts: gems, application
63-
COPY --from=build /usr/local/bundle /usr/local/bundle
62+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
6463
COPY --from=build /rails /rails
6564

6665
# Run and own only the runtime files as a non-root user for security
6766
RUN groupadd --system --gid 1000 rails && \
68-
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
69-
sed -i 's/env_reset/env_keep="*"/' /etc/sudoers && \
70-
chown -R 1000:1000 db log tmp
67+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
68+
sed -i 's/env_reset/env_keep="*"/' /etc/sudoers && \
69+
chown -R 1000:1000 db log storage tmp
7170
USER 1000:1000
7271

7372
# Deployment options
74-
ENV RUBY_YJIT_ENABLE="1"
73+
ENV LD_PRELOAD="libjemalloc.so.2" \
74+
MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true" \
75+
RUBY_YJIT_ENABLE="1"
7576

7677
# Entrypoint prepares the database.
7778
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
7879

7980
# Start the server by default, this can be overwritten at runtime
80-
EXPOSE 3000
81+
EXPOSE 80
8182
CMD ["foreman", "start", "--procfile=Procfile"]

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gem "bootsnap", ">= 1.1.0", require: false
77
gem "puma"
88
gem "propshaft"
99
gem "sqlite3"
10+
gem "thruster"
1011

1112
gem "elasticsearch-persistence"
1213
gem "opensearch-aws-sigv4"

Gemfile.lock

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,10 @@ GEM
110110
bigdecimal
111111
rexml
112112
crass (1.0.6)
113-
datadog-ci (0.8.3)
114-
msgpack
115113
date (3.4.1)
116-
ddtrace (1.23.3)
117-
datadog-ci (~> 0.8.1)
118-
debase-ruby_core_source (= 3.3.1)
119-
libdatadog (~> 7.0.0.1.0)
120-
libddwaf (~> 1.14.0.0.0)
114+
ddtrace (0.48.0)
115+
ffi (~> 1.0)
121116
msgpack
122-
debase-ruby_core_source (3.3.1)
123117
debug (1.10.0)
124118
irb (~> 1.10)
125119
reline (>= 0.3.8)
@@ -251,17 +245,6 @@ GEM
251245
kaminari-core (= 1.2.2)
252246
kaminari-core (1.2.2)
253247
language_server-protocol (3.17.0.3)
254-
libdatadog (7.0.0.1.0)
255-
libdatadog (7.0.0.1.0-aarch64-linux)
256-
libdatadog (7.0.0.1.0-x86_64-linux)
257-
libddwaf (1.14.0.0.0-aarch64-linux)
258-
ffi (~> 1.0)
259-
libddwaf (1.14.0.0.0-arm64-darwin)
260-
ffi (~> 1.0)
261-
libddwaf (1.14.0.0.0-x86_64-darwin)
262-
ffi (~> 1.0)
263-
libddwaf (1.14.0.0.0-x86_64-linux)
264-
ffi (~> 1.0)
265248
lint_roller (1.1.0)
266249
listen (3.9.0)
267250
rb-fsevent (~> 0.10, >= 0.10.3)
@@ -460,6 +443,10 @@ GEM
460443
tailwindcss-ruby (4.0.14-x86_64-darwin)
461444
tailwindcss-ruby (4.0.14-x86_64-linux-gnu)
462445
thor (1.3.2)
446+
thruster (0.1.12-aarch64-linux)
447+
thruster (0.1.12-arm64-darwin)
448+
thruster (0.1.12-x86_64-darwin)
449+
thruster (0.1.12-x86_64-linux)
463450
timeout (0.4.3)
464451
trenni (3.13.1)
465452
rake-compiler
@@ -543,6 +530,7 @@ DEPENDENCIES
543530
standard-rails
544531
stimulus-rails
545532
tailwindcss-rails
533+
thruster
546534
trenni-sanitize
547535
tty-spinner
548536
typhoeus

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: bundle exec rails server -p ${PORT:-3000}
1+
web: thrust bin/rails server -p ${PORT:-3000}

bin/docker-entrypoint

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash -e
22

3-
# If running the rails server then create or migrate existing database
4-
# if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
5-
# ./bin/rails db:prepare
6-
# fi
3+
if [ "${*}" == "foreman start --procfile=Procfile" ]; then
4+
./bin/rails db:prepare
5+
fi
76

87
exec "${@}"

config/dockerfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
---
44
options:
55
cache: true
6+
jemalloc: true
67
parallel: true
78
postgresql: true
89
procfile: Procfile
910
sudo: true
11+
thruster: true
1012
yjit: true
13+
packages:
14+
build:
15+
- libyaml-dev
16+
deploy:
17+
- libyaml-dev

0 commit comments

Comments
 (0)