Skip to content

Commit 1a205b9

Browse files
committed
test,.github/workflows: add a test and CI action
Exercise the configuration and see if tailscaled is started. Various improvements to UX included as necessary for debugging and implementing the test. Updates #10
1 parent 5eec02a commit 1a205b9

File tree

6 files changed

+112
-14
lines changed

6 files changed

+112
-14
lines changed

.github/workflows/test.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test Devcontainer Feature
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test-feature:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Dev Container CLI
17+
run: |
18+
npm install -g @devcontainers/cli
19+
20+
- name: Run tests
21+
run: |
22+
npx @devcontainers/cli features test

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ To get started, add the following [feature](https://docs.github.com/en/codespace
99
to your `devcontainer.json`:
1010

1111
```json
12-
"runArgs": ["--device=/dev/net/tun"],
1312
"features": {
1413
"ghcr.io/tailscale/codespace/tailscale": {
1514
"version": "latest"

src/tailscale/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"documentationURL": "https://tailscale.com/kb/1160/github-codespaces/",
77
"licenseURL": "https://github.com/tailscale/codespace/blob/main/LICENSE",
88
"entrypoint": "/usr/local/sbin/tailscaled-entrypoint",
9-
"capAdd": ["NET_ADMIN", "NET_RAW"],
9+
"capAdd": ["NET_ADMIN", "NET_RAW", "MKNOD"],
1010
"options": {
1111
"version": {
1212
"type": "string",

src/tailscale/install.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Use of this source code is governed by a BSD-style
44
# license that can be found in the LICENSE file.
55

6-
set -euo pipefail
6+
set -xeuo pipefail
77

88
platform=$(uname -m)
99
if [ "$platform" = "x86_64" ]; then
@@ -15,14 +15,41 @@ else
1515
exit 1
1616
fi
1717

18+
CURL_INSTALL_ATTEMPTED=""
19+
install_curl() {
20+
CURL_INSTALL_ATTEMPTED=1
21+
22+
if type apt-get > /dev/null 2>/dev/null; then
23+
apt-get update
24+
# install recommends left on so we get ca-certificates.
25+
apt-get -y install curl
26+
elif type microdnf > /dev/null 2>/dev/null; then
27+
microdnf makecache
28+
microdnf -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0 curl
29+
elif type dnf > /dev/null 2>/dev/null; then
30+
dnf check-update
31+
dnf -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0 curl
32+
elif type yum > /dev/null 2>/dev/null; then
33+
yum -y install --noplugins --setopt=install_weak_deps=0 curl
34+
else
35+
2> echo "Unknown platform, can not automate curl install. curl is required to download tailscale"
36+
return 1
37+
fi
38+
}
39+
1840
download() {
1941
if command -v curl &> /dev/null; then
20-
curl -fsSL "$1"
42+
curl -fsSL "$@"
2143
elif command -v wget &> /dev/null; then
22-
wget -qO - "$1"
44+
wget -qO - "$@"
2345
else
24-
echo "Must install curl or wget to download $1" 1&>2
25-
return 1
46+
if [[ -z "$CURL_INSTALL_ATTEMPTED" ]]; then
47+
install_curl >&2
48+
download "$@"
49+
else
50+
echo "Must install curl or wget to download $1" >&2
51+
return 1
52+
fi
2653
fi
2754
}
2855

src/tailscale/tailscaled-entrypoint.sh

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,73 @@
33
# Use of this source code is governed by a BSD-style
44
# license that can be found in the LICENSE file.
55

6-
set -euxo pipefail
6+
check_userspace() {
7+
if [[ ! -c /dev/net/tun ]]; then
8+
>&2 cat - <<-EOF
9+
Error: /dev/net/tun is missing and could not be created!
10+
11+
taiilscaled will fail to start.
12+
13+
You can start tailscaled manually in userspace mode, see:
14+
https://tailscale.com/kb/1112/userspace-networking
15+
EOF
16+
fi
17+
}
718

819
# Note: It is not recommended that users copy this setting into other
920
# environments, the feature is in test and will be formally released in the
1021
# future, debug flags may later be recycled for other purposes leading to
1122
# unexpected behavior.
1223
export TS_DEBUG_FIREWALL_MODE=auto
24+
TAILSCALED_PID=""
25+
TAILSCALED_SOCK=/var/run/tailscale/tailscaled.sock
26+
TAILSCALED_LOG=/var/log/tailscaled.log
1327
if [[ "$(id -u)" -eq 0 ]]; then
14-
mkdir -p /workspaces/.tailscale || true
15-
2>/dev/null >/dev/null \
28+
if [[ ! -c /dev/net/tun ]]; then
29+
mkdir -p /dev/net
30+
mknod /dev/net/tun c 10 200
31+
fi
32+
check_userspace
33+
mkdir -p /workspaces/.tailscale /var/log
34+
touch $TAILSCALED_LOG
35+
>$TAILSCALED_LOG 2>&1 \
1636
/usr/local/sbin/tailscaled \
1737
--statedir=/workspaces/.tailscale/ \
18-
--socket=/var/run/tailscale/tailscaled.sock \
38+
--socket=$TAILSCALED_SOCK \
1939
--port=41641 &
40+
TAILSCALED_PID=$!
2041
elif command -v sudo > /dev/null; then
21-
sudo --non-interactive mkdir -p /workspaces/.tailscale
22-
2>/dev/null >/dev/null \
42+
if [[ ! -c /dev/net/tun ]]; then
43+
sudo --non-interactive mkdir -p /dev/net
44+
sudo --non-interactive mknod /dev/net/tun c 10 200
45+
fi
46+
check_userspace
47+
sudo --non-interactive mkdir -p /workspaces/.tailscale /var/log
48+
sudo --non-interactive touch $TAILSCALED_LOG
49+
>$TAILSCALED_LOG 2>&1 \
2350
sudo --non-interactive "TS_DEBUG_FIREWALL_MODE=$TS_DEBUG_FIREWALL_MODE" \
2451
/usr/local/sbin/tailscaled \
2552
--statedir=/workspaces/.tailscale/ \
26-
--socket=/var/run/tailscale/tailscaled.sock \
53+
--socket=$TAILSCALED_SOCK \
2754
--port=41641 &
55+
TAILSCALED_PID=$!
2856
else
2957
>&2 echo "tailscaled could not start as root."
3058
fi
3159
unset TS_DEBUG_FIREWALL_MODE
3260

61+
if [[ -n "$TAILSCALED_PID" ]]; then
62+
count=100
63+
while ((count--)); do
64+
[[ -f $TAILSCALED_SOCK ]] && break
65+
sleep 0.01
66+
67+
if ! kill -0 "$TAILSCALED_PID"; then
68+
>&2 echo "ERROR: tailscaled exited during startup, logs follow:"
69+
>&2 cat $TAILSCALED_LOG
70+
break
71+
fi
72+
done
73+
fi
74+
3375
exec "$@"

test/tailscale/test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# Copyright (c) 2025 Tailscale Inc & AUTHORS All rights reserved.
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file.
5+
6+
set -e
7+
8+
tailscale version --daemon

0 commit comments

Comments
 (0)