forked from avalonmediasystem/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
165 lines (140 loc) · 6.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Base stage for building gems
FROM ruby:3.2-bullseye AS bundle
LABEL stage=build
LABEL project=avalon
RUN apt-get update && apt-get upgrade -y build-essential && apt-get autoremove \
&& apt-get install -y --no-install-recommends --fix-missing \
cmake \
pkg-config \
zip \
git \
ffmpeg \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
ENV BUILD_DEPS="build-essential libpq-dev libsqlite3-dev libwrap0-dev tzdata locales git curl unzip shared-mime-info" \
DEBIAN_FRONTEND="noninteractive" \
RAILS_ENV="production" \
LANG="en_US.UTF-8"
RUN useradd -m -U app \
&& su -s /bin/bash -c "mkdir -p /home/app" app
RUN apt-get update -qq && apt-get install -y $BUILD_DEPS
ENV RUBY_THREAD_MACHINE_STACK_SIZE=8388608
ENV RUBY_THREAD_VM_STACK_SIZE=8388608
# Build development gems
FROM bundle AS bundle-dev
LABEL stage=build
LABEL project=avalon
RUN bundle config set --local without 'production zoom' \
&& bundle config set --local with 'aws development test postgres' \
&& bundle install
RUN gem update --system \
&& chown -R app:staff /usr/local/bundle
# Download binaries in parallel
FROM ruby:3.2-bullseye AS download
LABEL stage=build
LABEL project=avalon
RUN curl -L https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz | tar xvz -C /usr/bin/
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN chrome_version=`dpkg-deb -f /chrome.deb Version | cut -d '.' -f 1-3`
RUN chromedriver_version=`curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chrome_version}`
RUN curl https://chromedriver.storage.googleapis.com/index.html?path=${chromedriver_version} -o /usr/local/bin/chromedriver \
&& chmod +x /usr/local/bin/chromedriver
RUN apt-get -y update && apt-get install -y ffmpeg
COPY --chown=app:app Gemfile* /home/app/
ENV BUNDLE_WITH='aws:postgres' BUNDLE_WITHOUT='development:test:zoom'
RUN bundle install --jobs $(nproc) --retry 5
RUN find /usr/local/bundle/ -name '*.gem' -or -name '*.c' -or -name '*.o' -delete
RUN rm -rf /usr/local/bundle/**/.git
# Base stage for building final images
FROM ruby:3.2-slim-bullseye AS base
LABEL stage=build
LABEL project=avalon
RUN echo "deb http://ftp.us.debian.org/debian/ bullseye main contrib non-free" > /etc/apt/sources.list.d/bullseye.list \
&& echo "deb-src http://ftp.us.debian.org/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list.d/bullseye.list \
&& cat /etc/apt/sources.list.d/bullseye.list \
&& mkdir -p /etc/apt/keyrings \
&& apt-get update && apt-get install -y --no-install-recommends curl ca-certificates gnupg2 ffmpeg \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& cat /etc/apt/sources.list.d/nodesource.list \
&& cat /etc/apt/sources.list.d/yarn.list
RUN apt-get update && \
apt-get -y dist-upgrade && \
apt-get install -y --no-install-recommends --allow-unauthenticated \
nodejs \
yarn \
lsof \
x264 \
sendmail \
git \
libxml2-dev \
libxslt-dev \
libpq-dev \
openssh-client \
zip \
dumb-init \
libsqlite3-dev \
sudo \
&& apt-get -y install mediainfo \
&& ln -s /usr/bin/lsof /usr/sbin/
RUN useradd -m -U app \
&& su -s /bin/bash -c "mkdir -p /home/app/avalon" app
WORKDIR /home/app/avalon
# Build devevelopment image
FROM base AS dev
LABEL stage=final
LABEL project=avalon
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
build-essential \
cmake
COPY --chown=app:staff --from=ruby-deps /usr/local/bundle /usr/local/bundle
COPY --chown=app:app --from=npm-deps /home/app/node_modules/ /home/app/node_modules/
COPY --chown=app:app . /home/app/
RUN mkdir /var/run/puma && chown root:app /var/run/puma && chmod 0775 /var/run/puma
USER app
WORKDIR /home/app
ENV BUNDLE_WITH='aws:postgres' BUNDLE_WITHOUT='development:test:zoom'
RUN bundle exec rake assets:precompile SECRET_KEY_BASE=$(ruby -r 'securerandom' -e 'puts SecureRandom.hex(64)')
# Build production gems
FROM bundle AS bundle-prod
LABEL stage=build
LABEL project=avalon
COPY Gemfile* .
RUN bundle config set --local without 'development test zoom' \
&& bundle config set --local with 'aws production postgres' \
&& bundle install
# Install node modules
FROM node:20-bullseye-slim AS node-modules
LABEL stage=build
LABEL project=avalon
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates
COPY package.json .
COPY yarn.lock .
RUN yarn install
# Build production assets
FROM base AS assets
LABEL stage=build
LABEL project=avalon
COPY --from=bundle-prod --chown=app:app /usr/local/bundle /usr/local/bundle
COPY --chown=app:app . .
COPY --from=node-modules --chown=app:app /node_modules ./node_modules
USER app
ENV RAILS_ENV=production
RUN SECRET_KEY_BASE=$(ruby -r 'securerandom' -e 'puts SecureRandom.hex(64)') SHAKAPACKER_ASSET_HOST='' bundle exec rake assets:precompile
RUN cp config/controlled_vocabulary.yml.example config/controlled_vocabulary.yml
# Build production image
FROM base AS prod
LABEL stage=final
LABEL project=avalon
COPY --from=assets --chown=app:app /home/app/avalon /home/app/avalon
COPY --from=bundle-prod --chown=app:app /usr/local/bundle /usr/local/bundle
RUN mkdir /var/run/puma && chown root:app /var/run/puma && chmod 0775 /var/run/puma
USER app
ENV RAILS_ENV=production
ENV PATH="/home/app/bin:${PATH}"
EXPOSE 3000
CMD bin/boot_container
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:3000/