albatros/hcl/nixcache/builder.hcl

163 lines
3 KiB
HCL
Raw Normal View History

2023-03-15 08:21:42 +00:00
job "builder" {
namespace = "ci"
type = "batch"
2023-03-24 14:53:14 +00:00
datacenters = ["neptune"]
2023-03-15 08:21:42 +00:00
priority = 100
parameterized {
2023-03-15 09:28:09 +00:00
payload = "optional"
2023-03-15 09:16:49 +00:00
meta_required = [ "REPO_URL", "COMMIT", "BRANCH", "FLAVOR" ]
2023-03-15 08:21:42 +00:00
}
reschedule {
attempts = 0
unlimited = false
}
2023-03-22 15:21:15 +00:00
constraint {
distinct_hosts = true
}
2023-03-22 15:24:45 +00:00
group "runner" {
2023-03-22 15:21:15 +00:00
task "warmup-cache" {
driver = "docker"
config {
image = "nixpkgs/nix:nixos-22.11"
args = [ "/tmp/warmup.sh" ]
volumes = [
"local/warmup.sh:/tmp/warmup.sh",
"/var/cache/albatros/nix:/mnt/nix"
]
}
lifecycle {
hook = "prestart"
sidecar = false
}
template {
2023-03-24 13:35:43 +00:00
data = file("./warmup.sh")
2023-03-22 15:21:15 +00:00
destination = "local/warmup.sh"
perms = "555"
}
}
2023-03-22 15:24:45 +00:00
task "executor" {
2023-03-15 08:21:42 +00:00
driver = "docker"
leader = true
2023-03-15 08:21:42 +00:00
config {
image = "nixpkgs/nix:nixos-22.11"
args = [ "/tmp/builder.sh" ]
volumes = [
"local/builder.sh:/tmp/builder.sh",
2023-03-15 09:28:09 +00:00
"local/nix.conf:/etc/nix/nix.conf",
2023-03-16 11:50:06 +00:00
"local/secrets:/var/run/secrets/albatros",
2023-03-24 13:35:43 +00:00
"/var/cache/albatros/nix:/nix:ro",
"/var/cache/albatros/cacheroot:/mnt/cacheroot"
2023-03-15 08:21:42 +00:00
]
}
2023-03-15 09:28:09 +00:00
dispatch_payload {
2023-03-16 11:50:06 +00:00
file = "secrets/secret.txt"
2023-03-15 09:28:09 +00:00
}
2023-03-22 15:21:15 +00:00
env {
COMMIT = "${NOMAD_META_COMMIT}"
BRANCH = "${NOMAD_META_BRANCH}"
REPO_URL = "${NOMAD_META_REPO_URL}"
FLAVOR = "${NOMAD_META_FLAVOR}"
2023-03-24 13:35:43 +00:00
GCROOT = "/mnt/cacheroot/${NOMAD_META_COMMIT}"
2023-03-22 15:21:15 +00:00
NIX_REMOTE = "daemon"
}
2023-03-15 08:21:42 +00:00
template {
2023-03-24 13:35:43 +00:00
data = file("./user.sh")
2023-03-15 08:21:42 +00:00
destination = "local/builder.sh"
perms = "555"
}
template {
2023-03-24 13:35:43 +00:00
data = file("./nix.conf")
2023-03-15 08:21:42 +00:00
destination = "local/nix.conf"
}
restart {
attempts = 0
}
2023-03-22 15:21:15 +00:00
resources {
# actual work should be done in the nix daemon
cpu = 100
memory = 500
}
}
task "daemon" {
driver = "docker"
config {
image = "nixpkgs/nix:nixos-22.11"
command = "nix-daemon"
volumes = [
2023-03-24 13:35:43 +00:00
"/var/cache/albatros/nix:/nix",
2023-03-24 14:58:28 +00:00
"local/nix.conf:/etc/nix/nix.conf",
2023-03-24 13:35:43 +00:00
"local/pin.sh:/usr/local/bin/pin.sh"
2023-03-22 15:21:15 +00:00
]
}
template {
2023-03-24 13:35:43 +00:00
data = file("./nix.conf")
2023-03-22 15:21:15 +00:00
destination = "local/nix.conf"
}
2023-03-24 13:35:43 +00:00
template {
data = file("./pin.sh")
destination = "local/pin.sh"
perms = "555"
}
2023-03-22 15:21:15 +00:00
restart {
attempts = 0
}
2023-03-15 08:21:42 +00:00
resources {
cpu = 1000
memory = 4000
}
2023-03-22 15:21:15 +00:00
}
2023-03-24 15:46:31 +00:00
task "garbage-collect-cache" {
driver = "docker"
config {
image = "nixpkgs/nix:nixos-22.11"
args = [ "/tmp/gc.sh" ]
volumes = [
"local/gc.sh:/tmp/gc.sh",
"local/nix.conf:/etc/nix/nix.conf",
"/var/cache/albatros/nix:/nix",
]
}
lifecycle {
hook = "poststop"
sidecar = false
}
template {
data = file("./nix.conf")
destination = "local/nix.conf"
}
template {
data = file("./gc.sh")
destination = "local/gc.sh"
perms = "555"
}
restart {
attempts = 0
}
}
2023-03-15 08:21:42 +00:00
}
}