44# Copyright (C) 2021-2023 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
55
66FROM index.docker.io/library/almalinux:9.5 AS clamav-almalinux-devcontainer
7+
8+ # Declare args again after FROM to make them available in this build stage
79ARG REMOTE_USER
810ARG REMOTE_UID
11+
12+ # Set working directory
913WORKDIR /src
1014
15+ # Copy current directory contents into the container
1116COPY . /src/
1217
18+ # Set environment variables
1319ENV CARGO_HOME=/src/build
14-
15- ENV HOME /home/${REMOTE_USER}
20+ ENV HOME=/home/${REMOTE_USER}
1621
1722# Install and enable EPEL and CRB repositories
1823RUN dnf -y install epel-release && dnf config-manager --set-enabled crb
1924
25+ # Install necessary packages
2026RUN dnf -y --allowerasing install \
21- cmake \
22- bison \
23- check \
24- curl \
25- flex \
26- gcc \
27- gcc-c++ \
28- git \
29- gdb \
30- glibc-all-langpacks \
31- make \
32- man-db \
33- net-tools \
34- psmisc \
35- pkg-config \
36- python3-pip \
37- python3-pytest \
38- sudo \
39- tcpdump \
40- valgrind \
41- wget \
42- zip \
43- bzip2-devel \
44- check-devel \
45- curl-devel \
46- json-c-devel \
47- sendmail-devel \
48- ncurses-devel \
49- pcre2-devel \
50- openssl-devel \
51- libxml2-devel \
52- zlib-devel \
53- && \
54- rm -rf /var/cache/apt/archives \
55- && \
56- # Add the user to the system and to sudoers
57- adduser --uid $REMOTE_UID $REMOTE_USER \
58- && \
59- echo "${REMOTE_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers \
60- && \
61- # Using rustup to install Rust rather than rust:1.62.1-bullseye, because there is no rust:1.62.1-bullseye image for ppc64le at this time.
62- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
63- && \
64- . $CARGO_HOME/env \
65- && \
66- rustup update \
67- && \
68- mkdir -p "./build" && cd "./build" \
69- && \
70- ls /src \
71- && \
72- cmake .. \
73- -DCARGO_HOME=$CARGO_HOME \
74- -DCMAKE_BUILD_TYPE="Release" \
75- -DCMAKE_INSTALL_PREFIX="/usr" \
76- -DCMAKE_INSTALL_LIBDIR="/usr/lib" \
77- -DAPP_CONFIG_DIRECTORY="/etc/clamav" \
78- -DDATABASE_DIRECTORY="/var/lib/clamav" \
79- -DENABLE_CLAMONACC=OFF \
80- -DENABLE_EXAMPLES=OFF \
81- -DENABLE_JSON_SHARED=ON \
82- -DENABLE_MAN_PAGES=OFF \
83- -DENABLE_MILTER=ON \
84- -DENABLE_STATIC_LIB=OFF \
85- && \
86- make DESTDIR="/clamav" -j$(($(nproc) - 1)) install \
87- && \
88- rm -r \
89- "/clamav/usr/include" \
90- "/clamav/usr/lib/pkgconfig/" \
91- && \
92- sed -e "s|^\( Example\) |\# \1 |" \
93- -e "s|.*\( LocalSocket\) .*|\1 /tmp/clamd.sock|" \
94- -e "s|.*\( TCPSocket\) .*|\1 3310|" \
95- -e "s|.*\( TCPAddr\) .*|#\1 0.0.0.0|" \
96- -e "s|.*\( User\) .*|\1 clamav|" \
97- -e "s|^\#\( LogFile\) .*|\1 /var/log/clamav/clamd.log|" \
98- -e "s|^\#\( LogTime\) .*|\1 yes|" \
99- "/clamav/etc/clamav/clamd.conf.sample" > "/clamav/etc/clamav/clamd.conf" && \
100- sed -e "s|^\( Example\) |\# \1 |" \
101- -e "s|.*\( DatabaseOwner\) .*|\1 clamav|" \
102- -e "s|^\#\( UpdateLogFile\) .*|\1 /var/log/clamav/freshclam.log|" \
103- -e "s|^\#\( NotifyClamd\) .*|\1 /etc/clamav/clamd.conf|" \
104- -e "s|^\#\( ScriptedUpdates\) .*|\1 yes|" \
105- "/clamav/etc/clamav/freshclam.conf.sample" > "/clamav/etc/clamav/freshclam.conf" && \
106- sed -e "s|^\( Example\) |\# \1 |" \
107- -e "s|.*\( MilterSocket\) .*|\1 inet:7357|" \
108- -e "s|.*\( User\) .*|\1 clamav|" \
109- -e "s|^\#\( LogFile\) .*|\1 /var/log/clamav/milter.log|" \
110- -e "s|^\#\( LogTime\) .*|\1 yes|" \
111- -e "s|.*\(\C lamdSocket\) .*|\1 unix:/tmp/clamd.sock|" \
112- "/clamav/etc/clamav/clamav-milter.conf.sample" > "/clamav/etc/clamav/clamav-milter.conf" || \
113- exit 1
114- # Currently Unit test 1 fails with:
115- # /src/unit_tests/check_clamav.c:1797:F:assorted functions:test_cli_codepage_to_utf8_jis:0: test_cli_codepage_to_utf8: Failed to convert CODEPAGE_JAPANESE_SHIFT_JIS to UTF8: ret != SUCCESS!
116- # Todo: Investigate and fix this issue
117- # \
118- # && \
119- # ctest -V --timeout 3000
27+ cmake \
28+ bison \
29+ check \
30+ curl \
31+ flex \
32+ gcc \
33+ gcc-c++ \
34+ git \
35+ gdb \
36+ glibc-all-langpacks \
37+ make \
38+ man-db \
39+ net-tools \
40+ psmisc \
41+ pkg-config \
42+ python3-pip \
43+ python3-pytest \
44+ sudo \
45+ tcpdump \
46+ valgrind \
47+ wget \
48+ zip \
49+ bzip2-devel \
50+ check-devel \
51+ curl-devel \
52+ json-c-devel \
53+ sendmail-devel \
54+ ncurses-devel \
55+ pcre2-devel \
56+ openssl-devel \
57+ libxml2-devel \
58+ zlib-devel \
59+ && rm -rf /var/cache/apt/archives
60+
61+ RUN echo "REMOTE_USER is ${REMOTE_USER} and REMOTE_UID is ${REMOTE_UID}"
62+
63+ # Create a non-root user
64+ RUN echo "Creating user ${REMOTE_USER} with UID ${REMOTE_UID}" && \
65+ adduser --uid "$REMOTE_UID" "$REMOTE_USER" && \
66+ echo "${REMOTE_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${REMOTE_USER} && chmod 0440 /etc/sudoers.d/${REMOTE_USER}
67+
68+ # Install Rust
69+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
70+ && . $CARGO_HOME/env \
71+ && rustup update
72+
73+ # Build ClamAV
74+ RUN mkdir -p ./build && cd ./build \
75+ && cmake .. \
76+ -DCARGO_HOME=$CARGO_HOME \
77+ -DCMAKE_BUILD_TYPE="Release" \
78+ -DCMAKE_INSTALL_PREFIX="/usr" \
79+ -DCMAKE_INSTALL_LIBDIR="/usr/lib" \
80+ -DAPP_CONFIG_DIRECTORY="/etc/clamav" \
81+ -DDATABASE_DIRECTORY="/var/lib/clamav" \
82+ -DENABLE_CLAMONACC=OFF \
83+ -DENABLE_EXAMPLES=OFF \
84+ -DENABLE_JSON_SHARED=ON \
85+ -DENABLE_MAN_PAGES=OFF \
86+ -DENABLE_MILTER=ON \
87+ -DENABLE_STATIC_LIB=OFF \
88+ && make DESTDIR="/clamav" -j$(($(nproc) - 1)) install \
89+ && rm -r /clamav/usr/include /clamav/usr/lib/pkgconfig/ \
90+ && sed -e "s|^\( Example\) |# \1 |" \
91+ -e "s|.*\( LocalSocket\) .*|\1 /tmp/clamd.sock|" \
92+ -e "s|.*\( TCPSocket\) .*|\1 3310|" \
93+ -e "s|.*\( TCPAddr\) .*|#\1 0.0.0.0|" \
94+ -e "s|.*\( User\) .*|\1 clamav|" \
95+ -e "s|^\#\( LogFile\) .*|\1 /var/log/clamav/clamd.log|" \
96+ -e "s|^\#\( LogTime\) .*|\1 yes|" \
97+ /clamav/etc/clamav/clamd.conf.sample > /clamav/etc/clamav/clamd.conf \
98+ && sed -e "s|^\( Example\) |# \1 |" \
99+ -e "s|.*\( DatabaseOwner\) .*|\1 clamav|" \
100+ -e "s|^\#\( UpdateLogFile\) .*|\1 /var/log/clamav/freshclam.log|" \
101+ -e "s|^\#\( NotifyClamd\) .*|\1 /etc/clamav/clamd.conf|" \
102+ -e "s|^\#\( ScriptedUpdates\) .*|\1 yes|" \
103+ /clamav/etc/clamav/freshclam.conf.sample > /clamav/etc/clamav/freshclam.conf \
104+ && sed -e "s|^\( Example\) |# \1 |" \
105+ -e "s|.*\( MilterSocket\) .*|\1 inet:7357|" \
106+ -e "s|.*\( User\) .*|\1 clamav|" \
107+ -e "s|^\#\( LogFile\) .*|\1 /var/log/clamav/milter.log|" \
108+ -e "s|^\#\( LogTime\) .*|\1 yes|" \
109+ -e "s|.*\( ClamdSocket\) .*|\1 unix:/tmp/clamd.sock|" \
110+ /clamav/etc/clamav/clamav-milter.conf.sample > /clamav/etc/clamav/clamav-milter.conf
111+ # && ctest -V --timeout 3000
112+
113+ # Switch to the non-root user
114+ USER ${REMOTE_USER}
120115
121- USER ${REMOTE_USER}
116+ # Set working directory to user's home
117+ WORKDIR ${HOME}
0 commit comments