-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile-build-base
98 lines (87 loc) · 3.05 KB
/
Dockerfile-build-base
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
# Docker image for Decidim instance.
# ===
# This image is not suited for a development environment.
# The build is done in 3 steps:
# 2. Dependancy: a heavier image to build assets and native gems
# 3. Final: will take results of dependancy to serve a small and minimal image.
#
# The idea behind this process is to expose in the deployed image as few as possible dependancies.
# Reducing this way the number of security issues.
#
# Arguments
# ===
# * ALPINE_RUBY_VERSION: the version of alpine ruby to use, without "ruby-" prefix
# * BUNDLER_VERSION: bundler version
# * NODE_VERSION: node version with "v" prefix
#
# Filesystem
# ===
# * /home/decidim/app : Working directory
# * /home/decidim/vendor : Installed gems
#
# Volumes
# ===
# Some volumes will be mapped by defaults:
# * storage
# * public
# * log
# * ../vendor: to cache gems
ARG ALPINE_RUBY_VERSION=2.7.3
ARG BUNDLER_VERSION=2.2.22
# Should exists for alpine, see https://unofficial-builds.nodejs.org/download/release/
ARG NODE_VERSION=v16.13.0
########################################################################
# Dependancy layer
########################################################################
FROM ruby:${ALPINE_RUBY_VERSION}-alpine
ARG BUNDLER_VERSION
ARG NODE_VERSION
ENV BUNDLER_VERSION=$BUNDLER_VERSION \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3 \
NODE_VERSION=$NODE_VERSION \
RAILS_ROOT=/home/decidim/app \
NVM_DIR=/usr/local/nvm \
NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release \
NVM_ARCH=x64-musl \
RAILS_ENV=production \
RACK_ENV=production
ENV PATH=$PATH:$NVM_DIR
WORKDIR $RAILS_ROOT
RUN mkdir -p $NVM_DIR
# Install dependencies:
# - build-base: To ensure certain gems can be compiled
# - postgresql-dev postgresql-client: Communicate with postgres through the postgres gem
# - libxslt-dev libxml2-dev: Nokogiri native dependencies
# - imagemagick: for image processing
# - git: for gemfiles using git
# - bash curl: to download nvm and install it
# - libstdc++: to build NVM
RUN apk update && apk upgrade && \
gem update --system && \
gem install bundler --version "$BUNDLER_VERSION" && \
apk --update --no-cache add \
build-base \
tzdata \
postgresql-dev postgresql-client \
libxslt-dev libxml2-dev \
imagemagick \
git \
bash curl \
libstdc++ \
&& rm -rf /var/cache/apk/*
# Install nvm, to have the approriate node version to compile assets
RUN touch $RAILS_ROOT/.profile && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash; \
source $NVM_DIR/nvm.sh; \
echo "nvm_get_arch() { nvm_echo \"x64-musl\"; }" >> $RAILS_ROOT/.profile; source $RAILS_ROOT/.profile;\
nvm install $NODE_VERSION
# Install gems
COPY Gemfile Gemfile.lock ./
# Configure bundler path, and install gems if needed (dev, test and production)
RUN bundle config set without 'development test' && \
bundle install && \
rm -rf /usr/local/bundle/cache/ /usr/local/bundle/bundler/gems/*/.git
# Add code
COPY . ./
RUN mkdir -p /certs