Skip to content

Commit b6f7f63

Browse files
committed
deploy: Add Dockerfile.production.
1 parent 4df154e commit b6f7f63

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

Dockerfile.production

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
FROM docker.io/ruby:3.3.1-alpine3.18 AS base
2+
3+
RUN echo "@alpine/v3.16/main https://dl-cdn.alpinelinux.org/alpine/v3.16/main" >> /etc/apk/repositories \
4+
&& apk update \
5+
&& apk upgrade \
6+
&& apk add \
7+
build-base shared-mime-info mariadb-dev tzdata imagemagick \
8+
jemalloc \
9+
nodejs@alpine/v3.16/main yarn@alpine/v3.16/main \
10+
&& rm -rfv /var/cache/apk/*
11+
12+
# These are equivalent to always setting --deployment, --path, and --without when relevant.
13+
ENV BUNDLE_DEPLOYMENT="1"
14+
# Don't install to vendor/bundle.
15+
ENV BUNDLE_PATH="/usr/local/bundle"
16+
ENV BUNDLE_WITHOUT="development"
17+
18+
ENV RAILS_ENV="production"
19+
20+
WORKDIR /tap
21+
22+
23+
FROM base AS builder
24+
25+
COPY Gemfile Gemfile.lock ./
26+
RUN --mount=type=cache,target=vendor/cache bundle install && bundle cache
27+
RUN bundle exec bootsnap precompile --gemfile
28+
29+
COPY package.json yarn.lock ./
30+
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install --frozen-lockfile
31+
32+
COPY --parents \
33+
./app/ \
34+
./bin/ \
35+
./config/ \
36+
./db/ \
37+
./lib/ \
38+
./public/ \
39+
./spec/ \
40+
./.browserslistrc \
41+
./Rakefile \
42+
./babel.config.js \
43+
./config.ru \
44+
./postcss.config.js \
45+
./
46+
47+
RUN bundle exec bootsnap precompile app/ lib/
48+
RUN SECRET_KEY_BASE=1 ./bin/rails assets:precompile
49+
50+
51+
FROM base AS runner
52+
53+
COPY --from=builder "${BUNDLE_PATH}" "${BUNDLE_PATH}"
54+
COPY --from=builder /tap /tap
55+
56+
EXPOSE 80
57+
58+
COPY --chmod=755 <<"EOF" /entrypoint.sh
59+
#!/bin/sh
60+
set -eu
61+
62+
# Enable jemalloc for reduced memory usage and latency.
63+
LD_PRELOAD=/usr/lib/libjemalloc.so.2
64+
65+
echo -n "Waiting for database to start..."
66+
until ./bin/rails db:version 2>/dev/null; do
67+
echo -n .
68+
sleep .1
69+
done
70+
echo
71+
72+
# Create or migrate the database
73+
./bin/rails db:prepare
74+
75+
exec "${@}"
76+
EOF
77+
ENTRYPOINT ["/entrypoint.sh"]
78+
CMD ["./bin/rails", "server", "--binding=0.0.0.0", "--port=80"]

0 commit comments

Comments
 (0)