]> cat aescling's git repositories - mastodon.git/blob - Dockerfile
Bump css-loader from 5.0.2 to 5.1.0 (#15802)
[mastodon.git] / Dockerfile
1 FROM ubuntu:20.04 as build-dep
2
3 # Use bash for the shell
4 SHELL ["/usr/bin/bash", "-c"]
5
6 # Install Node v12 (LTS)
7 ENV NODE_VER="12.20.1"
8 RUN ARCH= && \
9 dpkgArch="$(dpkg --print-architecture)" && \
10 case "${dpkgArch##*-}" in \
11 amd64) ARCH='x64';; \
12 ppc64el) ARCH='ppc64le';; \
13 s390x) ARCH='s390x';; \
14 arm64) ARCH='arm64';; \
15 armhf) ARCH='armv7l';; \
16 i386) ARCH='x86';; \
17 *) echo "unsupported architecture"; exit 1 ;; \
18 esac && \
19 echo "Etc/UTC" > /etc/localtime && \
20 apt update && \
21 apt -y install wget python && \
22 cd ~ && \
23 wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
24 tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
25 rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
26 mv node-v$NODE_VER-linux-$ARCH /opt/node
27
28 # Install jemalloc
29 ENV JE_VER="5.2.1"
30 RUN apt update && \
31 apt -y install make autoconf gcc g++ && \
32 cd ~ && \
33 wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
34 tar xf $JE_VER.tar.gz && \
35 cd jemalloc-$JE_VER && \
36 ./autogen.sh && \
37 ./configure --prefix=/opt/jemalloc && \
38 make -j$(nproc) > /dev/null && \
39 make install_bin install_include install_lib && \
40 cd .. && rm -rf jemalloc-$JE_VER $JE_VER.tar.gz
41
42 # Install Ruby
43 ENV RUBY_VER="2.7.2"
44 ENV CPPFLAGS="-I/opt/jemalloc/include"
45 ENV LDFLAGS="-L/opt/jemalloc/lib/"
46 RUN apt update && \
47 apt -y install build-essential \
48 bison libyaml-dev libgdbm-dev libreadline-dev \
49 libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
50 cd ~ && \
51 wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
52 tar xf ruby-$RUBY_VER.tar.gz && \
53 cd ruby-$RUBY_VER && \
54 ./configure --prefix=/opt/ruby \
55 --with-jemalloc \
56 --with-shared \
57 --disable-install-doc && \
58 ln -s /opt/jemalloc/lib/* /usr/lib/ && \
59 make -j$(nproc) > /dev/null && \
60 make install && \
61 cd .. && rm -rf ruby-$RUBY_VER.tar.gz ruby-$RUBY_VER
62
63 ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
64
65 RUN npm install -g yarn && \
66 gem install bundler && \
67 apt update && \
68 apt -y install git libicu-dev libidn11-dev \
69 libpq-dev libprotobuf-dev protobuf-compiler
70
71 COPY Gemfile* package.json yarn.lock /opt/mastodon/
72
73 RUN cd /opt/mastodon && \
74 bundle config set deployment 'true' && \
75 bundle config set without 'development test' && \
76 bundle install -j$(nproc) && \
77 yarn install --pure-lockfile
78
79 FROM ubuntu:20.04
80
81 # Copy over all the langs needed for runtime
82 COPY --from=build-dep /opt/node /opt/node
83 COPY --from=build-dep /opt/ruby /opt/ruby
84 COPY --from=build-dep /opt/jemalloc /opt/jemalloc
85
86 # Add more PATHs to the PATH
87 ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
88
89 # Create the mastodon user
90 ARG UID=991
91 ARG GID=991
92 RUN apt update && \
93 echo "Etc/UTC" > /etc/localtime && \
94 ln -s /opt/jemalloc/lib/* /usr/lib/ && \
95 apt install -y whois wget && \
96 addgroup --gid $GID mastodon && \
97 useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
98 echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd
99
100 # Install mastodon runtime deps
101 RUN apt -y --no-install-recommends install \
102 libssl1.1 libpq5 imagemagick ffmpeg \
103 libicu66 libprotobuf17 libidn11 libyaml-0-2 \
104 file ca-certificates tzdata libreadline8 && \
105 apt -y install gcc && \
106 ln -s /opt/mastodon /mastodon && \
107 gem install bundler && \
108 rm -rf /var/cache && \
109 rm -rf /var/lib/apt/lists/*
110
111 # Add tini
112 ENV TINI_VERSION="0.19.0"
113 RUN dpkgArch="$(dpkg --print-architecture)" && \
114 ARCH=$dpkgArch && \
115 wget https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$ARCH \
116 https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$ARCH.sha256sum && \
117 cat tini-$ARCH.sha256sum | sha256sum -c - && \
118 mv tini-$ARCH /tini && rm tini-$ARCH.sha256sum && \
119 chmod +x /tini
120
121 # Copy over mastodon source, and dependencies from building, and set permissions
122 COPY --chown=mastodon:mastodon . /opt/mastodon
123 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
124
125 # Run mastodon services in prod mode
126 ENV RAILS_ENV="production"
127 ENV NODE_ENV="production"
128
129 # Tell rails to serve static files
130 ENV RAILS_SERVE_STATIC_FILES="true"
131 ENV BIND="0.0.0.0"
132
133 # Set the run user
134 USER mastodon
135
136 # Precompile assets
137 RUN cd ~ && \
138 OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
139 yarn cache clean
140
141 # Set the work dir and the container entry point
142 WORKDIR /opt/mastodon
143 ENTRYPOINT ["/tini", "--"]
144 EXPOSE 3000 4000
This page took 0.08917 seconds and 5 git commands to generate.