-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
62 lines (49 loc) · 1.77 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
# RUBY_VERSION set by build.sh based on .ruby-version file
ARG RUBY_VERSION
FROM public.ecr.aws/docker/library/ruby:${RUBY_VERSION}-alpine
# DataDog logs source
LABEL com.datadoghq.ad.logs='[{"source": "ruby"}]'
# Create web application user to run as non-root
RUN addgroup -g 1000 webapp \
&& adduser -u 1000 -G webapp -s /bin/sh -D webapp \
&& mkdir -p /home/webapp/app
WORKDIR /home/webapp/app
# Upgrade alpine packages (useful for security fixes)
RUN apk upgrade --no-cache
# Install rails/app dependencies
RUN apk --no-cache add \
libc6-compat \
git \
postgresql-libs \
tzdata \
nodejs \
imagemagick \
imagemagick-libs \
ghostscript \
ghostscript-fonts
# Copy dependency definitions and lock files
COPY Gemfile Gemfile.lock ./
# Install bundler version which created the lock file and configure it
RUN gem install bundler -v $(awk '/^BUNDLED WITH/ { getline; print $1; exit }' Gemfile.lock)
# Install build-dependencies, then install gems, subsequently removing build-dependencies
RUN apk --no-cache add --virtual build-deps build-base postgresql-dev imagemagick-dev ghostscript-dev \
&& bundle install --jobs 20 --retry 2 \
&& apk del build-deps
# Copy the application
COPY . .
# Environment required to build the application
ARG RAILS_ENV=production
ARG SECRET_KEY_BASE
ARG SMTP_ADDRESS=
ARG SMTP_USER_NAME=
ARG SMTP_PASSWORD=
# Compile assets
RUN RAILS_ENV=production bundle exec rake assets:precompile \
&& chown -R webapp:webapp /home/webapp/
# Define volumes used by ECS to share public html and extra nginx config with nginx container
VOLUME /home/webapp/app/public
VOLUME /home/webapp/app/nginx-conf
# Run container process as non-root user
USER webapp
# Command to start rails
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]