Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM golang:1.22-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download
COPY ./*.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o clamdproxy .

FROM alpine:latest

# Define build arguments with default values
ARG LISTEN_ADDR="0.0.0.0:3315"
ARG BACKEND_ADDR="clamav:3310"
ARG LOG_LEVEL="debug"
ARG METRICS_ADDR="0.0.0.0:2112"

# Create environment variables from the ARGs
ENV LISTEN_ADDR=${LISTEN_ADDR}
ENV BACKEND_ADDR=${BACKEND_ADDR}
ENV LOG_LEVEL=${LOG_LEVEL}
ENV METRICS_ADDR=${METRICS_ADDR}

RUN apk --no-cache add ca-certificates
WORKDIR /app
COPY --from=builder /app/clamdproxy /app/

# Create a startup script
RUN echo '#!/bin/sh' > /app/start.sh && \
echo 'exec /app/clamdproxy --listen "$LISTEN_ADDR" --backend "$BACKEND_ADDR" --log-level "$LOG_LEVEL" --metrics "$METRICS_ADDR"' >> /app/start.sh && \
chmod +x /app/start.sh

EXPOSE 3315 2112
ENTRYPOINT ["/app/start.sh"]
71 changes: 71 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: '3.8'

services:
clamav:
image: mkodockx/docker-clamav:alpine
container_name: clamav-docker
ports:
- "3310:3310"
volumes:
- ./testfiles:/scan
- clamav_data:/var/lib/clamav
restart: unless-stopped
healthcheck:
test: ["CMD", "./check.sh"]
interval: 30s
timeout: 10s
retries: 3
start_period: 120s
networks:
- clam-net
clamdproxy:
build:
context: ../
dockerfile: docker/Dockerfile
container_name: clamdproxy
ports:
- "3315:3315"
- "2112:2112"
depends_on:
clamav:
condition: service_healthy
restart: unless-stopped
networks:
- clam-net

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=15d'
networks:
- clam-net

grafana:
image: grafana/grafana:latest
ports:
- "3001:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_SECURITY_ADMIN_USER=admin
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- prometheus
networks:
- clam-net

volumes:
clamav_data:
prometheus_data:
grafana_data:

networks:
clam-net:
driver: bridge
62 changes: 62 additions & 0 deletions docker/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Docker Build and Run Guide

This guide explains how to build and run the ClamdProxy Docker container with custom configuration.

## Building the Docker Image

You can build the ClamdProxy Docker image using the following command:

```bash
docker build -t clamdproxy \
--build-arg LISTEN_ADDR=0.0.0.0:3315 \
--build-arg BACKEND_ADDR=docker.for.mac.localhost:3310 \
--build-arg LOG_LEVEL=debug \
--build-arg METRICS_ADDR=0.0.0.0:2112 \
-f docker/Dockerfile .
```

### Build Arguments

The Dockerfile supports the following build arguments:

| Argument | Description | Default Value |
|----------|-------------|---------------|
| `LISTEN_ADDR` | Address and port for ClamdProxy to listen on | `0.0.0.0:3315` |
| `BACKEND_ADDR` | Address and port of the clamd backend | `clamav:3310` |
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | `debug` |
| `METRICS_ADDR` | Address and port for exposing Prometheus metrics | `0.0.0.0:2112` |

## Running the Container

After building the image, you can run the container with:

```bash
docker run -p 3315:3315 -p 2112:2112 \
-e LISTEN_ADDR=0.0.0.0:3315 \
-e BACKEND_ADDR=docker.for.mac.localhost:3310 \
-e LOG_LEVEL=debug \
-e METRICS_ADDR=0.0.0.0:2112 \
clamdproxy
```

### Environment Variables

The container uses the following environment variables:

| Variable | Description | Default Value |
|----------|-------------|---------------|
| `LISTEN_ADDR` | Address and port for ClamdProxy to listen on | Value from build arg |
| `BACKEND_ADDR` | Address and port of the clamd backend | Value from build arg |
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | Value from build arg |
| `METRICS_ADDR` | Address and port for exposing Prometheus metrics | Value from build arg |

## Notes for macOS Users

When running Docker on macOS, use `docker.for.mac.localhost` to connect to clamD services running on your host machine. This is why the example uses `docker.for.mac.localhost:3310` as the backend address.

## Ports

- The proxy service listens on port 3315 (or as configured)
- Metrics are exposed on port 2112 (or as configured)

Make sure to map these ports correctly when running the container.
Loading