Skip to content

Commit f4298b8

Browse files
jhumlickjhumlick
jhumlick
authored andcommitted
clamd: Add devcontainers to project
ClamAV supports multiple platforms and sometimes requires the debugging of platform-specific bugs. This commit adds one devcontainer for debian and another for AlmaLinux so that the codebase can be reopened inside of a devcontainer for debugging/testing purposes. Jira: CLAM-2740
1 parent 1f214b2 commit f4298b8

File tree

4 files changed

+321
-0
lines changed

4 files changed

+321
-0
lines changed
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Copyright (C) 2020 Olliver Schinagl <[email protected]>
4+
# Copyright (C) 2021-2023 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5+
6+
FROM index.docker.io/library/almalinux:9.5 AS clamav-almalinux-devcontainer
7+
ARG REMOTE_USER
8+
ARG REMOTE_UID
9+
WORKDIR /src
10+
11+
COPY . /src/
12+
13+
ENV CARGO_HOME=/src/build
14+
15+
ENV HOME /home/${REMOTE_USER}
16+
17+
# Install and enable EPEL and CRB repositories
18+
RUN dnf -y install epel-release && dnf config-manager --set-enabled crb
19+
20+
RUN dnf -y --allowerasing install \
21+
cmake \
22+
bison \
23+
check \
24+
curl \
25+
flex \
26+
gcc \
27+
gcc-c++ \
28+
git \
29+
glibc-all-langpacks \
30+
make \
31+
man-db \
32+
net-tools \
33+
psmisc \
34+
pkg-config \
35+
python3-pip \
36+
python3-pytest \
37+
sudo \
38+
tcpdump \
39+
valgrind \
40+
wget \
41+
zip \
42+
bzip2-devel \
43+
check-devel \
44+
curl-devel \
45+
json-c-devel \
46+
sendmail-devel \
47+
ncurses-devel \
48+
pcre2-devel \
49+
openssl-devel \
50+
libxml2-devel \
51+
zlib-devel \
52+
&& \
53+
rm -rf /var/cache/apt/archives \
54+
&& \
55+
# Add the user to the system and to sudoers
56+
adduser --uid $REMOTE_UID $REMOTE_USER \
57+
&& \
58+
echo "${REMOTE_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers \
59+
&& \
60+
# 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.
61+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
62+
&& \
63+
. $CARGO_HOME/env \
64+
&& \
65+
rustup update \
66+
&& \
67+
mkdir -p "./build" && cd "./build" \
68+
&& \
69+
ls /src \
70+
&& \
71+
cmake .. \
72+
-DCARGO_HOME=$CARGO_HOME \
73+
-DCMAKE_BUILD_TYPE="Release" \
74+
-DCMAKE_INSTALL_PREFIX="/usr" \
75+
-DCMAKE_INSTALL_LIBDIR="/usr/lib" \
76+
-DAPP_CONFIG_DIRECTORY="/etc/clamav" \
77+
-DDATABASE_DIRECTORY="/var/lib/clamav" \
78+
-DENABLE_CLAMONACC=OFF \
79+
-DENABLE_EXAMPLES=OFF \
80+
-DENABLE_JSON_SHARED=ON \
81+
-DENABLE_MAN_PAGES=OFF \
82+
-DENABLE_MILTER=ON \
83+
-DENABLE_STATIC_LIB=OFF \
84+
&& \
85+
make DESTDIR="/clamav" -j$(($(nproc) - 1)) install \
86+
&& \
87+
rm -r \
88+
"/clamav/usr/include" \
89+
"/clamav/usr/lib/pkgconfig/" \
90+
&& \
91+
sed -e "s|^\(Example\)|\# \1|" \
92+
-e "s|.*\(LocalSocket\) .*|\1 /tmp/clamd.sock|" \
93+
-e "s|.*\(TCPSocket\) .*|\1 3310|" \
94+
-e "s|.*\(TCPAddr\) .*|#\1 0.0.0.0|" \
95+
-e "s|.*\(User\) .*|\1 clamav|" \
96+
-e "s|^\#\(LogFile\) .*|\1 /var/log/clamav/clamd.log|" \
97+
-e "s|^\#\(LogTime\).*|\1 yes|" \
98+
"/clamav/etc/clamav/clamd.conf.sample" > "/clamav/etc/clamav/clamd.conf" && \
99+
sed -e "s|^\(Example\)|\# \1|" \
100+
-e "s|.*\(DatabaseOwner\) .*|\1 clamav|" \
101+
-e "s|^\#\(UpdateLogFile\) .*|\1 /var/log/clamav/freshclam.log|" \
102+
-e "s|^\#\(NotifyClamd\).*|\1 /etc/clamav/clamd.conf|" \
103+
-e "s|^\#\(ScriptedUpdates\).*|\1 yes|" \
104+
"/clamav/etc/clamav/freshclam.conf.sample" > "/clamav/etc/clamav/freshclam.conf" && \
105+
sed -e "s|^\(Example\)|\# \1|" \
106+
-e "s|.*\(MilterSocket\) .*|\1 inet:7357|" \
107+
-e "s|.*\(User\) .*|\1 clamav|" \
108+
-e "s|^\#\(LogFile\) .*|\1 /var/log/clamav/milter.log|" \
109+
-e "s|^\#\(LogTime\).*|\1 yes|" \
110+
-e "s|.*\(\ClamdSocket\) .*|\1 unix:/tmp/clamd.sock|" \
111+
"/clamav/etc/clamav/clamav-milter.conf.sample" > "/clamav/etc/clamav/clamav-milter.conf" || \
112+
exit 1
113+
# Currently Unit test 1 fails with:
114+
# /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!
115+
# Todo: Investigate and fix this issue
116+
# \
117+
# && \
118+
# ctest -V --timeout 3000
119+
120+
USER ${REMOTE_USER}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//devcontainer.json
2+
{
3+
"name": "ClamAV AlmaLinux Development Container",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"context": "../..",
7+
"args": {
8+
"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.
10+
"REMOTE_UID": "${localEnv:UID}"
11+
},
12+
"options": [
13+
"--ssh=default"
14+
]
15+
},
16+
"postCreateCommand": "echo 'Welcome to your ClamAV AlmaLinux development container!'",
17+
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
18+
"mounts": [
19+
"source=${localEnv:HOME}/data/cvd,target=/var/lib/clamav,type=bind,consistency=cached"
20+
],
21+
"runArgs": [
22+
"--cap-add=SYS_PTRACE",
23+
"--security-opt",
24+
"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",
30+
// 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
31+
"--add-host=host.docker.internal:host-gateway"
32+
],
33+
"customizations": {
34+
"vscode": {
35+
"extensions": [
36+
"rust-lang.rust-analyzer",
37+
"ms-azuretools.vscode-docker",
38+
"eamodio.gitlens",
39+
"vadimcn.vscode-lldb",
40+
"webfreak.debug",
41+
"ms-vscode-remote.remote-containers"
42+
],
43+
"settings": {
44+
"terminal.integrated.shell.linux": "/bin/bash"
45+
}
46+
}
47+
}
48+
}
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Copyright (C) 2020 Olliver Schinagl <[email protected]>
4+
# Copyright (C) 2021-2023 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5+
6+
FROM index.docker.io/library/debian:12-slim AS clamav-debian-devcontainer
7+
ARG REMOTE_USER
8+
ARG REMOTE_UID
9+
WORKDIR /src
10+
11+
COPY . /src/
12+
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
ENV CARGO_HOME=/src/build
15+
16+
ENV HOME /home/${REMOTE_USER}
17+
18+
RUN apt update && apt install -y \
19+
cmake \
20+
bison \
21+
flex \
22+
gcc \
23+
git \
24+
make \
25+
man-db \
26+
net-tools \
27+
pkg-config \
28+
python3 \
29+
python3-pip \
30+
python3-pytest \
31+
check \
32+
libbz2-dev \
33+
libcurl4-openssl-dev \
34+
libjson-c-dev \
35+
libmilter-dev \
36+
libncurses-dev \
37+
libpcre2-dev \
38+
libssl-dev \
39+
libxml2-dev \
40+
sudo \
41+
zlib1g-dev \
42+
curl \
43+
&& \
44+
rm -rf /var/cache/apt/archives \
45+
&& \
46+
# Add the user to the system and to sudoers
47+
adduser --disabled-password --uid $REMOTE_UID $REMOTE_USER \
48+
&& \
49+
echo "${REMOTE_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers \
50+
&& \
51+
# 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.
52+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
53+
&& \
54+
. $CARGO_HOME/env \
55+
&& \
56+
rustup update \
57+
&& \
58+
mkdir -p "./build" && cd "./build" \
59+
&& \
60+
cmake .. \
61+
-DCARGO_HOME=$CARGO_HOME \
62+
-DCMAKE_BUILD_TYPE="Release" \
63+
-DCMAKE_INSTALL_PREFIX="/usr" \
64+
-DCMAKE_INSTALL_LIBDIR="/usr/lib" \
65+
-DAPP_CONFIG_DIRECTORY="/etc/clamav" \
66+
-DDATABASE_DIRECTORY="/var/lib/clamav" \
67+
-DENABLE_CLAMONACC=OFF \
68+
-DENABLE_EXAMPLES=OFF \
69+
-DENABLE_JSON_SHARED=ON \
70+
-DENABLE_MAN_PAGES=OFF \
71+
-DENABLE_MILTER=ON \
72+
-DENABLE_STATIC_LIB=OFF \
73+
&& \
74+
make DESTDIR="/clamav" -j$(($(nproc) - 1)) install \
75+
&& \
76+
rm -r \
77+
"/clamav/usr/include" \
78+
"/clamav/usr/lib/pkgconfig/" \
79+
&& \
80+
sed -e "s|^\(Example\)|\# \1|" \
81+
-e "s|.*\(LocalSocket\) .*|\1 /tmp/clamd.sock|" \
82+
-e "s|.*\(TCPSocket\) .*|\1 3310|" \
83+
-e "s|.*\(TCPAddr\) .*|#\1 0.0.0.0|" \
84+
-e "s|.*\(User\) .*|\1 clamav|" \
85+
-e "s|^\#\(LogFile\) .*|\1 /var/log/clamav/clamd.log|" \
86+
-e "s|^\#\(LogTime\).*|\1 yes|" \
87+
"/clamav/etc/clamav/clamd.conf.sample" > "/clamav/etc/clamav/clamd.conf" && \
88+
sed -e "s|^\(Example\)|\# \1|" \
89+
-e "s|.*\(DatabaseOwner\) .*|\1 clamav|" \
90+
-e "s|^\#\(UpdateLogFile\) .*|\1 /var/log/clamav/freshclam.log|" \
91+
-e "s|^\#\(NotifyClamd\).*|\1 /etc/clamav/clamd.conf|" \
92+
-e "s|^\#\(ScriptedUpdates\).*|\1 yes|" \
93+
"/clamav/etc/clamav/freshclam.conf.sample" > "/clamav/etc/clamav/freshclam.conf" && \
94+
sed -e "s|^\(Example\)|\# \1|" \
95+
-e "s|.*\(MilterSocket\) .*|\1 inet:7357|" \
96+
-e "s|.*\(User\) .*|\1 clamav|" \
97+
-e "s|^\#\(LogFile\) .*|\1 /var/log/clamav/milter.log|" \
98+
-e "s|^\#\(LogTime\).*|\1 yes|" \
99+
-e "s|.*\(\ClamdSocket\) .*|\1 unix:/tmp/clamd.sock|" \
100+
"/clamav/etc/clamav/clamav-milter.conf.sample" > "/clamav/etc/clamav/clamav-milter.conf" || \
101+
exit 1 \
102+
&& \
103+
ctest -V --timeout 3000
104+
105+
USER ${REMOTE_USER}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//devcontainer.json
2+
{
3+
"name": "ClamAV Debian Development Container",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"context": "../..",
7+
"args": {
8+
"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.
10+
"REMOTE_UID": "${localEnv:UID}"
11+
},
12+
"options": [
13+
"--ssh=default"
14+
]
15+
},
16+
"postCreateCommand": "echo 'Welcome to your ClamAV Debian development container!'",
17+
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
18+
"mounts": [
19+
"source=${localEnv:HOME}/data/cvd,target=/var/lib/clamav,type=bind,consistency=cached"
20+
],
21+
"runArgs": [
22+
"--cap-add=SYS_PTRACE",
23+
"--security-opt",
24+
"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",
30+
// 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
31+
"--add-host=host.docker.internal:host-gateway"
32+
],
33+
"customizations": {
34+
"vscode": {
35+
"extensions": [
36+
"rust-lang.rust-analyzer",
37+
"ms-azuretools.vscode-docker",
38+
"eamodio.gitlens",
39+
"vadimcn.vscode-lldb",
40+
"webfreak.debug",
41+
"ms-vscode-remote.remote-containers"
42+
],
43+
"settings": {
44+
"terminal.integrated.shell.linux": "/bin/bash"
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)