Compare commits

...

8 Commits
v0.3.0 ... main

Author SHA1 Message Date
Cadey Ratio d8d3872837 bump version
Signed-off-by: Xe Iaso <me@xeiaso.net>
2023-07-19 07:38:52 -04:00
Cadey Ratio 122df4c117 bump nixpkgs
Signed-off-by: Xe Iaso <me@xeiaso.net>
2023-07-19 07:36:48 -04:00
Cadey Ratio 640a408099 add portable service docs
Signed-off-by: Xe <me@christine.website>
2022-04-22 00:44:06 +00:00
Cadey Ratio 8db9f00549 bump to 0.3.1, fix portable service
Signed-off-by: Xe <me@christine.website>
2022-04-22 00:31:04 +00:00
Cadey Ratio a367222014 portable service: add RUST_LOG
Signed-off-by: Xe <me@christine.website>
2022-03-03 22:34:10 +00:00
Cadey Ratio 2ec9f9e661 portable service: make workingdir the derivation
Signed-off-by: Xe <me@christine.website>
2022-03-03 22:21:27 +00:00
Cadey Ratio b92f7d216d add docker image to flake
Signed-off-by: Xe <me@christine.website>
2022-02-27 13:32:39 +00:00
Cadey Ratio c956022422 Delete 'scripts/release.sh' 2022-02-27 12:52:39 +00:00
9 changed files with 130 additions and 69 deletions

2
.envrc
View File

@ -1 +1 @@
use_nix
use flake

