diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-02-23 16:20:57 -0500 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-02-23 16:20:57 -0500 |
| commit | 9afc37eaed75ad4cf60302be8494303bb4db3fcc (patch) | |
| tree | 3dbd6a596d6f4f457e32cefaf7e6974e4e662bf6 | |
| parent | 5be5a8fd26bf2318201652872a42e68618f87510 (diff) | |
| download | x-9afc37eaed75ad4cf60302be8494303bb4db3fcc.tar.xz x-9afc37eaed75ad4cf60302be8494303bb4db3fcc.zip | |
bring back portable services
Signed-off-by: Xe Iaso <me@xeiaso.net>
| -rw-r--r-- | cmd/xedn/build.go | 2 | ||||
| -rw-r--r-- | cmd/xedn/doc/README.md | 28 | ||||
| -rw-r--r-- | cmd/xedn/main.go | 4 | ||||
| -rw-r--r-- | flake.lock | 18 | ||||
| -rw-r--r-- | flake.nix | 69 | ||||
| -rw-r--r-- | mastodon/robocadey2/build.go | 2 | ||||
| -rw-r--r-- | run/robocadey-gpt2.service.in | 10 | ||||
| -rw-r--r-- | run/robocadey-gpt2.socket | 9 | ||||
| -rw-r--r-- | run/robocadey.preflight.sh | 11 | ||||
| -rw-r--r-- | run/robocadey.service.in | 11 | ||||
| -rw-r--r-- | run/xedn.service.in | 14 |
11 files changed, 100 insertions, 78 deletions
diff --git a/cmd/xedn/build.go b/cmd/xedn/build.go index ded63d7..11aea9b 100644 --- a/cmd/xedn/build.go +++ b/cmd/xedn/build.go @@ -18,7 +18,7 @@ func main() { defer cancel() env := append(os.Environ(), []string{"CGO_ENABLED=0", "GOOS=linux"}...) - yeet.ShouldWork(ctx, env, yeet.WD, "nix", "build", ".#xedn-docker") + yeet.ShouldWork(ctx, env, yeet.WD, "nix", "build", ".#docker.xedn") yeet.DockerLoadResult(ctx, "./result") yeet.DockerPush(ctx, "registry.fly.io/xedn:latest") yeet.ShouldWork(ctx, env, yeet.WD, "flyctl", "deploy", "--now") diff --git a/cmd/xedn/doc/README.md b/cmd/xedn/doc/README.md new file mode 100644 index 0000000..0524702 --- /dev/null +++ b/cmd/xedn/doc/README.md @@ -0,0 +1,28 @@ +# XeDN + +Xe's CDN replacement service + +## Goal + +XeDN is a CDN replacement service. It is a tool that enables you to +serve files from a central storage pool (such as Backblaze B2) in a +way that caches all those files locally. This lets you put several +instances of XeDN in different datacentres globally and then each +instance will act as a local cache. This strategy lets you decrease +observable latency for users. + +The goal of this service is to replace Cloudflare for my own uses. + +## Design + +At a high level, XeDN is a caching HTTP proxy. It caches files locally +using [BoltDB](https://github.com/etcd-io/bbolt) and serves from that +cache whenever possible. XeDN pulls files from its source (currently +over HTTP, but this can be changed in the future) and aggressively +caches them in the database. When each file is cached, it has a +default lifetime of one week. This lifetime is extended every time a +file is requested, hopefully making sure that each file that is +commonly used is never requested from backend servers. This does make +genuinely updating content hard, so users of XeDN are encouraged to +assume that the backend is an _append-only_ store. + diff --git a/cmd/xedn/main.go b/cmd/xedn/main.go index 377c904..7044060 100644 --- a/cmd/xedn/main.go +++ b/cmd/xedn/main.go @@ -130,14 +130,14 @@ func (dc *Cache) Save(dir string, resp *http.Response) error { return err } - diesAt := time.Now().Add(604800 * time.Second).Format(http.TimeFormat) + diesAt := time.Now().AddDate(0, 0, 7).Format(http.TimeFormat) if err := bkt.Put([]byte("diesAt"), []byte(diesAt)); err != nil { return err } // cache control headers - resp.Header.Set("Cache-Control", "max-age:604800") + resp.Header.Set("Cache-Control", "max-age:604800") // one week resp.Header.Set("Expires", diesAt) return nil @@ -45,11 +45,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1675942811, - "narHash": "sha256-/v4Z9mJmADTpXrdIlAjFa1e+gkpIIROR670UVDQFwIw=", + "lastModified": 1676569297, + "narHash": "sha256-2n4C4H3/U+3YbDrQB6xIw7AaLdFISCCFwOkcETAigqU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "724bfc0892363087709bd3a5a1666296759154b1", + "rev": "ac1f5b72a9e95873d1de0233fddcb56f99884b37", "type": "github" }, "original": { @@ -77,11 +77,11 @@ ] }, "locked": { - "lastModified": 1676082367, - "narHash": "sha256-0eO3S+2gLODqDoloufeC99PfQ5mthuN9JADzqFXid1Y=", + "lastModified": 1676687290, + "narHash": "sha256-DP0CJ7qtUXf+mmMglJL1yANizzV1O4UfQ9NrKgy7O04=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1373567ffd13719f6b7522737b010bfc514d49b4", + "rev": "bdccd5e973d45159f7d13f7c65a4271dc02cf6d4", "type": "github" }, "original": { @@ -92,11 +92,11 @@ }, "utils": { "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", "type": "github" }, "original": { @@ -41,9 +41,9 @@ }; rust = pkgs.rust-bin.stable.latest.default.override { - extensions = [ "rust-src" ]; - targets = [ "wasm32-wasi" ]; - }; + extensions = [ "rust-src" ]; + targets = [ "wasm32-wasi" ]; + }; naersk' = pkgs.callPackage naersk { cargo = rust; @@ -71,11 +71,7 @@ modules = ./gomod2nix.toml; subPackages = [ "cmd/xedn" ]; - buildInputs = with pkgs; [ - pkg-config - libaom - libavif - ]; + buildInputs = with pkgs; [ pkg-config libaom libavif ]; }; robocadey2 = pkgs.buildGoApplication { @@ -109,7 +105,7 @@ mastosan-wasm = naersk'.buildPackage { src = ./web/mastosan; - targets = ["wasm32-wasi"]; + targets = [ "wasm32-wasi" ]; }; license = copyFile { @@ -134,24 +130,49 @@ uploud = copyFile { pname = "uploud"; }; whoisfront = copyFile { pname = "whoisfront"; }; within-website = copyFile { pname = "within.website"; }; + }; - robocadey2-docker = pkgs.dockerTools.buildLayeredImage { - name = "registry.fly.io/xe-robocadey2"; - tag = "latest"; - contents = [ pkgs.cacert ]; - config = { - Cmd = [ "${robocadey2}/bin/robocadey2" ]; - WorkingDir = "${robocadey2}"; + legacyPackages = { + docker = let + robocadey2 = self.packages.${system}.robocadey2; + xedn = self.packages.${system}.xedn; + in { + robocadey2 = pkgs.dockerTools.buildLayeredImage { + name = "registry.fly.io/xe-robocadey2"; + tag = "latest"; + contents = [ pkgs.cacert ]; + config = { + Cmd = [ "${robocadey2}/bin/robocadey2" ]; + WorkingDir = "${robocadey2}"; + }; + }; + xedn = pkgs.dockerTools.buildLayeredImage { + name = "registry.fly.io/xedn"; + tag = "latest"; + contents = [ pkgs.cacert ]; + config = { + Cmd = [ "${xedn}/bin/xedn" ]; + WorkingDir = "${xedn}"; + }; }; }; - - xedn-docker = pkgs.dockerTools.buildLayeredImage { - name = "registry.fly.io/xedn"; - tag = "latest"; - contents = [ pkgs.cacert ]; - config = { - Cmd = [ "${xedn}/bin/xedn" ]; - WorkingDir = "${xedn}"; + portable = { + xedn = let + service = pkgs.substituteAll { + name = "xedn.service"; + src = ./run/xedn.service.in; + xedn = self.packages.${system}.xedn; + }; + in pkgs.portableService { + inherit (self.packages.${system}.xedn) version; + pname = "xedn"; + description = "Xe's CDN service"; + homepage = "https://xeiaso.net"; + units = [ service ]; + symlinks = [{ + object = "${pkgs.cacert}/etc/ssl"; + symlink = "/etc/ssl"; + }]; }; }; }; diff --git a/mastodon/robocadey2/build.go b/mastodon/robocadey2/build.go index 3310bd4..752f354 100644 --- a/mastodon/robocadey2/build.go +++ b/mastodon/robocadey2/build.go @@ -18,7 +18,7 @@ func main() { defer cancel() env := append(os.Environ(), []string{"CGO_ENABLED=0", "GOOS=linux"}...) - yeet.ShouldWork(ctx, env, yeet.WD, "nix", "build", ".#robocadey2-docker") + yeet.ShouldWork(ctx, env, yeet.WD, "nix", "build", ".#docker.robocadey2") yeet.DockerLoadResult(ctx, "./result") yeet.DockerPush(ctx, "registry.fly.io/xe-robocadey2:latest") yeet.ShouldWork(ctx, env, yeet.WD, "flyctl", "deploy", "--now") diff --git a/run/robocadey-gpt2.service.in b/run/robocadey-gpt2.service.in deleted file mode 100644 index 988119a..0000000 --- a/run/robocadey-gpt2.service.in +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Robo-Cadey GPT2 sidecar - -[Service] -ExecStart=@python@/bin/python3 @main@ -StateDirectory=xeserv.robocadey-gpt2 -CacheDirectory=xeserv.robocadey-gpt2 - -[Install] -WantedBy=multi-user.target diff --git a/run/robocadey-gpt2.socket b/run/robocadey-gpt2.socket deleted file mode 100644 index f720f27..0000000 --- a/run/robocadey-gpt2.socket +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=RoboCadey activation socket -PartOf=robocadey-gpt2.service - -[Socket] -ListenStream=/run/robocadey-gpt2.sock - -[Install] -WantedBy=sockets.target
\ No newline at end of file diff --git a/run/robocadey.preflight.sh b/run/robocadey.preflight.sh deleted file mode 100644 index 04be027..0000000 --- a/run/robocadey.preflight.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -sed 's/window.YTD.tweet.part0 = //' < tweets.js \ - | jq '.[] | [ select(.tweet.retweeted == false) ] | .[].tweet.full_text' \ - | sed -r 's/\s*\.?@[A-Za-z0-9_]+\s*//g' \ - | grep -v 'RT:' \ - | jq --slurp . \ - | jq -r .[] \ - | sed -e 's!http[s]\?://\S*!!g' \ - | sed '/^$/d' \ - > tweets.txt diff --git a/run/robocadey.service.in b/run/robocadey.service.in deleted file mode 100644 index 77327b9..0000000 --- a/run/robocadey.service.in +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Robo-Cadey - -[Service] -ExecStartPre=@robocadey@/bin/robocadey --read-from=./robocadey.gob -ExecStart=@robocadey@/bin/robocadey -StateDirectory=xeserv.robocadey -CacheDirectory=xeserv.robocadey - -[Install] -WantedBy=multi-user.target diff --git a/run/xedn.service.in b/run/xedn.service.in new file mode 100644 index 0000000..db41598 --- /dev/null +++ b/run/xedn.service.in @@ -0,0 +1,14 @@ +[Unit] +Description=XeDN +Documentation=https://cdn.xeiaso.net + +[Service] +DynamicUser=yes +StateDirectory=xedn +Environment=XEDN_STATE=/var/lib/private/xedn +ExecStart=@xedn@/bin/xedn +Restart=always +RestartSec=30s + +[Install] +WantedBy=multi-user.target |
