Skip to content

Commit

Permalink
Add CI Github Action (#36)
Browse files Browse the repository at this point in the history
* Generate link with Github action on commit

---------

Co-authored-by: Justin <jrussel1055@gmail.com>
  • Loading branch information
thebalaa and justin-russell authored Feb 22, 2024
1 parent 9c89963 commit 181f853
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches:
- '**' # This will run the workflow on every push to any branch

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build images
run: make docker

- name: Launch gateway and create link on gateway
run: make link-ci GATEWAY=gateway-sshd FQDN=app.example.com EXPOSE=app:3000

#- name: Ensure link works by making request to app.example.com
# run: curl --resolve app.example.com:443:127.0.0.1 http://app.example.com:443


- name: Cleanup
run: docker compose -f ./ci/docker-compose.yaml down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gateway-sim-key*
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: docker link setup gateway
.PHONY: docker link setup gateway ci

docker:
docker build -t fractalnetworks/selfhosted-gateway:latest ./src/gateway/
Expand All @@ -16,4 +16,7 @@ link:
docker run -e SSH_AGENT_PID=$$SSH_AGENT_PID -e SSH_AUTH_SOCK=$$SSH_AUTH_SOCK -v $$SSH_AUTH_SOCK:$$SSH_AUTH_SOCK --rm -it fractalnetworks/gateway-cli:latest $(GATEWAY) $(FQDN) $(EXPOSE)

link-macos:
docker run -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" --rm -it fractalnetworks/gateway-cli:latest $(GATEWAY) $(FQDN) $(EXPOSE}
docker run -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" --rm -it fractalnetworks/gateway-cli:latest $(GATEWAY) $(FQDN) $(EXPOSE)

link-ci:
./ci/create-link-ci.sh $(GATEWAY) $(FQDN) $(EXPOSE)
8 changes: 8 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:latest
RUN apk add openssh-server bash docker-cli curl
RUN ssh-keygen -A

COPY gateway-sim-key.pub /root/.ssh/authorized_keys

ENTRYPOINT [ "/usr/sbin/sshd", "-D", "-e" ]

11 changes: 11 additions & 0 deletions ci/create-link-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

cd ci/
ssh-keygen -t ed25519 -f ./gateway-sim-key -N ""
# create docker network if not exists
docker network create gateway || true
docker compose up -d --build
eval $(ssh-agent -s)
ssh-add ./gateway-sim-key
docker run --network gateway -e SSH_AGENT_PID=$SSH_AGENT_PID -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK -v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK --rm fractalnetworks/gateway-cli:latest $1 $2 $3
21 changes: 21 additions & 0 deletions ci/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.9'
services:
gateway-sshd:
build: .
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- gateway
gateway:
image: fractalnetworks/selfhosted-gateway:latest
environment:
NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx
networks:
- gateway


networks:
gateway:
external: true


11 changes: 10 additions & 1 deletion src/create-link/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
set -e

SSH_HOST=$1
SSH_PORT=22
# split port from SSH_HOST if SSH_HOST contains :
if [[ $SSH_HOST == *":"* ]]; then
IFS=':' read -ra ADDR <<< "$SSH_HOST"
SSH_HOST=${ADDR[0]}
SSH_PORT=${ADDR[1]}
fi
echo $SSH_HOST
echo $SSH_PORT
export LINK_DOMAIN=$2
export EXPOSE=$3
export WG_PRIVKEY=$(wg genkey)
Expand All @@ -16,7 +25,7 @@ export CONTAINER_NAME=$(echo $LINK_DOMAIN|python3 -c 'fqdn=input();print("-".joi


LINK_CLIENT_WG_PUBKEY=$(echo $WG_PRIVKEY|wg pubkey)
LINK_ENV=$(ssh $SSH_HOST "bash -s" -- < ./remote.sh $CONTAINER_NAME $LINK_CLIENT_WG_PUBKEY)
LINK_ENV=$(ssh -o StrictHostKeyChecking=accept-new $SSH_HOST -p $SSH_PORT "bash -s" -- < ./remote.sh $CONTAINER_NAME $LINK_CLIENT_WG_PUBKEY)

# convert to array
RESULT=($LINK_ENV)
Expand Down

0 comments on commit 181f853

Please sign in to comment.