2021-12-11 17:53:01 +00:00
|
|
|
local ci = import '.drone/ci.libsonnet';
|
2021-12-09 15:34:37 +00:00
|
|
|
|
2021-12-10 04:03:53 +00:00
|
|
|
local guix_pipeline(name) = ci.pipeline.new()
|
2021-12-09 15:34:37 +00:00
|
|
|
.withName(name)
|
|
|
|
.withType("docker")
|
|
|
|
.withNode({ "guix": "on"});
|
|
|
|
|
|
|
|
local guix_step(name,
|
|
|
|
commands,
|
|
|
|
image="docker.nexus.home.rekahsoft.ca/guix:latest") =
|
2021-12-10 04:03:53 +00:00
|
|
|
ci.pipeline.step.new(name, image).withPullIfNotExists().withCommands(commands);
|
2021-12-09 15:34:37 +00:00
|
|
|
|
|
|
|
local guix_step_time_machine(name,
|
|
|
|
commands,
|
|
|
|
cwd=".",
|
|
|
|
channels="channels.scm",
|
|
|
|
image="docker.nexus.home.rekahsoft.ca/guix:latest") =
|
2021-12-10 04:03:53 +00:00
|
|
|
ci.pipeline.step.new(name, image).withPullIfNotExists().withCommands(
|
2021-12-09 16:59:51 +00:00
|
|
|
// Conditionally change directory
|
2021-12-09 15:34:37 +00:00
|
|
|
(if cwd == "."
|
|
|
|
then [] else [std.format("cd %s", cwd)]) +
|
2021-12-09 16:59:51 +00:00
|
|
|
// Expand provide guix commands into executable shell
|
2021-12-09 15:34:37 +00:00
|
|
|
std.map(function(i) std.format("guix time-machine -C %s -- %s", [channels, i]),
|
|
|
|
if std.type(commands) == 'array' then commands else [commands]));
|
|
|
|
|
|
|
|
local deployStep(name, target=name, args=[]) = guix_step_time_machine(
|
|
|
|
name,
|
2021-12-09 17:16:24 +00:00
|
|
|
std.format('shell -m manifest.scm -- make %s ENV="${DRONE_DEPLOY_TO}" %s', [target, std.join(" ", args)]),
|
2021-12-09 15:34:37 +00:00
|
|
|
cwd="infra",
|
|
|
|
channels="../channels.scm")
|
2021-12-10 04:03:53 +00:00
|
|
|
.withEnv({ PLAN: "out.plan" } + ci.env_from_secret({
|
2021-12-09 15:34:37 +00:00
|
|
|
AWS_ACCESS_KEY_ID: "aws_access_key_id",
|
|
|
|
AWS_SECRET_ACCESS_KEY: "aws_secret_access_key",
|
|
|
|
}));
|
|
|
|
|
|
|
|
[
|
2021-12-10 04:03:53 +00:00
|
|
|
guix_pipeline("validate").withTrigger(ci.trigger.new().withEvent(["push", "pull_request", "tag"])).withSteps([
|
2021-12-09 15:34:37 +00:00
|
|
|
guix_step_time_machine("build", "build -f guix.scm"),
|
2021-12-10 04:03:53 +00:00
|
|
|
ci.promoteStep("staging"),
|
|
|
|
ci.promoteStep("production"),
|
2021-12-09 15:34:37 +00:00
|
|
|
]),
|
|
|
|
|
2021-12-10 04:03:53 +00:00
|
|
|
guix_pipeline("deploy").withTrigger(ci.trigger.new().withEvent("promote")).withSteps([
|
2021-12-09 15:34:37 +00:00
|
|
|
deployStep("init", "setup"),
|
2021-12-09 23:12:57 +00:00
|
|
|
deployStep("plan").withRuntimeEnvVar({
|
|
|
|
TF_VAR_site_static_files_dir: "$(guix time-machine -C channels.scm -- build -f guix.scm | grep -e '^.*-site$')"
|
|
|
|
}),
|
2021-12-09 15:34:37 +00:00
|
|
|
deployStep("deploy"),
|
|
|
|
])
|
|
|
|
]
|