Skip to content

Commit

Permalink
Add docker workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 11, 2023
1 parent a9da2a7 commit 8f99ba3
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 19 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/test.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Go
on: [push]

jobs:
build-and-deploy:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v3

- name: Install dependencies
run: sudo apt install -y make wget llvm clang gcc git npm gulp libbpf-dev

- name: Set asm version
run: sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm

- name: Build with make
run: sudo make release

- name: Test with the Go CLI
run: sudo go test -v ./...

- name: docker login
env:
DOCKER_ACCESS_TOKEN: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
docker login -u wagvpn -p $DOCKER_ACCESS_TOKEN
- name: Build the Docker image
run: docker build . --file Dockerfile --tag wagvpn/wag:$(date +%s) --tag wagvpn/wag

- name: Docker Push
run: docker push wagvpn/wag
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM redhat/ubi9-minimal:latest

RUN microdnf update -y
RUN microdnf install -y iptables nc

WORKDIR /app/wag

COPY wag /usr/bin/wag
COPY example_config.json /tmp

COPY docker_entrypoint.sh /
RUN chmod +x /docker_entrypoint.sh

VOLUME /data
VOLUME /cfg

CMD ["/docker_entrypoint.sh"]
32 changes: 32 additions & 0 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if [ ! -f /cfg/config.json ]; then
echo "No config file found, generating from example. Ensure /data is mounted for persistence"
cp /tmp/example_config.json /cfg/config.json
sed -i "s|AN EXAMPLE KEY|$(wg genkey)|" /cfg/config.json
sed -i "s|\"devices.db\"|\"/data/devices.db\"|" /cfg/config.json
echo "Please edit your newly generated config file and start again"
exit
fi

# trap for all processes created inside this block; a single Ctrl+C will stop them all
(trap 'kill 0' SIGINT

echo "WAG: start"
wag start -config /cfg/config.json &

while ! nc -z localhost 4433; do
echo "Waiting WAG to become online on port 4433 ..."
sleep 0.5
done

U=$(wag webadmin -list | grep $WEB_USER | cut -d, -f1)
if [ "$U" != "$WEB_USER" ]; then
echo "WEBADMIN: add user $WEB_USER"
wag webadmin -add -username "$WEB_USER" -password "$WEB_PWD"
else
echo "WEBADMIN: user $WEB_USER exists, nothing updated"
fi

# block until 'wag start' finishes
wait )
31 changes: 31 additions & 0 deletions example-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3.4'
services:
wag-docker:
container_name: wag
env_file:
- .env
build:
context: .
args:
WEB_USER: ${WEB_USER}
WEB_PWD: ${WEB_PWD}
ports:
- '4433:4433/tcp'
- '7080:7080/tcp'
- '8009:8009/udp'
- '443:443/tcp'
cap_add:
- NET_ADMIN
- NET_RAW
- SYS_ADMIN
ulimits:
# see PR #1
memlock: -1
nofile:
soft: "65536"
hard: "65536"
# tests with complete reg/auth didn't require privileged, so it is optional
# privileged: true
volumes:
- './cfg:/cfg:z'
- './data:/data:z'
15 changes: 15 additions & 0 deletions release_builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian:latest
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y make wget llvm clang gcc git npm gulp libbpf-dev
RUN wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz
ENV PATH="$PATH:/usr/local/go/bin"
RUN mkdir -p /build/
RUN chmod 777 /build/
WORKDIR /build
ADD build-wag.sh .
RUN ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
RUN chmod 777 build-wag.sh
ENTRYPOINT ["bash", "/build/build-wag.sh"]

13 changes: 13 additions & 0 deletions release_builder/build-wag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [[ ! -d /wag ]]; then
echo "/wag not present, please mount folder onto docker container with -v"
exit 1
fi


cd /wag
mkdir /build/go
export GOPATH=/build/go
export GOCACHE=/build/
make release

0 comments on commit 8f99ba3

Please sign in to comment.