|
2 | 2 |
|
3 | 3 | [](https://tailscale.com/kb/1167/release-stages/#experimental)
|
4 | 4 |
|
5 |
| -golink is a private shortlink service for your [tailnet]. It lets you create |
6 |
| -short, memorable links for the websites you and your team use most. |
| 5 | +golink is a private shortlink service for your [tailnet]. |
| 6 | +It lets you create short, memorable links for the websites you and your team use most. |
7 | 7 |
|
8 | 8 | [tailnet]: https://tailscale.com/kb/1136/tailnet/
|
9 | 9 |
|
10 | 10 | 
|
| 11 | + |
| 12 | +## Building and running |
| 13 | + |
| 14 | +To build from source and run in dev mode: |
| 15 | + |
| 16 | + go run ./cmd/golink -dev-listen :8080 |
| 17 | + |
| 18 | +golink will be available at http://localhost:8080/, |
| 19 | +storing links in a temporary database, and will not attempt to join a tailnet. |
| 20 | + |
| 21 | +The equivalent using the pre-built docker image: |
| 22 | + |
| 23 | + docker run -it --rm -p 8080:8080 -v /tmp/golink:/root ghcr.io/tailscale/golink:main -dev-listen :8080 |
| 24 | + |
| 25 | +## Joining a tailnet |
| 26 | + |
| 27 | +Create an [auth key] for your tailnet at <https://login.tailscale.com/admin/settings/keys>. |
| 28 | +Configure the auth key to your preferences, but at a minimum we generally recommend: |
| 29 | + |
| 30 | + - add a [tag] (maybe something like `tag:golink`) to make it easier to set ACLs for controlling access and to ensure the node doesn't expires. |
| 31 | + - don't set "ephemeral" so the node isn't removed if it goes offline |
| 32 | + |
| 33 | +Once you have a key, set it as the `TS_AUTHKEY` environment variable when starting golink. |
| 34 | +You will also need to specify your sqlite database file: |
| 35 | + |
| 36 | + TS_AUTHKEY="tskey-auth-<key>" go run ./cmd/golink -sqlitedb golink.db |
| 37 | + |
| 38 | +golink stores its tailscale data files in a `tsnet-golink` directory inside [os.UserConfigDir]. |
| 39 | +As long as this is on a persistent volume, the auth key only needs to be provided on first run. |
| 40 | + |
| 41 | +[auth-key]: https://tailscale.com/kb/1085/auth-keys/ |
| 42 | +[tag]: https://tailscale.com/kb/1068/acl-tags/ |
| 43 | +[os.UserConfigDir]: https://pkg.go.dev/os#UserConfigDir |
| 44 | + |
| 45 | +## MagicDNS |
| 46 | + |
| 47 | +When golink joins your tailnet, it will attempt to use "go" as its node name, |
| 48 | +and will be available at http://go.tailnet0000.ts.net/ (or whatever your tailnet name is). |
| 49 | +To make it accessible simply as http://go/, enable [MagicDNS] for your tailnet. |
| 50 | +With MagicDNS enabled, no special configuration or browser extensions are needed on client devices. |
| 51 | +Users just need to have Tailscale installed and connected to the tailnet. |
| 52 | + |
| 53 | +[MagicDNS]: https://tailscale.com/kb/1081/magicdns/ |
| 54 | + |
| 55 | +## Running in production |
| 56 | + |
| 57 | +golink compiles as a single static binary (including the frontend) and can be deployed and run like any other binary. |
| 58 | +Two pieces of data should be on persistent volumes: |
| 59 | + |
| 60 | + - tailscale data files in the `tsnet-golink` directory inside [os.UserConfigDir] |
| 61 | + - the sqlite database file where links are stored |
| 62 | + |
| 63 | +In the docker image, both are stored in `/root`, so you can mount a persistent volume at /root: |
| 64 | + |
| 65 | + docker run -v /persistant/data:/root ghcr.io/tailscale/golink:main |
| 66 | + |
| 67 | +No ports need to be exposed, whether running as a binary or in docker. |
| 68 | +golink will listen on port 80 on the tailscale interface, so can be accessed at http://go/. |
| 69 | + |
| 70 | +<details> |
| 71 | + <summary>Deploy on Fly</summary> |
| 72 | + |
| 73 | + See <https://fly.io/docs/> for full instructions for deploying apps on Fly, but this should give you a good start. |
| 74 | + Replace `FLY_APP_NAME` and `FLY_VOLUME_NAME` with your app and volume names. |
| 75 | + |
| 76 | + Create a [fly.toml](https://fly.io/docs/reference/configuration/) file: |
| 77 | + |
| 78 | + ``` toml |
| 79 | +app = "FLY_APP_NAME" |
| 80 | + |
| 81 | +[build] |
| 82 | +image = "ghcr.io/tailscale/golink:main" |
| 83 | + |
| 84 | +[deploy] |
| 85 | +strategy = "immediate" |
| 86 | + |
| 87 | +[mounts] |
| 88 | +source="FLY_VOLUME_NAME" |
| 89 | +destination="/root" |
| 90 | +``` |
| 91 | + |
| 92 | + Then run the commands with the [flyctl CLI]. |
| 93 | + |
| 94 | + ``` sh |
| 95 | + $ flyctl create app FLY_APP_NAME |
| 96 | + $ flyctl volumes create FLY_VOLUME_NAME |
| 97 | + $ flyctl secrets create TS_AUTHKEY=tskey-auth-<key> |
| 98 | + $ flyctl deploy |
| 99 | + ``` |
| 100 | + |
| 101 | +[flyctl CLI]: https://fly.io/docs/hands-on/install-flyctl/ |
| 102 | + |
| 103 | +</details> |
| 104 | + |
| 105 | +## Backups |
| 106 | + |
| 107 | +Once you have golink running, you can backup all of your links in [JSON lines] format from <http://go/.export>. |
| 108 | +At Tailscale, we snapshot our links weekly and store them in git. |
| 109 | + |
| 110 | +To restore links, specify the snapshot file on startup. |
| 111 | +Only links that don't already exist in the database will be added. |
| 112 | + |
| 113 | + golink -snapshot links.json |
| 114 | + |
| 115 | +[JSON lines]: https://jsonlines.org/ |
0 commit comments