mat.services/.drone.jsonnet

65 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-12-22 03:09:21 +00:00
local PROD = 'production';
local STAGE = 'staging';
local NIX = 'nix --extra-experimental-features nix-command --extra-experimental-features flakes';
2022-12-22 04:45:31 +00:00
local Secrets(secrets) = {
environment: {
[secret]: { from_secret: std.asciiLower(secret) }
for secret in secrets
},
};
2022-10-20 23:32:33 +00:00
local WhenProd(prod) = if prod then {
event: ['promote'],
2022-12-22 03:09:21 +00:00
target: [PROD],
2022-10-20 23:32:33 +00:00
} else {
2022-12-22 03:09:21 +00:00
target: { exclude: [PROD] },
2022-10-20 23:32:33 +00:00
};
2022-12-22 03:09:21 +00:00
2022-12-22 04:45:31 +00:00
local Step(env, name, cmds, extras={}) =
2022-12-22 03:09:21 +00:00
local prod = env == PROD;
2022-10-20 23:32:33 +00:00
{
2022-12-22 03:09:21 +00:00
name: name + ' ' + env,
2022-10-21 03:08:14 +00:00
image: 'nixos/nix:latest',
2022-12-22 04:59:24 +00:00
volumes: [
{ name: 'site', path: '/site' },
2022-12-22 05:19:43 +00:00
// { name: 'cache', path: '/nix/store' },
2022-12-22 04:59:24 +00:00
],
2022-12-22 03:09:21 +00:00
commands: cmds,
2022-10-20 23:32:33 +00:00
when: WhenProd(prod),
2022-12-22 04:45:31 +00:00
} + extras;
2022-12-22 03:09:21 +00:00
local NixStep(env) =
local prod = env == PROD;
local output = if prod then '' else ' .#staging-site';
Step(env, 'nix build', [
NIX + ' build' + output,
'cp -r result/* /site/',
]);
local DeployStep(env) =
local prod = env == PROD;
local options = if prod then '--prod' else '--alias staging';
Step(env, 'netlify deploy', [
2022-12-22 03:27:35 +00:00
NIX + ' profile install nixpkgs#netlify-cli',
2022-12-22 04:45:31 +00:00
'netlify deploy -d /site --auth $NETLIFY_TOKEN --site $NETLIFY_SITE_ID --message "$DRONE_COMMIT_MESSAGE" ' + options,
], Secrets(['NETLIFY_TOKEN', 'NETLIFY_SITE_ID']));
2022-12-22 03:09:21 +00:00
2022-10-20 22:40:22 +00:00
{
kind: 'pipeline',
type: 'docker',
name: 'default',
2022-12-22 04:59:24 +00:00
volumes: [
{ name: 'site', temp: {} },
2022-12-22 05:11:43 +00:00
{ name: 'cache', host: { path: '/data/cache' } },
2022-12-22 04:59:24 +00:00
],
2022-10-20 22:40:22 +00:00
steps: [
2022-12-22 03:09:21 +00:00
NixStep(STAGE),
NixStep(PROD),
DeployStep(STAGE),
DeployStep(PROD),
2022-10-20 22:40:22 +00:00
],
}