Skip to content

Commit eda2f4d

Browse files
committed
Update almalinux devcontainer to work on multiple platforms.
1 parent 29423eb commit eda2f4d

3 files changed

Lines changed: 112 additions & 116 deletions

File tree

.devcontainer/clamav-almalinux/Dockerfile

Lines changed: 98 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4,118 +4,114 @@
44
# Copyright (C) 2021-2023 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
55

66
FROM 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
79
ARG REMOTE_USER
810
ARG REMOTE_UID
11+
12+
# Set working directory
913
WORKDIR /src
1014

15+
# Copy current directory contents into the container
1116
COPY . /src/
1217

18+
# Set environment variables
1319
ENV 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
1823
RUN dnf -y install epel-release && dnf config-manager --set-enabled crb
1924

25+
# Install necessary packages
2026
RUN 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|.*\(\ClamdSocket\) .*|\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}

.devcontainer/clamav-almalinux/devcontainer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@
33
"name": "ClamAV AlmaLinux Development Container",
44
"build": {
55
"dockerfile": "Dockerfile",
6+
// Context must be the relative path to the project root
7+
// project/.devcontainer/clamav-almalinux
68
"context": "../..",
79
"args": {
10+
"CLAMAV_TAG_OR_BRANCH": "clamav-1.4.1",
811
"REMOTE_USER": "${localEnv:USER}",
9-
// This requires UID to be exported in your shell profile. See https://aka.ms/vscode-remote/containers/non-root-user.
12+
// UID must be exported, see README.md
1013
"REMOTE_UID": "${localEnv:UID}"
1114
},
1215
"options": [
1316
"--ssh=default"
14-
]
17+
],
18+
// Use VSCode's built-in SSH agent forwarding
19+
"sshAgentForwarding": true,
20+
"remoteUser": "${localEnv:USER}"
1521
},
16-
"postCreateCommand": "echo 'Welcome to your ClamAV AlmaLinux development container!'",
22+
"postCreateCommand": "echo 'Welcome to your ClamAV development container!'",
1723
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
1824
"mounts": [
19-
"source=${localEnv:HOME}/data/cvd,target=/var/lib/clamav,type=bind,consistency=cached"
25+
// Directory must exist. Edit if cvd files are in another location
26+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/data/cvd,target=/var/lib/clamav,type=bind,consistency=cached"
2027
],
2128
"runArgs": [
2229
"--cap-add=SYS_PTRACE",
2330
"--security-opt",
2431
"seccomp=unconfined",
25-
// Set the SSH_AUTH_SOCK environment variable
26-
"-e",
27-
"SSH_AUTH_SOCK=/ssh-agent.sock",
28-
// Mount the SSH agent socket
29-
"--mount=type=bind,src=${localEnv:SSH_AUTH_SOCK},target=/ssh-agent.sock",
3032
// Add host.docker.internal to /etc/hosts to enable container to reach host machine so that it can reach test Kafka broker running in docker on host machine
3133
"--add-host=host.docker.internal:host-gateway"
3234
],
@@ -38,9 +40,7 @@
3840
"eamodio.gitlens",
3941
"vadimcn.vscode-lldb",
4042
"webfreak.debug",
41-
"ms-vscode-remote.remote-containers",
42-
"ms-vscode.cpptools-extension-pack",
43-
"ms-vscode.cpptools"
43+
"ms-vscode-remote.remote-containers"
4444
],
4545
"settings": {
4646
"terminal.integrated.shell.linux": "/bin/bash"

.devcontainer/clamav-debian/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"build": {
55
"dockerfile": "Dockerfile",
66
// Context must be the relative path to the project root
7-
// project/.devcontainer/mac
7+
// project/.devcontainer/clamav-debian
88
"context": "../..",
99
// "noCache": true,
1010
"args": {
@@ -48,4 +48,4 @@
4848
}
4949
}
5050
}
51-
}
51+
}

0 commit comments

Comments
 (0)