-
Notifications
You must be signed in to change notification settings - Fork 176
/
Dockerfile
131 lines (101 loc) · 3.57 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
125
126
127
128
129
130
131
FROM ruby:3.3.5 AS base
ARG BUILD_TAG=local
ARG WCA_LIVE_SITE
ARG SHAKAPACKER_ASSET_HOST
WORKDIR /rails
ENV DEBIAN_FRONTEND noninteractive
# Set production environment
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_ENV="production" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT="1" \
BUILD_TAG=$BUILD_TAG \
WCA_LIVE_SITE=$WCA_LIVE_SITE \
SHAKAPACKER_ASSET_HOST=$SHAKAPACKER_ASSET_HOST
# Add dependencies necessary to install nodejs.
# From: https://github.com/nodesource/distributions#debian-and-ubuntu-based-distributions
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
ca-certificates \
curl \
gnupg
ARG NODE_MAJOR=20
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash && \
apt-get install -y nodejs
FROM base AS build
# Enable 'corepack' feature that lets NPM download the package manager on-the-fly as required.
RUN corepack enable
# Install native dependencies for Ruby:
# libvips = image processing for Rails ActiveStorage attachments
# libssl-dev = bindings for the native extensions of Ruby SSL gem
# libyaml-dev = bindings for the native extensions of Ruby psych gem
# tzdata = Timezone information for Rails ActiveSupport
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
build-essential \
software-properties-common \
git \
pkg-config \
libvips \
libssl-dev \
libyaml-dev \
tzdata
# Install application gems
COPY Gemfile Gemfile.lock ./
RUN gem update --system && gem install bundler
COPY . .
RUN ./bin/bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
# Install node dependencies
COPY package.json yarn.lock .yarnrc.yml ./
RUN ./bin/yarn install --immutable
RUN ASSETS_COMPILATION=true SECRET_KEY_BASE=1 ./bin/bundle exec i18n export
RUN ASSETS_COMPILATION=true SECRET_KEY_BASE=1 ./bin/rake assets:precompile
RUN rm -rf node_modules
FROM base AS runtime
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
mariadb-client \
zip \
python-is-python3
# Copy built artifacts: gems, application
COPY --from=build /rails .
# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails vendor db log tmp public app pids
FROM runtime AS sidekiq
USER rails:rails
RUN gem install mailcatcher
ENTRYPOINT ["/rails/bin/docker-entrypoint-sidekiq"]
FROM runtime AS shoryuken
USER rails:rails
ENTRYPOINT ["/rails/bin/docker-entrypoint-shoryuken"]
FROM runtime AS monolith
EXPOSE 3000
# Install fonts for rendering PDFs (mostly competition summary PDFs)
# dejavu = Hebrew, Arabic, Greek
# unfonts-core = Korean
# wqy-modern = Chinese
# ipafont = Japanese
# lmodern = Random accents and special symbols for Latin script
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
fonts-dejavu \
fonts-unfonts-core \
fonts-wqy-microhei \
fonts-ipafont \
fonts-lmodern
USER rails:rails
# Regenerate the font cache so WkHtmltopdf can find them
# per https://dalibornasevic.com/posts/76-figuring-out-missing-fonts-for-wkhtmltopdf
RUN fc-cache -f -v
# Entrypoint prepares database and starts app on 0.0.0.0:3000 by default,
# but can also take a rails command, like "console" or "runner" to start instead.
ENV PIDFILE="/rails/pids/puma.pid"
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
CMD ["./bin/rails", "server"]
FROM runtime AS monolith-api
EXPOSE 3000
USER rails:rails
ENV API_ONLY="true"
CMD ["./bin/rails", "server"]