Skip to content

Commit

Permalink
Add Dockerfile and build instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
ismvru authored May 26, 2023
1 parent ab30b5f commit ead9cd2
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__pycache__
.mypy_cache
.pytest_cache
.vscode
cvdupdate.egg-info
/build
/dist
/tests
.github
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3-slim
RUN apt-get -y update \
&& apt-get -y --no-install-recommends install cron gosu \
&& rm -rf /var/lib/apt/lists/*
COPY . /dist
RUN pip install --no-cache-dir /dist
ENTRYPOINT [ "/dist/scripts/docker-entrypoint.sh" ]
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,47 @@ You can test it by running `freshclam` or `freshclam.exe` locally, where you've
DatabaseMirror http://localhost:8000
```

### Use docker

Build docker image

```bash
docker build . --tag cvdupdate:latest
```

Run image, that will automaticly update databases in folder `/srv/cvdupdate` and write logs to `/var/log/cvdupdate`

```bash
docker run -d \
-v /srv/cvdupdate:/cvdupdate/database \
-v /var/log/cvdupdate:/cvdupdate/logs \
cvdupdate:latest
```

Run image, that will automaticly update databases in folder `/srv/cvdupdate`, write logs to `/var/log/cvdupdate` and set owner of files to user with ID 1000

```bash
docker run -d \
-v /srv/cvdupdate:/cvdupdate/database \
-v /var/log/cvdupdate:/cvdupdate/logs \
-e USER_ID=1000 \
cvdupdate:latest
```

Default update interval is `30 */4 * * *` (see [Cron Example](#cron-example))

You may pass custom update interval in environment variable `CRON`

For example - update every day in 00:00

```bash
docker run -d \
-v /srv/cvdupdate:/cvdupdate/database \
-v /var/log/cvdupdate:/cvdupdate/logs \
-e CRON='0 0 * * *' \
cvdupdate:latest
```

## Contribute

We'd love your help. There are many ways to contribute!
Expand Down
41 changes: 41 additions & 0 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
USER_ID="${USER_ID:-0}"
SCRIPT_PATH=$(readlink -f "$0")
echo "ClamAV Private Database Mirror Updater Cron ${SCRIPT_PATH}"
if [ "${USER_ID}" -ne "0" ]; then
echo "Creating user with ID ${USER_ID}"
useradd --create-home --home-dir /cvdupdate --uid "${USER_ID}" cvdupdate
chown -R "${USER_ID}" /cvdupdate
gosu cvdupdate cvdupdate config set --logdir /cvdupdate/logs
gosu cvdupdate cvdupdate config set --dbdir /cvdupdate/database
else
mkdir -p /cvdupdate/{logs,database}
cvdupdate config set --logdir /cvdupdate/logs
cvdupdate config set --dbdir /cvdupdate/database
fi

if [ $# -eq 0 ]; then
set -e

echo "Adding crontab entry"
if [ "${USER_ID}" -ne "0" ]; then
crontab -l | {
cat
echo "${CRON:-"30 */4 * * *"} /usr/sbin/gosu cvdupdate /usr/local/bin/cvdupdate update >/proc/1/fd/1 2>/proc/1/fd/2"
echo "@reboot /usr/sbin/gosu cvdupdate /usr/local/bin/cvdupdate update >/proc/1/fd/1 2>/proc/1/fd/2"
} | crontab -
else
crontab -l | {
cat
echo "${CRON:-"30 */4 * * *"} /usr/local/bin/cvdupdate update >/proc/1/fd/1 2>/proc/1/fd/2"
echo "@reboot /usr/local/bin/cvdupdate update >/proc/1/fd/1 2>/proc/1/fd/2"
} | crontab -
fi
cron -f
else
if [ "${USER_ID}" -ne "0" ]; then
exec gosu cvdupdate "$@"
else
exec "$@"
fi
fi

0 comments on commit ead9cd2

Please sign in to comment.