2022-12-22 03:09:21 +00:00
|
|
|
local PROD = 'production';
|
|
|
|
local STAGE = 'staging';
|
2022-12-22 05:48:52 +00:00
|
|
|
local NIX = 'nix --store /tmp/cache --extra-experimental-features nix-command --extra-experimental-features flakes';
|
2022-12-22 06:00:02 +00:00
|
|
|
local VOLUMES = [
|
|
|
|
{ name: 'site', path: '/site' },
|
|
|
|
{ name: 'cache', path: '/tmp/cache' },
|
|
|
|
];
|
2022-12-22 03:09:21 +00:00
|
|
|
|
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 06:00:02 +00:00
|
|
|
local Step(env, name, cmds, extras={}, volumes=VOLUMES) =
|
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 06:00:02 +00:00
|
|
|
volumes: volumes,
|
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
|
|
|
|
2022-12-22 06:00:02 +00:00
|
|
|
local BootstrapStep =
|
|
|
|
Step(STAGE, 'bootrap nix', [
|
|
|
|
'for file in /nix/store/*; do',
|
|
|
|
' item=$(basename $file)',
|
|
|
|
' if [ ! -e /cache/$item ]; then',
|
2022-12-22 06:01:43 +00:00
|
|
|
' echo "moving $file to cache"',
|
2022-12-22 06:00:02 +00:00
|
|
|
' cp -r $file /cache/$item',
|
|
|
|
' fi',
|
|
|
|
'done',
|
|
|
|
], volumes=[{ name: 'cache', path: '/cache' }]);
|
|
|
|
|
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 06:00:02 +00:00
|
|
|
BootstrapStep,
|
2022-12-22 05:26:49 +00:00
|
|
|
NixStep(STAGE),
|
|
|
|
NixStep(PROD),
|
|
|
|
DeployStep(STAGE),
|
|
|
|
DeployStep(PROD),
|
2022-10-20 22:40:22 +00:00
|
|
|
],
|
|
|
|
}
|