-
Notifications
You must be signed in to change notification settings - Fork 249
/
Dockerfile
99 lines (74 loc) · 3.26 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
ARG BASE_IMAGE=public.ecr.aws/docker/library/ruby:3.3.5-slim-bookworm
ARG NODE_IMAGE=public.ecr.aws/docker/library/node:18-bookworm-slim@sha256:d2d8a6420c9fc6b7b403732d3a3c5395d016ebc4996f057aad1aded74202a476
FROM $BASE_IMAGE AS builder
WORKDIR /app
RUN echo "--- :package: Installing system deps" \
# Cache apt
rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
# Install a few pre-reqs
&& apt-get update \
&& apt-get install -y curl gnupg \
# Setup apt for GH cli
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
# Install all the things
&& apt-get update \
&& apt-get install -y gh jq build-essential \
## Pull down security updates
&& apt-get upgrade -y \
# Upgrade rubygems and bundler
&& gem update --system \
&& gem install bundler \
# clean up
&& rm -rf /tmp/*
# ------------------------------------------------------------------
FROM builder AS bundle
COPY Gemfile Gemfile.lock .ruby-version ./
ARG RAILS_ENV
RUN echo "--- :bundler: Installing ruby gems" \
&& bundle config set --local without "$([ "$RAILS_ENV" = "production" ] && echo 'development test')" \
&& bundle config set force_ruby_platform true \
&& bundle install --jobs $(nproc) --retry 3
# ------------------------------------------------------------------
FROM $NODE_IMAGE as node-deps
COPY package.json yarn.lock ./
RUN echo "--- :yarn: Installing node packages" && yarn
# ------------------------------------------------------------------
FROM builder as assets
COPY . /app/
COPY --from=node-deps /usr/local/bin /usr/local/bin
COPY --from=node-deps /node_modules /app/node_modules
COPY --from=bundle /usr/local/bundle/ /usr/local/bundle/
ARG RAILS_ENV
RUN if [ "$RAILS_ENV" = "production" ]; then \
echo "--- :vite: Compiling assets" \
&& RAILS_ENV=production RAILS_GROUPS=assets SECRET_KEY_BASE=xxx bundle exec rake assets:precompile \
&& cp -r /app/public/docs/assets /app/public/assets; \
fi
# ------------------------------------------------------------------
FROM $BASE_IMAGE AS runtime
# Install a few misc. deps for CI
RUN apt-get update && apt-get install -y curl jq
RUN apt purge --assume-yes linux-libc-dev
WORKDIR /app
ARG RAILS_ENV
ARG DD_RUM_VERSION="unknown"
ARG DD_RUM_ENV="unknown"
# Config. Don't love this.
ENV RAILS_ENV=$RAILS_ENV
ENV DD_RUM_ENV=${DD_RUM_ENV}
ENV DD_RUM_VERSION=${DD_RUM_VERSION}
ENV DD_RUM_ENABLED=true
ENV RAILS_SERVE_STATIC_FILES=true
ENV SEGMENT_TRACKING_ID=q0LtPl49tgnyHHY8PGBsPsshHk9AVNKm
ENV SECRET_KEY_BASE=xxx
COPY . /app
COPY --from=node-deps /usr/local/bin /usr/local/bin
COPY --from=node-deps /node_modules /app/node_modules
COPY --from=bundle /usr/local/bundle/ /usr/local/bundle/
COPY --from=assets /app/public/ /app/public/
RUN bundle exec rake sitemap:create
EXPOSE 3000
CMD ["bundle", "exec", "puma", "-C", "./config/puma.rb"]