-
Notifications
You must be signed in to change notification settings - Fork 371
/
Copy pathDockerfile
124 lines (97 loc) · 3.46 KB
/
Dockerfile
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
# Setting global arguments
ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_DEPLOYMENT=true
FROM ruby:3.4-alpine AS build-env
# include global args
ARG BUNDLE_WITHOUT
ARG BUNDLE_DEPLOYMENT
LABEL org.opencontainers.image.authors='[email protected]'
# Required build packages
RUN 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
ENV APP_ROOT=/opt/PasswordPusher
WORKDIR ${APP_ROOT}
COPY Gemfile Gemfile.lock package.json yarn.lock ./
ENV RACK_ENV=production RAILS_ENV=production
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
RUN yarn install
COPY ./ ${APP_ROOT}/
RUN yarn build
# Set DATABASE_URL to sqlite to have a ready
# to use db file for ephemeral configuration
ENV DATABASE_URL=sqlite3:db/db.sqlite3
# Set a default secret_key_base
# For those self-hosting this app, you should
# generate your own secret_key_base and set it
# in your environment.
# 1. Generate a secret_key_base value with:
# bundle exec rails secret
# 2. Set the secret_key_base in your environment:
# SECRET_KEY_BASE=<value>
ENV SECRET_KEY_BASE=783ff1544b9612d8bceb8e26a0bab0cf22543eec658a498e7ef9e1d617976f960092005c8a54cb588759dc6dd8fd054bc4eca4a94dd7b96c6efda4a14a01bfbd
# Precompile bootsnap cache for gems an application code to improve load time
# This creates a cache of the gem requires and application code which speeds up application boot
# Note: This must be run AFTER bundle install since it caches the installed gems
RUN bundle exec bootsnap precompile --gemfile
RUN bundle exec bootsnap precompile app/ lib/
RUN bundle exec rails assets:precompile
RUN bundle exec rake db:setup && rm -rf tmp/cache tmp/pids tmp/sockets
################## Build done ##################
FROM ruby:3.4-alpine
# include global args
ARG BUNDLE_WITHOUT
ARG BUNDLE_DEPLOYMENT
LABEL maintainer='[email protected]'
# install only runtime packages (removed build-related packages)
RUN apk add --no-cache \
bash \
curl \
libc6-compat \
libpq \
mariadb-connector-c \
nodejs \
tzdata \
yarn
# Create a user and group to run the application
ARG UID=1000
ARG GID=1000
ENV LC_CTYPE=UTF-8 LC_ALL=en_US.UTF-8
ENV APP_ROOT=/opt/PasswordPusher
WORKDIR ${APP_ROOT}
ENV RACK_ENV=production RAILS_ENV=production
RUN addgroup -g "${GID}" pwpusher \
&& adduser -D -u "${UID}" -G pwpusher pwpusher \
&& chown -R pwpusher:pwpusher ${APP_ROOT}
# Set a default secret_key_base
# For those self-hosting this app, you should
# generate your own secret_key_base and set it
# in your environment.
# 1. Generate a secret_key_base value with:
# bundle exec rails secret
# 2. Set the secret_key_base in your environment:
# SECRET_KEY_BASE=<value>
ENV SECRET_KEY_BASE=783ff1544b9612d8bceb8e26a0bab0cf22543eec658a498e7ef9e1d617976f960092005c8a54cb588759dc6dd8fd054bc4eca4a94dd7b96c6efda4a14a01bfbd
COPY --from=build-env --chown=pwpusher:pwpusher ${APP_ROOT} ${APP_ROOT}
RUN bundle config set without "${BUNDLE_WITHOUT}" \
&& bundle config set deployment "${BUNDLE_DEPLOYMENT}"
USER pwpusher
EXPOSE 5100
ENTRYPOINT ["containers/docker/entrypoint.sh"]