Add bootstrap step
continuous-integration/drone/push Build is failing Details

main
mat ess 2022-12-22 01:00:02 -05:00
parent 1f6e1dfb72
commit b0390a0f02
1 changed files with 17 additions and 6 deletions

View File

@ -1,6 +1,10 @@
local PROD = 'production'; local PROD = 'production';
local STAGE = 'staging'; local STAGE = 'staging';
local NIX = 'nix --store /tmp/cache --extra-experimental-features nix-command --extra-experimental-features flakes'; local NIX = 'nix --store /tmp/cache --extra-experimental-features nix-command --extra-experimental-features flakes';
local VOLUMES = [
{ name: 'site', path: '/site' },
{ name: 'cache', path: '/tmp/cache' },
];
local Secrets(secrets) = { local Secrets(secrets) = {
environment: { environment: {
@ -16,24 +20,30 @@ local WhenProd(prod) = if prod then {
target: { exclude: [PROD] }, target: { exclude: [PROD] },
}; };
local Step(env, name, cmds, extras={}) = local Step(env, name, cmds, extras={}, volumes=VOLUMES) =
local prod = env == PROD; local prod = env == PROD;
{ {
name: name + ' ' + env, name: name + ' ' + env,
image: 'nixos/nix:latest', image: 'nixos/nix:latest',
volumes: [ volumes: volumes,
{ name: 'site', path: '/site' },
{ name: 'cache', path: '/tmp/cache' },
],
commands: cmds, commands: cmds,
when: WhenProd(prod), when: WhenProd(prod),
} + extras; } + extras;
local BootstrapStep =
Step(STAGE, 'bootrap nix', [
'for file in /nix/store/*; do',
' item=$(basename $file)',
' if [ ! -e /cache/$item ]; then',
' cp -r $file /cache/$item',
' fi',
'done',
], volumes=[{ name: 'cache', path: '/cache' }]);
local NixStep(env) = local NixStep(env) =
local prod = env == PROD; local prod = env == PROD;
local output = if prod then '' else ' .#staging-site'; local output = if prod then '' else ' .#staging-site';
Step(env, 'nix build', [ Step(env, 'nix build', [
'ls /nix/store',
NIX + ' build' + output, NIX + ' build' + output,
'cp -r result/* /site/', 'cp -r result/* /site/',
]); ]);
@ -57,6 +67,7 @@ local DeployStep(env) =
], ],
steps: [ steps: [
BootstrapStep,
NixStep(STAGE), NixStep(STAGE),
NixStep(PROD), NixStep(PROD),
DeployStep(STAGE), DeployStep(STAGE),