diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bca78f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ + +FROM alpine:3.19.2 + +ARG AWGTOOLS_RELEASE=1.0.20240213 +# ARG AWGTOOLS_RELEASE=1.0.20250706 + +RUN apk --no-cache add iproute2 iptables bash && \ + cd /usr/bin/ && \ + wget https://github.com/amnezia-vpn/amneziawg-tools/releases/download/v${AWGTOOLS_RELEASE}/alpine-3.19-amneziawg-tools.zip && \ + unzip -j alpine-3.19-amneziawg-tools.zip && \ + chmod +x /usr/bin/awg /usr/bin/awg-quick && \ + ln -s /usr/bin/awg /usr/bin/wg && \ + ln -s /usr/bin/awg-quick /usr/bin/wg-quick + +# COPY /usr/bin/amneziawg-go /usr/bin/amneziawg-go + +RUN apk add --no-cache openresolv dpkg dumb-init iptables-legacy && \ + update-alternatives --install /sbin/iptables iptables /sbin/iptables-legacy 10 --slave /sbin/iptables-restore iptables-restore /sbin/iptables-legacy-restore --slave /sbin/iptables-save iptables-save /sbin/iptables-legacy-save && \ + mkdir /config && \ + mkdir -p /etc/amnezia/amneziawg + +COPY init.sh init.sh +RUN chmod +x init.sh + +HEALTHCHECK --interval=1m --timeout=5s --retries=3 CMD /usr/bin/timeout 5s /bin/sh -c \"awg show | grep interface || exit 1\" +ENTRYPOINT ["/usr/bin/dumb-init", "/init.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a7ce297 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +services: + awgtest: + build: + context: . + dockerfile: Dockerfile + container_name: awgtest + cap_add: + - NET_ADMIN + - SYS_MODULE + # sysctls: + # - net.ipv4.ip_forward=1 + # - net.ipv4.conf.all.src_valid_mark=1 + network_mode: host + devices: + - /dev/net/tun:/dev/net/tun + volumes: + - ./config:/config + restart: unless-stopped \ No newline at end of file diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..a6cfb58 --- /dev/null +++ b/init.sh @@ -0,0 +1,24 @@ +#!/bin/bash +find /etc/amnezia/amneziawg -mindepth 1 -delete +COUNTER=0 +for s in $(find /config -name "*.conf") +do + if test -f ${s} + then + COUNTER=$(( COUNTER + 1 )) + basename=$(basename ${s}) + name=${basename%.conf} + echo awg interface "${name}" will be created from config file "${basename}" + cp ${s} /etc/amnezia/amneziawg/${name}.conf + chmod 600 /etc/amnezia/amneziawg/${name}.conf + awg-quick up ${name} + iptables -A FORWARD -i ${name} -j ACCEPT + iptables -A FORWARD -o ${name} -j ACCEPT + iptables -A FORWARD -i ${name} -o ${name} -j ACCEPT + fi +done + +if [[ $COUNTER -lt 1 ]] +then + echo "There are no config files in the /config folder" +fi