Skip to content

Commit 36ff242

Browse files
authored
Convert into Dev Container feature (#6)
* Convert into Dev Container feature Fixes #5 * Redirect tailscaled log to /dev/null * Use --statedir instead of --state * Updated tailscale up command * Revert accidental removal
1 parent 7696139 commit 36ff242

File tree

8 files changed

+123
-100
lines changed

8 files changed

+123
-100
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Release Dev Container feature
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
- name: Publish Features
11+
uses: devcontainers/action@v1
12+
with:
13+
publish-features: "true"
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
permissions:
17+
contents: read
18+
packages: write

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
# Codespace with Tailscale connectivity
2-
This repository contains a simple [codespace devcontainer](https://github.com/features/codespaces)
3-
which can connect the running VM to a [Tailscale network](https://tailscale.com). To use it
4-
you need to be a member of a GitHub Organization which has Codespaces enabled. When you
5-
click on the Code button you should see a second tab with an option to start up
6-
a new codespace.
1+
# Codespace feature for Tailscale connectivity
2+
3+
This repository contains a feature for [GitHub Codespaces](https://github.com/features/codespaces)
4+
to connect the running VM to a [Tailscale network](https://tailscale.com).
75

86
![Start a new codespace](codespace.jpg)
97

10-
You need to create a [Reusable Authkey](https://login.tailscale.com/admin/settings/authkeys)
11-
for your Tailnet and add it as a [Codespaces Secret](https://github.com/settings/codespaces)
12-
named `TAILSCALE_AUTHKEY`.
8+
To get started, add the following [feature](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-features-to-a-devcontainer-file)
9+
to your `devcontainer.json`:
10+
11+
```json
12+
"runArgs": ["--device=/dev/net/tun"],
13+
"features": {
14+
// ...
15+
"ghcr.io/tailscale/codespace/tailscale": {}
16+
// ...
17+
}
18+
```
19+
20+
Then launch your Codespace. After it starts up, run [`tailscale up`](https://tailscale.com/kb/1080/cli/#up):
21+
22+
```shell
23+
sudo tailscale up --accept-routes
24+
```
1325

14-
Then launch your codespace!
26+
You'll only need to run `tailscale up` once per Codespace.
27+
The Tailscale state will be saved between rebuilds.

tailscale/devcontainer-feature.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Tailscale",
3+
"id": "tailscale",
4+
"description": "Connect to your tailnet in your development container",
5+
"documentationURL": "https://tailscale.com/kb/1160/github-codespaces/",
6+
"licenseURL": "https://github.com/tailscale/codespace/blob/main/LICENSE",
7+
"entrypoint": "/usr/local/sbin/tailscaled-entrypoint",
8+
"capAdd": ["NET_ADMIN", "NET_RAW"],
9+
"options": {
10+
"version": {
11+
"type": "string",
12+
"default": "1.34.0",
13+
"description": "Version of Tailscale to download"
14+
}
15+
}
16+
}

tailscale/install.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2022 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 -euo pipefail
7+
8+
tailscale_url="https://pkgs.tailscale.com/stable/tailscale_${VERSION}_amd64.tgz"
9+
10+
download() {
11+
if command -v curl >& /dev/null; then
12+
curl -fsSL "$1"
13+
elif command -v wget >& /dev/null; then
14+
wget -qO - "$1"
15+
else
16+
echo "Must install curl or wget to download $1" 1>&2
17+
return 1
18+
fi
19+
}
20+
21+
script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
22+
scratch_dir="/tmp/tailscale"
23+
mkdir -p "$scratch_dir"
24+
trap 'rm -rf "$scratch_dir"' EXIT
25+
26+
download "$tailscale_url" |
27+
tar -xzf - --strip-components=1 -C "$scratch_dir"
28+
install "$scratch_dir/tailscale" /usr/local/bin/tailscale
29+
install "$scratch_dir/tailscaled" /usr/local/sbin/tailscaled
30+
install "$script_dir/tailscaled-entrypoint.sh" /usr/local/sbin/tailscaled-entrypoint
31+
32+
mkdir -p /var/lib/tailscale /var/run/tailscale
33+
34+
if ! command -v iptables >& /dev/null; then
35+
if command -v apt-get >& /dev/null; then
36+
apt-get update
37+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends iptables
38+
rm -rf /var/lib/apt/lists/*
39+
else
40+
echo "WARNING: iptables not installed. tailscaled might fail."
41+
fi
42+
fi

tailscale/tailscaled-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2022 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 -euxo pipefail
7+
8+
if [[ "$(id -u)" -eq 0 ]]; then
9+
mkdir -p /workspaces/.tailscale || true
10+
/usr/local/sbin/tailscaled \
11+
--statedir=/workspaces/.tailscale/ \
12+
--socket=/var/run/tailscale/tailscaled.sock \
13+
--port=41641 \
14+
>& /dev/null &
15+
elif command -v sudo >& /dev/null; then
16+
sudo --non-interactive sh -c 'mkdir -p /workspaces/.tailscale ; /usr/local/sbin/tailscaled \
17+
--statedir=/workspaces/.tailscale/ \
18+
--socket=/var/run/tailscale/tailscaled.sock \
19+
--port=41641 >& /dev/null' &
20+
else
21+
echo "tailscaled could not start as root." 1>&2
22+
fi
23+
24+
exec "$@"

tailscaled

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)