Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
096908ac39 | ||
|
|
cbfdc8c4f2 |
@@ -19,18 +19,17 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: pick reporter
|
|
||||||
run: |
|
|
||||||
if [ "${{ github.event_name }}" = pull_request ]; then
|
|
||||||
echo "REPORTER=gitea-pr-review" >> "$GITHUB_ENV"
|
|
||||||
else
|
|
||||||
echo "REPORTER=local" >> "$GITHUB_ENV"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: run linters
|
- name: run linters
|
||||||
run: nix run -L .#ci -- lint . "$RUNNER_TEMP/findings"
|
run: nix run -L .#ci -- lint . "$RUNNER_TEMP/findings"
|
||||||
|
|
||||||
- name: report findings
|
- name: report findings
|
||||||
|
if: always()
|
||||||
env:
|
env:
|
||||||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
REVIEWDOG_GITEA_API_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
run: nix run -L .#ci -- lint-report "$REPORTER" "$RUNNER_TEMP/findings"
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = pull_request ]; then
|
||||||
|
nix run -L .#ci -- lint-report gitea-pr-review "$RUNNER_TEMP/findings"
|
||||||
|
else
|
||||||
|
nix run -L .#ci -- lint-summary "$RUNNER_TEMP/findings" \
|
||||||
|
| tee -a "$GITHUB_STEP_SUMMARY"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# runner's own nix, not a pinned one).
|
# runner's own nix, not a pinned one).
|
||||||
pkgs.writers.writePython3Bin "ci" {
|
pkgs.writers.writePython3Bin "ci" {
|
||||||
flakeIgnore = [ "E501" ];
|
flakeIgnore = [ "E501" ];
|
||||||
|
libraries = [ pkgs.python3Packages.subprocess-tee ];
|
||||||
makeWrapperArgs = [
|
makeWrapperArgs = [
|
||||||
"--prefix"
|
"--prefix"
|
||||||
"PATH"
|
"PATH"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import subprocess_tee
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
@@ -17,7 +18,7 @@ def run(*args, **kw):
|
|||||||
|
|
||||||
|
|
||||||
def nix(*args):
|
def nix(*args):
|
||||||
return run("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args, check=True, stdout=subprocess.PIPE).stdout
|
return subprocess_tee.run(("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args), check=True, text=True).stdout
|
||||||
|
|
||||||
|
|
||||||
def git(*args, check=True):
|
def git(*args, check=True):
|
||||||
@@ -362,10 +363,63 @@ def lint_report(args):
|
|||||||
|
|
||||||
codes = [reviewdog(f"{args.dir}/{name}", flags)
|
codes = [reviewdog(f"{args.dir}/{name}", flags)
|
||||||
for name, flags in LINTERS
|
for name, flags in LINTERS
|
||||||
if os.path.getsize(f"{args.dir}/{name}") > 0]
|
if os.path.isfile(f"{args.dir}/{name}") and os.path.getsize(f"{args.dir}/{name}") > 0]
|
||||||
sys.exit(1 if any(codes) else 0)
|
sys.exit(1 if any(codes) else 0)
|
||||||
|
|
||||||
|
|
||||||
|
def has_findings(path):
|
||||||
|
return os.path.isfile(path) and os.path.getsize(path) > 0
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_rdjsonl(path):
|
||||||
|
lines = []
|
||||||
|
with open(path) as f:
|
||||||
|
for raw in f:
|
||||||
|
rec = json.loads(raw)
|
||||||
|
loc = rec["location"]
|
||||||
|
r = loc.get("range", {}).get("start")
|
||||||
|
pos = f"{loc['path']}:{r['line']}:{r['column']}" if r else loc["path"]
|
||||||
|
lines.append(f"- `{pos}`: {rec['message']}")
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_errfmt(path):
|
||||||
|
lines = []
|
||||||
|
with open(path) as f:
|
||||||
|
for raw in f:
|
||||||
|
parts = raw.strip().split(">", 1)
|
||||||
|
if len(parts) == 2:
|
||||||
|
lines.append(f"- `{parts[0]}:{parts[1].split(':', 3)[-1].strip()}`" if ":" in parts[1] else f"- `{raw.strip()}`")
|
||||||
|
elif raw.strip():
|
||||||
|
lines.append(f"- `{raw.strip()}`")
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def lint_summary(args):
|
||||||
|
sections = []
|
||||||
|
d = args.dir
|
||||||
|
|
||||||
|
if has_findings(f"{d}/nixfmt.diff"):
|
||||||
|
with open(f"{d}/nixfmt.diff") as f:
|
||||||
|
sections.append(f"## nixfmt\n\n```diff\n{f.read().rstrip()}\n```")
|
||||||
|
|
||||||
|
if has_findings(f"{d}/statix.errfmt"):
|
||||||
|
sections.append(f"## statix\n\n{fmt_errfmt(f'{d}/statix.errfmt')}")
|
||||||
|
|
||||||
|
if has_findings(f"{d}/deadnix.rdjsonl"):
|
||||||
|
sections.append(f"## deadnix\n\n{fmt_rdjsonl(f'{d}/deadnix.rdjsonl')}")
|
||||||
|
|
||||||
|
if has_findings(f"{d}/cycles.rdjsonl"):
|
||||||
|
sections.append(f"## systemd ordering cycles\n\n{fmt_rdjsonl(f'{d}/cycles.rdjsonl')}")
|
||||||
|
|
||||||
|
if sections:
|
||||||
|
print("\n\n".join(["# Lint findings"] + sections))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("No lint findings.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def post_comment(args):
|
def post_comment(args):
|
||||||
body = args.marker + "\n" + Path(args.body_file).read_text()
|
body = args.marker + "\n" + Path(args.body_file).read_text()
|
||||||
pr = os.environ["PR"]
|
pr = os.environ["PR"]
|
||||||
@@ -438,6 +492,7 @@ def main():
|
|||||||
command("vulnix", vulnix, "ref", "body_out")
|
command("vulnix", vulnix, "ref", "body_out")
|
||||||
command("lint", lint, "target", "out")
|
command("lint", lint, "target", "out")
|
||||||
command("lint-report", lint_report, "reporter", "dir")
|
command("lint-report", lint_report, "reporter", "dir")
|
||||||
|
command("lint-summary", lint_summary, "dir")
|
||||||
command("post-comment", post_comment, "marker", "body_file")
|
command("post-comment", post_comment, "marker", "body_file")
|
||||||
command("upsert-issue", upsert_issue, "label", "title", "body_file")
|
command("upsert-issue", upsert_issue, "label", "title", "body_file")
|
||||||
command("close-issue", close_issue, "label")
|
command("close-issue", close_issue, "label")
|
||||||
|
|||||||
@@ -381,6 +381,6 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
hostAddr = c.hostAddr;
|
inherit (c) hostAddr;
|
||||||
in
|
in
|
||||||
c
|
c
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ in
|
|||||||
net.expose.tcp = [ 3000 ];
|
net.expose.tcp = [ 3000 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
ci-runner = mkVm {
|
ci-runner =
|
||||||
|
mkVm {
|
||||||
name = "ci-runner";
|
name = "ci-runner";
|
||||||
includedInTests = false;
|
includedInTests = false;
|
||||||
net.access = [
|
net.access = [
|
||||||
@@ -75,6 +76,12 @@ in
|
|||||||
source = "${ciRunnerData}/nix-rw-store";
|
source = "${ciRunnerData}/nix-rw-store";
|
||||||
mountPoint = "/nix/.rw-store";
|
mountPoint = "/nix/.rw-store";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
proto = "virtiofs";
|
||||||
|
tag = "nix-db";
|
||||||
|
source = "${ciRunnerData}/nix-db";
|
||||||
|
mountPoint = "/nix/var/nix/db";
|
||||||
|
}
|
||||||
{
|
{
|
||||||
proto = "virtiofs";
|
proto = "virtiofs";
|
||||||
tag = "docker-data";
|
tag = "docker-data";
|
||||||
@@ -152,6 +159,8 @@ in
|
|||||||
"flakes"
|
"flakes"
|
||||||
];
|
];
|
||||||
max-jobs = "auto";
|
max-jobs = "auto";
|
||||||
|
substituters = [ "https://microvm.cachix.org" ];
|
||||||
|
trusted-public-keys = [ "microvm.cachix.org-1:oXnBc6hRE3eX5rSYdRyMYXnfzcCxC7yKPTbZXALsqys=" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
nix.gc = {
|
nix.gc = {
|
||||||
@@ -161,13 +170,23 @@ in
|
|||||||
};
|
};
|
||||||
# nix.optimise.automatic = true; - doesn't work with microvm.writableStoreOverlay
|
# nix.optimise.automatic = true; - doesn't work with microvm.writableStoreOverlay
|
||||||
|
|
||||||
|
services.openssh = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
PermitRootLogin = "yes";
|
||||||
|
PermitEmptyPasswords = "yes";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
users.users.root.initialHashedPassword = "";
|
||||||
services.journald.extraConfig = "ForwardToConsole=yes";
|
services.journald.extraConfig = "ForwardToConsole=yes";
|
||||||
|
|
||||||
virtualisation.containerd.enable = true;
|
virtualisation.containerd.enable = true;
|
||||||
virtualisation.containerd.settings.plugins."io.containerd.snapshotter.v1.overlayfs".mount_options = [ "userxattr" ];
|
virtualisation.containerd.settings.plugins."io.containerd.snapshotter.v1.overlayfs".mount_options =
|
||||||
|
[ "userxattr" ];
|
||||||
|
|
||||||
virtualisation.docker.enable = true;
|
virtualisation.docker.enable = true;
|
||||||
virtualisation.docker.extraOptions = "--containerd /run/containerd/containerd.sock";
|
virtualisation.docker.extraOptions = "--containerd /run/containerd/containerd.sock";
|
||||||
|
virtualisation.docker.daemon.settings.exec-opts = [ "native.cgroupdriver=cgroupfs" ];
|
||||||
systemd.services.docker.wants = [ "containerd.service" ];
|
systemd.services.docker.wants = [ "containerd.service" ];
|
||||||
systemd.services.docker.after = [ "containerd.service" ];
|
systemd.services.docker.after = [ "containerd.service" ];
|
||||||
|
|
||||||
@@ -201,5 +220,15 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
// {
|
||||||
|
hostConfig = {
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d ${ciRunnerData}/nix-rw-store 0755 server server -"
|
||||||
|
"d ${ciRunnerData}/nix-db 0755 server server -"
|
||||||
|
"d ${ciRunnerData}/docker 0755 server server -"
|
||||||
|
"d ${ciRunnerData}/runner-state 0755 server server -"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,6 +210,6 @@ let
|
|||||||
};
|
};
|
||||||
inherit (setup) containerConfig;
|
inherit (setup) containerConfig;
|
||||||
};
|
};
|
||||||
hostAddr = c.hostAddr;
|
inherit (c) hostAddr;
|
||||||
in
|
in
|
||||||
c
|
c
|
||||||
|
|||||||
@@ -572,7 +572,10 @@ rec {
|
|||||||
Gateway = hostAddr;
|
Gateway = hostAddr;
|
||||||
};
|
};
|
||||||
networkConfig.DNS = [ hostAddr ];
|
networkConfig.DNS = [ hostAddr ];
|
||||||
networkConfig.Domains = [ "~." "containers" ];
|
networkConfig.Domains = [
|
||||||
|
"~."
|
||||||
|
"containers"
|
||||||
|
];
|
||||||
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
|
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
|
||||||
};
|
};
|
||||||
networking.enableIPv6 = false;
|
networking.enableIPv6 = false;
|
||||||
|
|||||||
@@ -129,11 +129,10 @@
|
|||||||
{
|
{
|
||||||
nixosConfigurations = lib.mapAttrs (_: host: host.hostCfg) allHosts;
|
nixosConfigurations = lib.mapAttrs (_: host: host.hostCfg) allHosts;
|
||||||
|
|
||||||
inspect = lib.mapAttrs
|
inspect = lib.mapAttrs (
|
||||||
(name: host:
|
name: host:
|
||||||
pkgs.writeText "inspect-${name}.json"
|
pkgs.writeText "inspect-${name}.json" (builtins.toJSON (introspect.hostReport { inherit host; }))
|
||||||
(builtins.toJSON (introspect.hostReport { inherit host; })))
|
) allHosts;
|
||||||
allHosts;
|
|
||||||
|
|
||||||
packages.${system} = customPkgs // {
|
packages.${system} = customPkgs // {
|
||||||
inherit ci;
|
inherit ci;
|
||||||
|
|||||||
@@ -205,12 +205,7 @@ with subtest("(isolation): edges are one-way"):
|
|||||||
server.fail(ct_connect("git", ADDR["nginx"], 443, timeout=2))
|
server.fail(ct_connect("git", ADDR["nginx"], 443, timeout=2))
|
||||||
|
|
||||||
with subtest("(isolation): host access allowlist"):
|
with subtest("(isolation): host access allowlist"):
|
||||||
server.succeed(
|
server.succeed(ct_connect("overseer", HOST_ADDR["overseer"], HOST_EXPORTER_PORT))
|
||||||
net_cmd(
|
|
||||||
"overseer",
|
|
||||||
f"{CURL} -sf --max-time 5 http://{HOST_ADDR['overseer']}:{HOST_EXPORTER_PORT}/metrics >&2",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for port in (HOST_EXPORTER_PORT, HOST_CADVISOR_PORT):
|
for port in (HOST_EXPORTER_PORT, HOST_CADVISOR_PORT):
|
||||||
server.fail(ct_connect("git", HOST_ADDR["git"], port, timeout=2))
|
server.fail(ct_connect("git", HOST_ADDR["git"], port, timeout=2))
|
||||||
server.fail(ct_connect("git", HOST_ADDR["overseer"], port, timeout=2))
|
server.fail(ct_connect("git", HOST_ADDR["overseer"], port, timeout=2))
|
||||||
|
|||||||
Reference in New Issue
Block a user