-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
91 lines (67 loc) · 2.34 KB
/
Copy pathDockerfile
File metadata and controls
91 lines (67 loc) · 2.34 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
### === base === ###
FROM ruby:4.0.6-alpine AS base
RUN apk add --no-cache --update postgresql-dev yaml-dev tzdata nodejs npm libffi-dev curl && \
gem install bundler
WORKDIR /rails
# ENV BUNDLE_PATH="/usr/local/bundle"
RUN adduser -D rails && \
chown -R rails:rails /rails /usr/local/bundle
### === development === ###
FROM base AS development
RUN apk add --no-cache --update build-base \
linux-headers \
gcompat \
git \
yarn \
less \
curl \
gnupg \
openssh-client \
postgresql18-client \
musl musl-utils musl-locales
USER rails:rails
ENV BINDING=0.0.0.0
### === test === ###
FROM development AS test
COPY --chown=rails:rails Gemfile Gemfile.lock ./
RUN --mount=type=cache,id=gems,target=/usr/local/bundle/cache,uid=1000,gid=1000,sharing=locked \
bundle install && \
bundle exec bootsnap precompile --gemfile
COPY --chown=rails:rails package.json yarn.lock ./
RUN --mount=type=cache,id=yarn,target=/yarn-cache,uid=1000,gid=1000,sharing=locked \
yarn install --cache-folder /yarn-cache
COPY --chown=rails:rails . .
RUN bundle exec bootsnap precompile app/ lib/
### === build === ###
FROM base AS build
RUN apk add --no-cache --update build-base git yarn
USER rails:rails
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_WITHOUT="development" \
NODE_ENV="production" \
APP_HOST="localhost"
COPY --chown=rails:rails Gemfile Gemfile.lock ./
RUN --mount=type=cache,id=gems,target=/usr/local/bundle/cache,uid=1000,gid=1000,sharing=locked \
bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
COPY --chown=rails:rails package.json yarn.lock ./
RUN --mount=type=cache,id=yarn,target=/yarn-cache,uid=1000,gid=1000,sharing=locked \
yarn install --cache-folder /yarn-cache
COPY --chown=rails:rails . .
RUN bundle exec bootsnap precompile app/ lib/ && \
bin/vite build
### === production === ###
FROM base AS production
EXPOSE 3000
CMD ["bin/rails", "s", "-b", "0.0.0.0"]
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_WITHOUT="development"
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
RUN rm -rf node_modules spec coverage
USER rails:rails
ARG VERSION_SUFFIX=""
RUN if [ -n "$VERSION_SUFFIX" ]; then echo "$VERSION_SUFFIX" >> VERSION; fi