Skip to content

Commit

Permalink
Remove python dep
Browse files Browse the repository at this point in the history
  • Loading branch information
thebalaa committed Feb 25, 2024
1 parent 75b66e5 commit 7ca30bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ 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)

link-ci:
./ci/create-link-ci.sh $(GATEWAY) $(FQDN) $(EXPOSE)
./ci/create-link-ci.sh gateway-sshd app.example.com nginx:80
3 changes: 2 additions & 1 deletion ci/create-link-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ docker network create gateway || true # create docker network if not exists
docker compose up -d --build
eval $(ssh-agent -s)
ssh-add ./gateway-sim-key
#
# generate a docker compose to test the generated link
cat test-link.template.yaml > test-link.yaml
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 >> test-link.yaml
cat network.yaml >> test-link.yaml
# set the gateway endpoint to the gateway link container
sed -i 's/^\(\s*GATEWAY_ENDPOINT:\).*/\1 app-example-com:18521/' test-link.yaml
docker compose -f test-link.yaml up -d
docker compose -f test-link.yaml exec link ping 10.0.0.1 -c 2
Expand Down
10 changes: 0 additions & 10 deletions ci/link.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions ci/test-link.template.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3.9'

# need this
networks:
gateway:
external: true

services:
services:
21 changes: 19 additions & 2 deletions src/create-link/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@

set -e

function fqdn_to_container_name() {
local fqdn="$1"

# Check if the FQDN is non-empty
if [[ -z "$fqdn" ]]; then
echo "Error: No FQDN provided."
return 1
fi

# Replace all dots with dashes
CONTAINER_NAME="${fqdn//./-}"

echo "$CONTAINER_NAME"
}

SSH_HOST=$1
SSH_PORT=22
# split port from SSH_HOST if SSH_HOST contains :
Expand All @@ -14,13 +29,15 @@ fi

export LINK_DOMAIN=$2
export EXPOSE=$3
export WG_PRIVKEY=$(wg genkey)
WG_PRIVKEY=$(wg genkey)
export WG_PRIVKEY
# Nginx uses Docker DNS resolver for dynamic mapping of LINK_DOMAIN to link container hostnames, see nginx/*.conf
# This is the magic.
# NOTE: All traffic for `*.subdomain.domain.tld`` will be routed to the container named `subdomain-domain-tld``
# Also supports `subdomain.domain.tld` as well as apex `domain.tld`
# *.domain.tld should resolve to the Gateway's public IPv4 address
export CONTAINER_NAME=$(echo $LINK_DOMAIN|python3 -c 'fqdn=input();print("-".join(fqdn.split(".")[-4:]))')
CONTAINER_NAME=$(fqdn_to_container_name "$LINK_DOMAIN")
export CONTAINER_NAME


LINK_CLIENT_WG_PUBKEY=$(echo $WG_PRIVKEY|wg pubkey)
Expand Down

0 comments on commit 7ca30bd

Please sign in to comment.