-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.main
262 lines (217 loc) · 7.85 KB
/
Dockerfile.main
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
ARG TARGETPLATFORM=${TARGETPLATFORM}
ARG BUILDPLATFORM=${BUILDPLATFORM}
# Ruby image to use for base image.
ARG RUBY_VERSION="3.3.5"
# # Node version to use in base image.
ARG NODE_MAJOR="22"
# Debian image to use for base image.
ARG DEBIAN_VERSION="bookworm"
FROM --platform=${TARGETPLATFORM} docker.io/node:${NODE_MAJOR}-${DEBIAN_VERSION}-slim AS node
FROM --platform=${TARGETPLATFORM} docker.io/ruby:${RUBY_VERSION}-slim-${DEBIAN_VERSION} AS ruby
ARG RAILS_SERVE_STATIC_FILES="true"
ARG RUBY_YJIT_ENABLE="1"
ARG UID="991"
ARG GID="991"
# Set the frontend to noninteractive to prevent tzdata from hanging during install
# and set the version of Ruby to install.
ENV DEBIAN_FRONTEND=noninteractive
ENV NODE_MAJOR=${NODE_MAJOR}
ENV RAILS_SERVE_STATIC_FILES=${RAILS_SERVE_STATIC_FILES}
ENV RUBY_YJIT_ENABLE=${RUBY_YJIT_ENABLE}
ENV BIND="0.0.0.0"
ENV NODE_ENV="production"
ENV RAILS_ENV="production"
ENV PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin"
ENV MALLOC_CONF="narenas:2,background_thread:true,thp:never,dirty_decay_ms:1000,muzzy_decay_ms:0"
RUN groupadd -g ${GID} mastodon && \
useradd -l -u "${UID}" -g "${GID}" -m -d /opt/mastodon mastodon && \
ln -s /opt/mastodon /mastodon
WORKDIR /opt/mastodon
# Set timezone to EST/EDT, update installed packages,
# setup NodeSource for NodeJS, install all required packages,
# and add the 'mastodon' user.
RUN echo "Etc/UTC" > /etc/localtime && \
apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y curl gnupg apt-transport-https lsb-release ca-certificates git && \
mkdir -p /etc/apt/keyrings && \
apt-get update && \
apt-get install -y --no-install-recommends \
curl \
file \
libjemalloc2 \
patchelf \
procps \
tini \
tzdata \
wget \
autoconf \
automake \
build-essential \
cmake \
git \
libgdbm-dev \
libglib2.0-dev \
libgmp-dev \
libicu-dev \
libidn-dev \
libpq-dev \
libssl-dev \
libtool \
meson \
nasm \
pkg-config \
shared-mime-info \
xz-utils \
# libvips components
libcgif-dev \
libexif-dev \
libexpat1-dev \
libgirepository1.0-dev \
libheif-dev \
libimagequant-dev \
libjpeg62-turbo-dev \
liblcms2-dev \
liborc-dev \
libspng-dev \
libtiff-dev \
libwebp-dev \
# ffmpeg components
libdav1d-dev \
liblzma-dev \
libmp3lame-dev \
libopus-dev \
libsnappy-dev \
libvorbis-dev \
libvpx-dev \
libx264-dev \
libx265-dev && \
patchelf --add-needed libjemalloc.so.2 /usr/local/bin/ruby && \
apt-get purge -y patchelf && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
FROM --platform=${TARGETPLATFORM} ruby AS build
COPY --from=node /usr/local/bin /usr/local/bin
COPY --from=node /usr/local/lib /usr/local/lib
WORKDIR /opt/mastodon
# Apply custom patches
RUN rm .profile && \
git config --global --add safe.directory /opt/mastodon && \
git config --global init.defaultBranch main && \
git init && \
git remote add origin https://github.com/glitch-soc/mastodon.git && \
git pull origin main
# Apply a fix for iOS padding when using Mastodon as a PWA.
COPY ./patches/mastodon/fix-ios-pwa.patch /tmp/fix-ios-pwa.patch
RUN git config user.name "ContainerBuild" ; \
git config user.email "build@localhost" ; \
git am /tmp/fix-ios-pwa.patch; \
rm /tmp/fix-ios-pwa.patch
# Add Tangerine UI theme
RUN git clone https://github.com/nileane/TangerineUI-for-Mastodon.git /tmp/tangerine-ui && \
cp -r /tmp/tangerine-ui/mastodon/app/javascript/styles/* /opt/mastodon/app/javascript/styles && \
cp -r /tmp/tangerine-ui/mastodon/app/javascript/skins/vanilla/* /opt/mastodon/app/javascript/skins/vanilla && \
rm -rf /tmp/tangerine-ui
RUN rm /usr/local/bin/yarn* ; \
corepack enable && \
corepack prepare --activate
# Build libvips
FROM --platform=${TARGETPLATFORM} build AS libvips-build
ARG VIPS_VERSION=8.16.0
ARG VIPS_URL=https://github.com/libvips/libvips/releases/download
WORKDIR /usr/local/libvips/src
ADD ${VIPS_URL}/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.xz /usr/local/libvips/src/
RUN tar xf vips-${VIPS_VERSION}.tar.xz
WORKDIR /usr/local/libvips/src/vips-${VIPS_VERSION}
RUN meson setup build \
--prefix /usr/local/libvips \
--libdir=lib \
-Ddeprecated=false \
-Dintrospection=disabled \
-Dmodules=disabled \
-Dexamples=false; \
cd build; \
ninja; \
ninja install
# Build ffmpeg
FROM --platform=${TARGETPLATFORM} build AS ffmpeg-build
ARG FFMPEG_VERSION=7.1
ARG FFMPEG_URL=https://ffmpeg.org/releases
WORKDIR /usr/local/ffmpeg/src
ADD ${FFMPEG_URL}/ffmpeg-${FFMPEG_VERSION}.tar.xz /usr/local/ffmpeg/src/
RUN tar xf ffmpeg-${FFMPEG_VERSION}.tar.xz
WORKDIR /usr/local/ffmpeg/src/ffmpeg-${FFMPEG_VERSION}
RUN ./configure \
--prefix=/usr/local/ffmpeg \
--toolchain=hardened \
--disable-debug \
--disable-devices \
--disable-doc \
--disable-ffplay \
--disable-network \
--disable-static \
--enable-ffmpeg \
--enable-ffprobe \
--enable-gpl \
--enable-libdav1d \
--enable-libmp3lame \
--enable-libopus \
--enable-libsnappy \
--enable-libvorbis \
--enable-libvpx \
--enable-libwebp \
--enable-libx264 \
--enable-libx265 \
--enable-shared \
--enable-version3; \
make -j$(nproc); \
make install
FROM --platform=${TARGETPLATFORM} build AS bundler
WORKDIR /opt/mastodon
RUN bundle config set --global frozen "true" && \
bundle config set --global cache_all "false" && \
bundle config set --local without "development test" && \
bundle config set silence_root_warning "true" && \
bundle install -j"$(nproc)"
FROM --platform=${TARGETPLATFORM} build AS yarn
WORKDIR /opt/mastodon
RUN yarn workspaces focus --production @mastodon/mastodon
FROM --platform=${TARGETPLATFORM} build AS precompiler
COPY --from=yarn /opt/mastodon /opt/mastodon/
COPY --from=bundler /opt/mastodon /opt/mastodon/
COPY --from=bundler /usr/local/bundle/ /usr/local/bundle/
COPY --from=libvips-build /usr/local/libvips/bin /usr/local/bin
COPY --from=libvips-build /usr/local/libvips/lib /usr/local/lib
RUN ldconfig; \
SECRET_KEY_BASE_DUMMY=1 \
bundle exec rails assets:precompile && \
rm -rf /opt/mastodon/tmp
FROM --platform=${TARGETPLATFORM} ruby AS mastodon
WORKDIR /opt/mastodon
RUN rm .profile && \
git config --global --add safe.directory /opt/mastodon && \
git config --global init.defaultBranch main && \
git init && \
git remote add origin https://github.com/glitch-soc/mastodon.git && \
git pull origin main && \
rm -rf /opt/mastodon/.git && \
mkdir -p /opt/mastodon/public/system && \
chown mastodon:mastodon /opt/mastodon/public/system && \
mkdir -p /opt/mastodon/tmp && \
chown -R mastodon:mastodon /opt/mastodon/tmp
WORKDIR /opt/mastodon
COPY --from=build /opt/mastodon/app/javascript/styles /opt/mastodon/app/javascript/styles
COPY --from=build /opt/mastodon/app/javascript/skins/vanilla /opt/mastodon/app/javascript/skins/vanilla
COPY --from=precompiler /opt/mastodon/public/packs /opt/mastodon/public/packs
COPY --from=precompiler /opt/mastodon/public/assets /opt/mastodon/public/assets
COPY --from=bundler /usr/local/bundle/ /usr/local/bundle/
COPY --from=libvips-build /usr/local/libvips/bin /usr/local/bin
COPY --from=libvips-build /usr/local/libvips/lib /usr/local/lib
COPY --from=ffmpeg-build /usr/local/ffmpeg/bin /usr/local/bin
COPY --from=ffmpeg-build /usr/local/ffmpeg/lib /usr/local/lib
RUN ldconfig; \
bundle exec bootsnap precompile --gemfile app/ lib/
USER mastodon
EXPOSE 3000
ENTRYPOINT ["/usr/bin/tini", "--"]