diff --git a/Makefile b/Makefile index 9e8e4e3..c66ae59 100644 --- a/Makefile +++ b/Makefile @@ -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) \ No newline at end of file + ./ci/create-link-ci.sh gateway-sshd app.example.com nginx:80 diff --git a/ci/create-link-ci.sh b/ci/create-link-ci.sh index 5fde1f9..65bbc7d 100755 --- a/ci/create-link-ci.sh +++ b/ci/create-link-ci.sh @@ -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 diff --git a/ci/link.yaml b/ci/link.yaml deleted file mode 100644 index 4573da7..0000000 --- a/ci/link.yaml +++ /dev/null @@ -1,10 +0,0 @@ -link: - image: fractalnetworks/gateway-client:latest - environment: - LINK_DOMAIN: app.example.com - EXPOSE: app:3000 - GATEWAY_CLIENT_WG_PRIVKEY: sJ0KvUe9NRApimZr7cn3v/upyyW8cCzWAz9ogz7FXl4= - GATEWAY_LINK_WG_PUBKEY: Q2wp3wXj6CKmjNEJF0s+c2aatMzdFvhfZX56XhA9e0k= - GATEWAY_ENDPOINT: 130.18.104.86:64950 - cap_add: - - NET_ADMIN diff --git a/ci/test-link.template.yaml b/ci/test-link.template.yaml index bb4efa8..f182416 100644 --- a/ci/test-link.template.yaml +++ b/ci/test-link.template.yaml @@ -1,8 +1,7 @@ version: '3.9' -# need this networks: gateway: external: true -services: +services: diff --git a/src/create-link/entrypoint.sh b/src/create-link/entrypoint.sh index 3aef0fe..ba7f9ca 100755 --- a/src/create-link/entrypoint.sh +++ b/src/create-link/entrypoint.sh @@ -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 : @@ -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)