6
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler32"
version = "1.2.0"
@ -731,7 +733,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "printerfacts"
version = "0.3.0"
version = "0.3.2"
dependencies = [
"anyhow",
"hyper",
@ -739,7 +741,7 @@ dependencies = [
"mime",
"pfacts",
"prometheus",
"rand 0.8.3",
"rand 0.7.3",
"ructe",
"serde",
"tokio",

View File

@ -1,7 +1,7 @@
[package]
name = "printerfacts"
version = "0.3.0"
authors = ["Christine Dodrill <me@christine.website>"]
version = "0.3.2"
authors = ["Xe Iaso <me@christine.website>"]
edition = "2018"
build = "build.rs"
description = "Printer facts: The API"

59
doc/portable-svc.md Normal file
View File

@ -0,0 +1,59 @@
# Portable Service
To run this service as a [portable
service](https://systemd.io/PORTABLE_SERVICES/), you either need to build it
from source or fetch a premade image from my server. Then you need to activate
the portable service and manage it like any other systemd service.
## Getting Image
### Building From Source
To build from source, install Nix and enable flakes. Then run this command:
```
nix build "git+https://tulpa.dev/cadey/printerfacts.git?ref=main#portable-service"
```
Copy this to somewhere on your target server:
```
scp $(readlink ./result) target:printerfacts_0.3.1.raw
```
### Downloading From My Server
Visit [my portable services
repository](https://xena.greedo.xeserv.us/pkg/portable/) server and download the
most recent `printerfacts` `.raw` file. Put it somewhere on the target machine.
## Installing and Activating
If you are running Ubuntu 22.04, you will need to install `systemd-portabled`:
```
sudo apt -y install systemd-container
```
This may work on other distros, but I have only tested this on Ubuntu 22.04.
Then attach the service image:
```
sudo portablectl attach ./printerfacts_0.3.1.raw
```
And activate it like any other systemd service:
```
sudo systemctl enable --now printerfacts.service
```
And then fetch a printer fact:
```
$ curl http://[::1]:32042/fact
On average, a printer will sleep for 16 hours a day.
```
Or open it in your browser: http://target:32042

View File

@ -1,12 +1,15 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
@ -20,11 +23,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1639947939,
"narHash": "sha256-pGsM8haJadVP80GFq4xhnSpNitYNQpaXk4cnA796Cso=",
"lastModified": 1688534083,
"narHash": "sha256-/bI5vsioXscQTsx+Hk9X5HfweeNZz/6kVKsbdqfwW7g=",
"owner": "nix-community",
"repo": "naersk",
"rev": "2fc8ce9d3c025d59fee349c1f80be9785049d653",
"rev": "abca1fb7a6cfdd355231fc220c3d0302dbb4369a",
"type": "github"
},
"original": {
@ -35,11 +38,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1645866791,
"narHash": "sha256-okyN8nAb0gFfF2rjjJnMiIuOM+nZXxZ9Wc2PyoYYKWo=",
"lastModified": 1689631193,
"narHash": "sha256-AGSkBZaiTODQc8eT1rZDrQIjtb8JtFwJ0wVPzArlrnM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "607178a179d6943cb64970882511c24b2a983c2b",
"rev": "57695599bdc4f7bfe5d28cfa23f14b3d8bdf8a5f",
"type": "github"
},
"original": {
@ -49,11 +52,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1645866791,
"narHash": "sha256-okyN8nAb0gFfF2rjjJnMiIuOM+nZXxZ9Wc2PyoYYKWo=",
"lastModified": 1689631193,
"narHash": "sha256-AGSkBZaiTODQc8eT1rZDrQIjtb8JtFwJ0wVPzArlrnM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "607178a179d6943cb64970882511c24b2a983c2b",
"rev": "57695599bdc4f7bfe5d28cfa23f14b3d8bdf8a5f",
"type": "github"
},
"original": {
@ -63,11 +66,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1640319671,
"narHash": "sha256-ZkKmakwaOaLiZOpIZWbeJZwap5CzJ30s4UJTfydYIYc=",
"lastModified": 1678898370,
"narHash": "sha256-xTICr1j+uat5hk9FyuPOFGxpWHdJRibwZC+ATi0RbtE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "eac07edbd20ed4908b98790ba299250b5527ecdf",
"rev": "ac718d02867a84b42522a0ece52d841188208f2c",
"type": "github"
},
"original": {
@ -77,38 +80,36 @@
"type": "github"
}
},
"portable-svc": {
"locked": {
"lastModified": 1645960986,
"narHash": "sha256-XuapDz2dkUAgKaj3L2EUgzXApn6IXGtQVg/TEfhr0w8=",
"ref": "main",
"rev": "138c25c1c3ee4f7945059e05259d3fe03678e843",
"revCount": 5,
"type": "git",
"url": "https://tulpa.dev/cadey/portable-svc.git"
},
"original": {
"ref": "main",
"type": "git",
"url": "https://tulpa.dev/cadey/portable-svc.git"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs_2",
"portable-svc": "portable-svc",
"xess": "xess"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1638122382,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"lastModified": 1678901627,
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
"type": "github"
},
"original": {
@ -123,11 +124,11 @@
"utils": "utils"
},
"locked": {
"lastModified": 1640540322,
"narHash": "sha256-II4raADUWKTLDAALyJSToAgL8FB1ADbRHqEr/b3JeIc=",
"lastModified": 1682266158,
"narHash": "sha256-VK66KyF1doJ24yktb9rp7Yv7auS6i0P8EnJLhFOz+jY=",
"owner": "Xe",
"repo": "Xess",
"rev": "5fabc96de6487a721235c4bdf18214519d9e6201",
"rev": "3a85d1de06cd3420b4d56a8edd72cd57e6f0806e",
"type": "github"
},
"original": {

View File

@ -3,13 +3,14 @@
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
xess.url = "github:Xe/Xess";
portable-svc.url = "git+https://tulpa.dev/cadey/portable-svc.git?ref=main";
};
outputs = { self, nixpkgs, flake-utils, naersk, xess, portable-svc }:
outputs = { self, nixpkgs, flake-utils, naersk, xess }:
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
let
pkgs = import nixpkgs { overlays = [ portable-svc.overlay ]; inherit system; };
pkgs = import nixpkgs {
inherit system;
};
naersk-lib = naersk.lib."${system}";
src = ./.;
in rec {
@ -30,18 +31,32 @@
cp -rf $src/templates $out/templates
cp -rf ${printerfacts-bin}/bin $out/bin
cp -rf ${
xess.defaultPackage."${system}"
xess.packages."${system}".default
}/static/css/xess.css $out/static/gruvbox.css
'';
};
docker = let
printerfacts = self.packages.${system}.printerfacts;
name = "xena/printerfacts";
tag = printerfacts.version;
in pkgs.dockerTools.buildLayeredImage {
inherit name tag;
contents = [ printerfacts ];
config = {
Cmd = [ "${printerfacts}/bin/printerfacts" ];
Env = [ "RUST_LOG=info" "PORT=32042" ];
WorkingDir = "/";
};
};
printerfacts-service = pkgs.substituteAll {
name = "printerfacts.service";
pname = "printerfacts.service";
src = ./systemd/printerfacts.service.in;
printerfacts = self.packages.${system}.printerfacts;
};
portable-service = pkgs.portableService {
inherit (self.packages.${system}.printerfacts) version;
name = "printerfacts";
pname = "printerfacts";
description = "Printer facts";
units = [ self.packages.${system}.printerfacts-service ];
};
@ -54,12 +69,12 @@
defaultApp = apps.printerfacts;
# `nix develop`
devShell = pkgs.mkShell {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rustc
cargo
cargo-watch
rls
rust-analyzer
rustfmt
];

View File

@ -1,5 +0,0 @@
#!/usr/bin/env nix-shell
#! nix-shell -p doctl -p kubectl -i bash
doctl kubernetes cluster kubeconfig save kubermemes
dhall-to-yaml-ng < ./printerfacts.dhall | kubectl apply -n apps -f -
kubectl rollout status -n apps deployment/printerfacts

View File

@ -1,13 +0,0 @@
let
pkgs = import <nixpkgs> { };
in pkgs.mkShell {
buildInputs = with pkgs; [
rustc
cargo
cargo-watch
rls
rustfmt
];
RUST_LOG = "info";
}

View File

@ -4,6 +4,8 @@ Description=The Printerfacts service
[Service]
DynamicUser=yes
Environment=PORT=32042
Environment=RUST_LOG=info
WorkingDirectory=@printerfacts@
ExecStart=@printerfacts@/bin/printerfacts
[Install]