Compare commits

...

3 commits

4 changed files with 145 additions and 49 deletions

View file

@ -1,3 +1,4 @@
elizabeth-and-daylin.com {
reverse_proxy http://localhost:4321
}
@ -6,10 +7,6 @@ elizabeth.dayl.in, www.elizabeth-and-daylin.com {
redir https://elizabeth-and-daylin.com{uri} permanent
}
attic.dayl.in {
reverse_proxy http://localhost:5656
}
git.dayl.in {
reverse_proxy http://localhost:3000
}

View file

@ -0,0 +1,68 @@
<!doctype html>
<html>
<head>
<title>Attic Binary Cache</title>
<style>
.cursor {
display: inline-block;
background-color: black;
animation-name: cursor;
animation-duration: 0.8s;
animation-iteration-count: infinite;
}
@keyframes cursor {
0% {
background-color: #ffffff;
}
20% {
background-color: #555;
}
50% {
background-color: #555;
}
60% {
background-color: #ffffff;
}
100% {
background-color: #ffffff;
}
}
/* https://stackoverflow.com/a/13356401 */
body {
background-color: #1e1e2e;
}
pre {
color: #f5e0dc;
}
#box {
width: 100px;
height: 100px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box">
<pre>
┏━━━━━━━━━━━━━━━━┑
┃┏━━━ @ ━━━ @ ━━┓┃
┃┃ ┃┃
┃┃$ attic push <div class="cursor"> </div>┃┃
┃┃ ┃┃
┃┗━━━ ╰─────╯ ━━┛┃
┗━━━━━━━━━━━━━━━━┛
╲ ############### ╲
╲ ############### ╲
╲ ############### ╲
━━━━━━━━━━━━━━━━━━
</pre>
</div>
</body>
</html>

View file

@ -1,6 +1,10 @@
{ pkgs, enabled, ... }:
let
atticPort = "5656";
static = pkgs.runCommandLocal "static-files" { } ''
mkdir $out
cp ${./caddy/index.html} $out/index.html
'';
in
{
@ -15,12 +19,22 @@ in
settings.PasswordAuthentication = false;
};
services.comin = enabled // {
remotes = [
{
name = "origin";
url = "https://github.com/daylinmorgan/oizys.git";
branches.main.name = "main";
}
];
};
security.polkit = enabled; # attic was looking for this...
environment.systemPackages = [ pkgs.attic-client ];
# allow docker to forward the request to the host running attic
# https://discourse.nixos.org/t/docker-container-not-resolving-to-host/30259/6
networking.firewall.extraCommands = "iptables -A INPUT -p tcp --destination-port ${atticPort} -s 172.16.0.0/12 -j ACCEPT";
# networking.firewall.extraCommands = "iptables -A INPUT -p tcp --destination-port ${atticPort} -s 172.16.0.0/12 -j ACCEPT";
services.atticd = enabled // {
# Replace with absolute path to your credentials file
@ -56,17 +70,19 @@ in
};
};
services.comin = enabled // {
remotes = [
{
name = "origin";
url = "https://github.com/daylinmorgan/oizys.git";
branches.main.name = "main";
}
];
};
services.caddy = enabled // {
extraConfig = builtins.readFile ./Caddyfile;
extraConfig = builtins.readFile ./caddy/Caddyfile;
virtualHosts."attic.dayl.in".extraConfig = ''
redir /oizys /
handle / {
root * ${static}
file_server
}
handle /* {
reverse_proxy http://localhost:5656
}
'';
};
}

View file

@ -1,4 +1,4 @@
import std/[httpclient,logging, os, strformat, strutils, json, tables, tempfiles]
import std/[httpclient,logging, os, strformat, strutils, json, tables, tempfiles, times]
import jsony, hwylterm, hwylterm/logging, zippy/ziparchives
import ./[exec, context]
@ -12,6 +12,33 @@ template withTmpDir(body: untyped): untyped =
body
removeDir tmpDir
type
GhArtifact = object
id: int
name: string
url: string
archive_download_url*: string
GhWorkflowRun = object
id*: int
node_id: string
run_number: int
event: string
status: string
conclusion: string
html_url: string
workflow_id: int
created_at*: string # use datetime?
updated_at: string # use datetime?
ListGhArtifactResponse = object
total_count: int
artifacts: seq[GhArtifact]
ListGhWorkflowResponse = object
total_count: int
workflow_runs: seq[GhWorkflowRun]
var ghToken = getEnv "GITHUB_TOKEN"
proc checkToken() {.inline.} =
@ -52,47 +79,35 @@ proc postGhApi(url: string, body: JsonNode) =
except:
errorQuit "failed to get response code"
proc getInProgressRun(workflow: string, timeout: int = 5000): (GhWorkflowRun, bool) =
let
start = now()
timeoutDuration = initDuration(milliseconds = timeout)
withSpinner fmt"waiting for {workflow} workflow to start":
while (now() - start) < timeoutDuration:
let response = getGhApi(fmt"https://api.github.com/repos/daylinmorgan/oizys/actions/workflows/{workflow}/runs")
let runs = fromJson(response.body, ListGhWorkflowResponse).workflow_runs
if runs[0].status == "in_progress":
spinner.stop() # cleanup
return (runs[0], true)
sleep 500
warn "timeout reached waiting for workflow to start"
proc createDispatch*(workflowFileName: string, `ref`: string) =
## https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
var workflow =
let workflow =
if workflowFileName.endsWith(".yml") or workflowFileName.endsWith(".yaml"): workflowFileName
else: workflowFileName & ".yml"
let body = %*{"ref": `ref`}
info fmt"creating dispatch event for {workflow}"
postGhApi(
fmt"https://api.github.com/repos/daylinmorgan/oizys/actions/workflows/{workflow}/dispatches",
%*{
"ref": `ref`,
}
body
)
type
GhArtifact = object
id: int
name: string
url: string
archive_download_url*: string
GhWorkflowRun = object
id*: int
node_id: string
run_number: int
event: string
status: string
conclusion: string
html_url: string
workflow_id: int
created_at*: string # use datetime?
updated_at: string # use datetime?
ListGhArtifactResponse = object
total_count: int
artifacts: seq[GhArtifact]
ListGhWorkflowResponse = object
total_count: int
workflow_runs: seq[GhWorkflowRun]
let (run, ok) = getInProgressRun(workflow)
if ok: info "view workflow run at: " & run.html_url
proc listUpdateRuns(): seq[GhWorkflowRun] =
## get update.yml runs