-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathDockerfile
More file actions
148 lines (115 loc) 路 4.41 KB
/
Copy pathDockerfile
File metadata and controls
148 lines (115 loc) 路 4.41 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Setting global arguments
ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_DEPLOYMENT=true
FROM ruby:4.0.6-alpine AS build-env
# include global args
ARG BUNDLE_WITHOUT
ARG BUNDLE_DEPLOYMENT
LABEL org.opencontainers.image.authors='pglombardo@hey.com'
# Required build packages - install in single layer for better caching
RUN apk update && apk add --no-cache \
git \
build-base \
musl-dev \
libc6-compat \
libpq-dev \
mariadb-dev \
nodejs \
sqlite-dev \
tzdata \
yaml-dev \
yarn \
pkgconf \
openssl-dev \
libffi-dev
ENV APP_ROOT=/opt/PasswordPusher
ENV RACK_ENV=production RAILS_ENV=production
WORKDIR ${APP_ROOT}
# Copy dependency files first for better layer caching
COPY Gemfile Gemfile.lock ./
# Install Ruby dependencies - this layer will be cached unless Gemfile changes
RUN bundle config set without "${BUNDLE_WITHOUT}" \
&& bundle config set deployment "${BUNDLE_DEPLOYMENT}" \
&& bundle install \
&& rm -rf vendor/bundle/ruby/*/cache \
&& rm -rf vendor/bundle/ruby/*/bundler/gems/*/.git \
&& find vendor/bundle/ruby/*/gems/ -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "*.o" -delete
# Copy Node.js dependency files
COPY package.json yarn.lock ./
# Install Node.js dependencies - this layer will be cached unless package.json changes
RUN yarn install --frozen-lockfile
# Copy source code - this should be done as late as possible
COPY ./ ${APP_ROOT}/
# Full multi-theme CSS (build_themes.js) runs during assets:precompile.
# See config/application.rb for the CSS build policy.
# SECRET_KEY_BASE must be set at runtime via environment variable
# Do NOT hardcode secrets in Docker images for security reasons.
# Users should generate their own secret_key_base:
# bundle exec rails secret
# Then set it when running the container:
# docker run -e SECRET_KEY_BASE=<your-secret> ...
# Precompile bootsnap cache only for amd64 architecture
RUN if [ "$TARGETARCH" = "amd64" ]; then \
SECRET_KEY_BASE_DUMMY=1 bundle exec bootsnap precompile --gemfile && \
SECRET_KEY_BASE_DUMMY=1 bundle exec bootsnap precompile app/ lib/ ; \
else \
echo "Skipping bootsnap precompilation for $TARGETARCH" ; \
fi
# Precompile Rails assets - this layer will be rebuilt when assets change
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
RUN rm -rf tmp/cache tmp/pids tmp/sockets app/assets/images/features
################## Build done ##################
FROM ruby:4.0.6-alpine
# include global args
ARG BUNDLE_WITHOUT
ARG BUNDLE_DEPLOYMENT
LABEL maintainer='pglombardo@hey.com'
# Install runtime packages in single layer for better caching
RUN apk update && apk add --no-cache \
bash \
curl \
libc6-compat \
libpq \
mariadb-connector-c \
nodejs \
tzdata \
yarn \
jemalloc
# Create a user and group to run the application
ARG UID=1000
ARG GID=1000
# Set environment variables
ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher
ENV RACK_ENV=production RAILS_ENV=production
ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
WORKDIR ${APP_ROOT}
# Create user and set permissions in single layer
RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher
# SECRET_KEY_BASE must be set at runtime via environment variable
# The entrypoint script will validate or generate one if missing
# Copy application from build stage
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}
# Configure bundle for production
RUN bundle config set without "${BUNDLE_WITHOUT}" \
&& bundle config set deployment "${BUNDLE_DEPLOYMENT}"
# Make sure that the storage directory exists
RUN mkdir -p ${APP_ROOT}/storage/db && chown -R pwpusher:pwpusher ${APP_ROOT}/storage
# Copy and setup entrypoints in single layer
COPY containers/docker/entrypoint.sh /usr/local/bin/docker-entrypoint
COPY containers/docker/worker-entrypoint.sh /usr/local/bin/docker-worker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint /usr/local/bin/docker-worker-entrypoint
# Clean up unnecessary files
RUN rm -rf ${APP_ROOT}/.do \
${APP_ROOT}/.github \
${APP_ROOT}/app.json \
${APP_ROOT}/bin/move_up_stable_tag.sh \
${APP_ROOT}/containers \
${APP_ROOT}/test \
${APP_ROOT}/ct.yaml
RUN touch /opt/PasswordPusher/.env.production && chown pwpusher:pwpusher /opt/PasswordPusher/.env.production
USER pwpusher
EXPOSE 80 443 5100
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]