Skip to content

Instantly share code, notes, and snippets.

@jsiebens
Last active November 4, 2021 08:18
Show Gist options
  • Save jsiebens/4cf66c135ecefe8638c06a16c488b201 to your computer and use it in GitHub Desktop.
Save jsiebens/4cf66c135ecefe8638c06a16c488b201 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
appname="--generatename"
orgname="personal"
region=""
internal_port="8080"
external_port=""
if [ -n "${INLETS_FLY_NAME}" ]; then
appname=${INLETS_FLY_NAME}
fi
if [ -n "${INLETS_FLY_ORG}" ]; then
orgname=${INLETS_FLY_ORG}
fi
if [ -n "${INLETS_FLY_REGION}" ]; then
region=${INLETS_FLY_REGION}
fi
if [ -n "${INLETS_FLY_INTERNAL_PORT}" ]; then
internal_port=${INLETS_FLY_INTERNAL_PORT}
fi
if [ -n "${INLETS_FLY_EXTERNAL_PORT}" ]; then
external_port=${INLETS_FLY_EXTERNAL_PORT}
fi
token=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32 ; echo '')
if [ -z "$external_port" ]; then
tee import.toml >/dev/null <<EOF
[[services]]
internal_port = 8123
protocol = "tcp"
[[services.ports]]
handlers = []
port = 10023
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 6
timeout = "2s"
[[services]]
internal_port = ${internal_port}
protocol = "tcp"
[[services.ports]]
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
EOF
else
tee import.toml >/dev/null <<EOF
[[services]]
internal_port = 8123
protocol = "tcp"
[[services.ports]]
handlers = []
port = 10023
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 6
timeout = "2s"
[[services]]
internal_port = ${internal_port}
protocol = "tcp"
[[services.ports]]
handlers = []
port = ${external_port}
EOF
fi
flyctl init $appname --import import.toml --org $orgname --overwrite --dockerfile
rm import.toml
name=$(flyctl info | grep Name | cut -c 14- | xargs)
tee Dockerfile >/dev/null <<EOF
FROM ghcr.io/inlets/inlets-pro:0.9.1
CMD ["tcp", "server", "--auto-tls-san=${name}.fly.dev", "--token-env=TOKEN"]
EOF
if [ -n "$region" ]; then
flyctl regions set $region
fi
flyctl secrets set TOKEN=$token
flyctl deploy
echo "
==================================================================
inlets PRO TCP (${name}) server summary:
URL: wss://${name}.fly.dev:10023/connect
Auth-token: ${token}
Command:
# Obtain a license at https://inlets.dev
# Store it at $HOME/.inlets/LICENSE or use --help for more options
export PORTS=\"${internal_port}\"
export UPSTREAM=\"localhost\"
inlets-pro tcp client \\
--url wss://${name}.fly.dev:10023/connect \\
--token ${token} \\
--upstream \$UPSTREAM \\
--ports \$PORTS
To delete:
flyctl destroy ${name}
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment