Setup tailscale on instances, create a common network script

This commit is contained in:
Mikhail f. Shiryaev 2024-02-22 15:21:41 +01:00
parent a768f40adc
commit 758acd4268
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
3 changed files with 30 additions and 26 deletions

View File

@ -1,19 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -xeuo pipefail set -xeuo pipefail
# Add cloudflare DNS as a fallback bash /usr/local/share/scripts/init-network.sh
# Get default gateway interface
IFACE=$(ip --json route list | jq '.[]|select(.dst == "default").dev' --raw-output)
# `Link 2 (eth0): 172.31.0.2`
ETH_DNS=$(resolvectl dns "$IFACE") || :
CLOUDFLARE_NS=1.1.1.1
if [[ "$ETH_DNS" ]] && [[ "${ETH_DNS#*: }" != *"$CLOUDFLARE_NS"* ]]; then
# Cut the leading legend
ETH_DNS=${ETH_DNS#*: }
# shellcheck disable=SC2206
new_dns=(${ETH_DNS} "$CLOUDFLARE_NS")
resolvectl dns "$IFACE" "${new_dns[@]}"
fi
# tune sysctl for network performance # tune sysctl for network performance
cat > /etc/sysctl.d/10-network-memory.conf << EOF cat > /etc/sysctl.d/10-network-memory.conf << EOF

View File

@ -60,19 +60,7 @@ export RUNNER_URL="https://github.com/${RUNNER_ORG}"
INSTANCE_ID=$(ec2metadata --instance-id) INSTANCE_ID=$(ec2metadata --instance-id)
export INSTANCE_ID export INSTANCE_ID
# Add cloudflare DNS as a fallback bash /usr/local/share/scripts/init-network.sh
# Get default gateway interface
IFACE=$(ip --json route list | jq '.[]|select(.dst == "default").dev' --raw-output)
# `Link 2 (eth0): 172.31.0.2`
ETH_DNS=$(resolvectl dns "$IFACE") || :
CLOUDFLARE_NS=1.1.1.1
if [[ "$ETH_DNS" ]] && [[ "${ETH_DNS#*: }" != *"$CLOUDFLARE_NS"* ]]; then
# Cut the leading legend
ETH_DNS=${ETH_DNS#*: }
# shellcheck disable=SC2206
new_dns=(${ETH_DNS} "$CLOUDFLARE_NS")
resolvectl dns "$IFACE" "${new_dns[@]}"
fi
# combine labels # combine labels
RUNNER_TYPE=$(/usr/local/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" --query "Tags[?Key=='github:runner-type'].Value" --output text) RUNNER_TYPE=$(/usr/local/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" --query "Tags[?Key=='github:runner-type'].Value" --output text)

View File

@ -153,6 +153,34 @@ apt-get update
apt-get install tailscale --yes --no-install-recommends apt-get install tailscale --yes --no-install-recommends
# Create a common script for the instances
mkdir /usr/local/share/scripts -p
cat > /usr/local/share/scripts/init-network.sh << 'EOF'
#!/usr/bin/env bash
# Add cloudflare DNS as a fallback
# Get default gateway interface
IFACE=$(ip --json route list | jq '.[]|select(.dst == "default").dev' --raw-output)
# `Link 2 (eth0): 172.31.0.2`
ETH_DNS=$(resolvectl dns "$IFACE") || :
CLOUDFLARE_NS=1.1.1.1
if [[ "$ETH_DNS" ]] && [[ "${ETH_DNS#*: }" != *"$CLOUDFLARE_NS"* ]]; then
# Cut the leading legend
ETH_DNS=${ETH_DNS#*: }
# shellcheck disable=SC2206
new_dns=(${ETH_DNS} "$CLOUDFLARE_NS")
resolvectl dns "$IFACE" "${new_dns[@]}"
fi
# Setup tailscale, the very first action
TS_API_CLIENT_ID=$(aws ssm get-parameter --region us-east-1 --name /tailscale/api-client-id --query 'Parameter.Value' --output text --with-decryption)
TS_API_CLIENT_SECRET=$(aws ssm get-parameter --region us-east-1 --name /tailscale/api-client-secret --query 'Parameter.Value' --output text --with-decryption)
export TS_API_CLIENT_ID TS_API_CLIENT_SECRET
TS_AUTHKEY=$(get-authkey -tags tag:svc-core-ci-github -reusable -ephemeral)
tailscale up --ssh --auth-key="$TS_AUTHKEY" --hostname="ci-runner-$INSTANCE_ID"
EOF
# The following line is used in aws TOE check. # The following line is used in aws TOE check.
touch /var/tmp/clickhouse-ci-ami.success touch /var/tmp/clickhouse-ci-ami.success
# END OF THE SCRIPT # END OF THE SCRIPT