2023-09-30 01:50:21 +02:00
|
|
|
name: Continuous Integration
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
schedule:
|
|
|
|
- cron: "0 0 * * TUE"
|
|
|
|
|
2023-10-03 18:32:07 +02:00
|
|
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
|
|
|
|
env:
|
|
|
|
platforms: "linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7"
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
jobs:
|
2023-10-03 18:32:07 +02:00
|
|
|
ci:
|
|
|
|
name: Continuous Integration
|
2023-09-30 01:50:21 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
timeout-minutes: 10
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Load necessary kernel modules
|
|
|
|
run: sudo modprobe ip6_tables
|
2023-09-30 01:50:21 +02:00
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Install WireGuard
|
2023-09-30 01:50:21 +02:00
|
|
|
run: sudo apt-get install wireguard
|
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Create WireGuard config
|
2023-10-03 18:32:07 +02:00
|
|
|
run: echo '${{ secrets.WIREGUARD_CONF }}' > wireguard.conf
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
|
|
|
|
- name: Set up Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Build local Docker image for testing
|
2023-09-30 01:50:21 +02:00
|
|
|
uses: docker/build-push-action@v5
|
|
|
|
with:
|
|
|
|
pull: true
|
|
|
|
load: true
|
|
|
|
tags: wireguard
|
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Copy Docker image to Podman
|
|
|
|
run: |
|
|
|
|
sudo podman pull docker-daemon:docker.io/library/wireguard:latest
|
|
|
|
sudo podman save -o ${{ runner.temp }}/wireguard.tar docker.io/library/wireguard:latest
|
|
|
|
podman load -i ${{ runner.temp }}/wireguard.tar
|
|
|
|
|
2023-10-03 17:54:42 +02:00
|
|
|
- name: Test tunnel
|
2023-09-30 01:50:21 +02:00
|
|
|
run: |
|
2023-10-04 18:49:03 +02:00
|
|
|
for cmd in "docker" "podman" "sudo podman"; do
|
|
|
|
$cmd run --rm -d --name wireguard --cap-add NET_ADMIN --cap-add NET_RAW --cap-add SYS_MODULE --sysctl net.ipv4.conf.all.src_valid_mark=1 -v ${{ github.workspace }}/wireguard.conf:/etc/wireguard/wg0.conf wireguard
|
2023-10-04 19:13:51 +02:00
|
|
|
normal_ip=$($cmd run --rm curlimages/curl --retry 3 --retry-delay 1 --retry-all-errors ifconfig.io)
|
|
|
|
wireguard_ip=$($cmd run --rm --net=container:wireguard curlimages/curl --retry 3 --retry-delay 1 --retry-all-errors ifconfig.io)
|
2023-10-04 18:49:03 +02:00
|
|
|
if [ "$normal_ip" = "$wireguard_ip" ]; then echo "normal ip and wireguard ip are the same" && exit 1; fi
|
|
|
|
$cmd stop wireguard
|
|
|
|
done
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Test kill switch
|
|
|
|
run: |
|
2023-10-04 18:49:03 +02:00
|
|
|
for cmd in "docker" "podman" "sudo podman"; do
|
|
|
|
$cmd run --rm -d --name wireguard --cap-add NET_ADMIN --cap-add NET_RAW --cap-add SYS_MODULE --sysctl net.ipv4.conf.all.src_valid_mark=1 -v ${{ github.workspace }}/wireguard.conf:/etc/wireguard/wg0.conf wireguard
|
2023-10-04 19:13:51 +02:00
|
|
|
$cmd run --rm --net=container:wireguard curlimages/curl --retry 3 --retry-delay 1 --retry-all-errors ifconfig.io
|
2023-10-04 18:49:03 +02:00
|
|
|
$cmd exec wireguard wg-quick down wg0
|
2023-10-04 19:13:51 +02:00
|
|
|
! $cmd run --rm --net=container:wireguard curlimages/curl --retry 3 --retry-delay 1 --retry-all-errors ifconfig.io
|
2023-10-04 18:49:03 +02:00
|
|
|
$cmd stop wireguard
|
|
|
|
done
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Test local subnets
|
|
|
|
run: |
|
2023-10-04 18:49:03 +02:00
|
|
|
for cmd in "docker" "podman" "sudo podman"; do
|
|
|
|
ip_address=$(ip route get 1.2.3.4 | awk '{print $7}')
|
|
|
|
$cmd run --rm -d --name nginx -p 8080:80 nginx
|
|
|
|
$cmd run --rm -d --name wireguard --cap-add NET_ADMIN --cap-add NET_RAW --cap-add SYS_MODULE --sysctl net.ipv4.conf.all.src_valid_mark=1 -v ${{ github.workspace }}/wireguard.conf:/etc/wireguard/wg0.conf -e LOCAL_SUBNETS=$ip_address/32 wireguard
|
2023-10-04 19:13:51 +02:00
|
|
|
$cmd run --rm --net=container:wireguard curlimages/curl --retry 3 --retry-delay 1 --retry-all-errors $ip_address:8080
|
2023-10-04 18:49:03 +02:00
|
|
|
$cmd stop wireguard nginx
|
|
|
|
done
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Test exposed ports
|
|
|
|
run: |
|
2023-10-04 18:49:03 +02:00
|
|
|
for cmd in "docker" "podman" "sudo podman"; do
|
|
|
|
$cmd run --rm -d --name wireguard --cap-add NET_ADMIN --cap-add NET_RAW --cap-add SYS_MODULE --sysctl net.ipv4.conf.all.src_valid_mark=1 -v ${{ github.workspace }}/wireguard.conf:/etc/wireguard/wg0.conf -p 8080:80 wireguard
|
|
|
|
$cmd run --rm -d --name nginx --net=container:wireguard nginx
|
2023-10-04 19:13:51 +02:00
|
|
|
curl --retry 3 --retry-delay 1 --retry-all-errors localhost:8080
|
2023-10-04 18:49:03 +02:00
|
|
|
$cmd stop wireguard nginx
|
|
|
|
done
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Log into Docker Hub
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
with:
|
|
|
|
username: jordanpotter
|
|
|
|
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
|
|
|
|
|
|
|
- name: Log into GitHub Container Registry
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2023-10-04 18:49:03 +02:00
|
|
|
- name: Get date
|
|
|
|
id: date
|
|
|
|
uses: josStorer/get-current-time@v2
|
|
|
|
with:
|
|
|
|
format: YYYY-MM-DD
|
|
|
|
|
2023-09-30 01:50:21 +02:00
|
|
|
- name: Get metadata for image
|
|
|
|
id: metadata
|
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
with:
|
|
|
|
images: |
|
|
|
|
jordanpotter/wireguard
|
|
|
|
ghcr.io/${{ github.repository }}
|
|
|
|
tags: |
|
2023-10-03 18:32:07 +02:00
|
|
|
type=raw,value=${{ steps.date.outputs.formattedTime }},enable=${{ github.event_name == 'schedule' }}
|
|
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
|
|
|
|
|
|
- name: Build images
|
|
|
|
if: ${{ github.ref != 'refs/heads/main' }}
|
|
|
|
uses: docker/build-push-action@v5
|
|
|
|
with:
|
|
|
|
pull: true
|
|
|
|
push: false
|
|
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
|
|
|
platforms: ${{ env.platforms }}
|
2023-09-30 01:50:21 +02:00
|
|
|
|
|
|
|
- name: Build and push images
|
2023-10-03 18:32:07 +02:00
|
|
|
if: ${{ github.ref == 'refs/heads/main' }}
|
2023-09-30 01:50:21 +02:00
|
|
|
uses: docker/build-push-action@v5
|
|
|
|
with:
|
|
|
|
pull: true
|
|
|
|
push: true
|
|
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
2023-10-03 18:32:07 +02:00
|
|
|
platforms: ${{ env.platforms }}
|
2023-09-30 01:51:15 +02:00
|
|
|
|
|
|
|
- name: Update Docker Hub description
|
2023-10-03 18:32:07 +02:00
|
|
|
if: ${{ github.ref == 'refs/heads/main' }}
|
2023-09-30 01:51:15 +02:00
|
|
|
uses: peter-evans/dockerhub-description@v3
|
|
|
|
with:
|
|
|
|
repository: jordanpotter/wireguard
|
|
|
|
username: jordanpotter
|
|
|
|
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
|
|
|
short-description: ${{ github.event.repository.description }}
|