-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
236 lines (213 loc) · 6.89 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
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
FROM phusion/baseimage:focal-1.2.0 AS clamav-builder
RUN set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get -qq update; \
apt-get -qqy --no-install-recommends install \
build-essential \
cmake \
git \
check \
libcurl4-openssl-dev \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libxml2-dev \
libpcre2-dev \
libjson-c-dev \
libncurses5-dev \
valgrind \
pkg-config \
libmilter-dev \
gcc \
make \
python3 \
python3-pip \
python3-pytest \
curl \
; \
rm -rf /var/lib/apt/lists/*; \
\
# Install Rust and Cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; \
. $HOME/.cargo/env; \
\
curl -L -o clamav.tar.gz https://www.clamav.net/downloads/production/clamav-1.3.1.tar.gz; \
tar xzf clamav.tar.gz; \
cd clamav-1.3.1; \
mkdir build && cd build; \
cmake .. \
-D CMAKE_BUILD_TYPE="Release" \
-D CMAKE_INSTALL_PREFIX=/usr \
-D APP_CONFIG_DIRECTORY=/etc/clamav \
-D DATABASE_DIRECTORY=/var/lib/clamav \
-D ENABLE_JSON_SHARED=ON \
-D CMAKE_INSTALL_LIBDIR=/usr/lib \
-D ENABLE_CLAMONACC=OFF \
-D ENABLE_EXAMPLES=OFF \
-D ENABLE_MAN_PAGES=OFF \
-D ENABLE_MILTER=ON \
-D ENABLE_STATIC_LIB=OFF \
; \
make DESTDIR="/clamav" --quiet -j$(($(nproc) - 1)) install; \
cd ../../ && rm -r clamav.tar.gz clamav-1.3.1; \
rm -rf "/clamav/usr/include" \
"/clamav/usr/lib/pkgconfig/" \
"/clamav/usr/share/doc" ; \
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -qqy --auto-remove -o APT::AutoRemove::RecommendsImportant=false;
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM phusion/baseimage:focal-1.2.0 AS ruby-builder
##
# based on Dockerfile for ruby:2.7.7
# skip installing gem documentation
RUN set -eux; \
mkdir -p /usr/local/etc; \
{ \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
ENV LANG C.UTF-8
ENV RUBY_MAJOR 3.0
ENV RUBY_VERSION 3.0.7
ENV RUBY_DOWNLOAD_SHA256 1748338373c4fad80129921080d904aca326e41bd9589b498aa5ee09fd575bab
# some of ruby's build scripts are written in ruby
# we purge system ruby later to make sure our final image uses what we just built
RUN set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get -qq update; \
apt-get install -qqy --no-install-recommends \
bison \
dpkg-dev \
libgdbm-dev \
ruby \
autoconf \
gcc \
libssl-dev \
zlib1g-dev \
; \
rm -rf /var/lib/apt/lists/*; \
\
curl -o ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz"; \
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \
\
mkdir -p /usr/src/ruby; \
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \
rm ruby.tar.xz; \
\
cd /usr/src/ruby; \
\
# hack in "ENABLE_PATH_CHECK" disabling to suppress:
# warning: Insecure world writable dir
{ \
echo '#define ENABLE_PATH_CHECK 0'; \
echo; \
cat file.c; \
} > file.c.new; \
mv file.c.new file.c; \
\
autoconf; \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
./configure \
--silent \
--build="$gnuArch" \
--disable-install-doc \
--enable-shared \
; \
make --quiet -j "$(nproc)"; \
make --quiet install; \
\
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark > /dev/null; \
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| sort -u \
| grep -vE '^/usr/local/lib/' \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
; \
apt-get purge -qqy --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
cd /; \
rm -r /usr/src/ruby; \
# verify we have no "ruby" packages installed
if dpkg -l | grep -i ruby; then exit 1; fi; \
[ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \
# rough smoke test
ruby --version; \
gem --version; \
bundle --version
# don't create ".bundle" in all our apps
ENV GEM_HOME /usr/local/bundle
ENV BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $GEM_HOME/bin:$PATH
# adjust permissions of a few directories for running "gem install" as an arbitrary user
RUN mkdir -p "$GEM_HOME" && chmod 777 "$GEM_HOME"
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM phusion/baseimage:focal-1.2.0
COPY --from=ruby-builder "/usr" "/usr"
COPY --from=clamav-builder "/clamav" "/"
COPY config/freshclam.conf /etc/clamav/freshclam.conf
COPY config/clamd.conf /etc/clamav/clamd.conf
RUN groupadd clamav
RUN useradd -g clamav -s /bin/false -c "Clam Antivirus" clamav
RUN mkdir -p /var/lib/clamav && chown -R clamav:clamav /var/lib/clamav
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN freshclam -v && freshclam --version > /usr/src/app/CLAM_VERSION
##
# refresh virus definitions each 1 hour. ClamAV recommends not update in times multiple of 10
RUN echo "15 * * * * root /usr/bin/freshclam --quiet >/dev/null 2>&1" > /etc/cron.d/freshclam-cron && \
echo "30 * * * * root /usr/bin/freshclam --version > /usr/src/app/CLAM_VERSION" >> /etc/cron.d/freshclam-version-cron && \
chmod 644 /etc/cron.d/freshclam-cron && \
service cron restart
COPY Gemfile /usr/src/app/
COPY Gemfile.lock /usr/src/app/
RUN gem install bundler:2.2.33
RUN set -eux; \
\
apt-get -qq update; \
apt-get -qqy --no-install-recommends install \
# for postgresql
libpq-dev \
postgresql-client \
# for ruby-filemagic
libmagic-dev \
# for bundling vigilion gems
make \
gcc \
libpcre2-dev \
; \
rm -rf /var/lib/apt/lists/*; \
\
bundle install --jobs 4 --retry 3 ; \
\
apt-mark auto make gcc gcc-9-base libpcre2-dev > /dev/null; \
apt-get purge -qqy --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
##
# clean:
# we are doing the following so that we:
# Removing gcc-9-base:amd64 (9.4.0-1ubuntu1~20.04.1)
apt-get -qqy update; \
apt-get -qqy autoremove; \
apt-get clean; \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# link shared libraries
RUN ldconfig
COPY . /usr/src/app
RUN mkdir /etc/service/puma
COPY docker/puma.sh /etc/service/puma/run
RUN chmod +x /etc/service/puma/run
RUN mkdir /etc/service/sidekiq
COPY docker/sidekiq.sh /etc/service/sidekiq/run
RUN chmod +x /etc/service/sidekiq/run
RUN mkdir /etc/service/av-clamd
COPY docker/av-clamd.sh /etc/service/av-clamd/run
RUN chmod +x /etc/service/av-clamd/run
CMD ["/sbin/my_init"]
EXPOSE 3000