Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
97 lines (81 loc) · 4.05 KB
/
Copy pathDockerfile
File metadata and controls
97 lines (81 loc) · 4.05 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
ARG RUBY_VERSION=3.4.6
# Node and Ruby base images share the same Debian release so that glibc, libssl, and
# other system libraries line up between stages.
FROM docker.io/library/node:22-bookworm-slim AS node
FROM ruby:$RUBY_VERSION-slim-bookworm
# Yarn Classic / pnpm fallbacks for projects that haven't adopted corepack via
# `packageManager` in package.json. Override at build time (`--build-arg=YARN_CLASSIC_VERSION=...`)
# rather than editing this file so regenerating the Dockerfile keeps your pin.
ARG YARN_CLASSIC_VERSION=1.22.22
ARG PNPM_FALLBACK_VERSION=9.12.3
WORKDIR /app
# Keep Node.js available both for asset compilation and for SSR runtimes that
# rely on ExecJS in production. Narrowed to just what the node stage actually
# ships under /usr/local so we don't drag in unused Debian libs from that image.
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /usr/local/include/node /usr/local/include/node
RUN ln -sf ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
ln -sf ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx && \
ln -sf ../lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack && \
chmod +x /usr/local/lib/node_modules/npm/bin/npm-cli.js \
/usr/local/lib/node_modules/npm/bin/npx-cli.js \
/usr/local/lib/node_modules/corepack/dist/corepack.js && \
node --version && npm --version && corepack --version
# Expose Corepack-managed shims so later build steps can call yarn/pnpm
# directly during asset precompilation hooks.
RUN printf '%s\n' '#!/bin/sh' 'exec corepack yarn "$@"' > /usr/bin/yarn && \
chmod +x /usr/bin/yarn && \
printf '%s\n' '#!/bin/sh' 'exec corepack pnpm "$@"' > /usr/bin/pnpm && \
chmod +x /usr/bin/pnpm
# install ruby gems
COPY Gemfile* ./
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential && \
bundle config set without 'development test' && \
bundle config set with 'production' && \
bundle install --jobs=3 --retry=3 && \
apt-get purge -y --auto-remove build-essential && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
COPY . ./
# Install JavaScript dependencies only when the project actually has them.
# Pin `packageManager` in package.json to take the corepack path and avoid the
# YARN_CLASSIC_VERSION / PNPM_FALLBACK_VERSION fallbacks below; the fallbacks exist for
# projects that haven't adopted corepack and should be reviewed periodically as they go stale.
RUN if [ -f package.json ]; then \
package_manager="$(node -p "require('./package.json').packageManager || ''")"; \
if [ -f yarn.lock ]; then \
if printf '%s' "$package_manager" | grep -q '^yarn@'; then \
corepack prepare "$package_manager" --activate && \
(corepack yarn install --immutable || corepack yarn install --frozen-lockfile); \
else \
npm install -g "yarn@${YARN_CLASSIC_VERSION}" && \
(yarn install --immutable || yarn install --frozen-lockfile); \
fi; \
elif [ -f pnpm-lock.yaml ]; then \
if printf '%s' "$package_manager" | grep -q '^pnpm@'; then \
corepack prepare "$package_manager" --activate && \
corepack pnpm install --frozen-lockfile; \
else \
corepack prepare "pnpm@${PNPM_FALLBACK_VERSION}" --activate && \
corepack pnpm install --frozen-lockfile; \
fi; \
elif [ -f package-lock.json ]; then \
npm ci; \
else \
npm install; \
fi; \
fi
ENV RAILS_ENV=production
ENV RAILS_SERVE_STATIC_FILES=true
# Compiling assets requires any non-blank value, but the placeholder must not
# remain in the final image environment.
RUN SECRET_KEY_BASE=NOT_USED_NON_BLANK bin/shakapacker-precompile-hook
RUN SECRET_KEY_BASE=NOT_USED_NON_BLANK rails assets:precompile
# add entrypoint
COPY bin/docker-entrypoint /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
ARG GIT_COMMIT=unknown
ENV GIT_COMMIT=$GIT_COMMIT
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["rails", "s"]