jsonnet-drone/save.libsonnet

122 lines
3.9 KiB
Plaintext
Raw Normal View History

local build = import 'lib/build.libsonnet';
local images = import 'lib/images.libsonnet';
local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
local compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
local util = import 'lib/util.libsonnet';
local login = import 'lib/login.libsonnet';
function(config)
function(
defs,
builtDefs,
)
{
kind: 'pipeline',
type: 'docker',
name: 'save',
clone: {
disable: true,
},
steps: [
2020-10-23 19:20:40 +00:00
images(config).ssh() {
settings +: {
script +: [
'mkdir -p /%(root)s/.images/%(name)s/built' % config,
'rm -f /%(root)s/.images/%(name)s/*.*' % config,
'rm -f /%(root)s/.images/%(name)s/built/*.*' % config,
],
},
}
{
name: 'mkdir',
},
] +
std.map(
function(def)
2020-10-23 19:20:40 +00:00
images(config).ssh() {
settings +: {
envs +: [
'registry_domain',
'registry_port',
'registry_password',
'destination_registry'
],
script +: [
login,
'docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s' % (config + def),
'docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s -o /%(root)s/.images/%(name)s/%(out)s.tar' % (
config + def +
{
out: std.strReplace(def.save, '/', '_'),
}
),
'echo "docker load < %(out)s.tar" >> /%(root)s/.images/%(name)s/load.sh' % (
config + {
out: std.strReplace(def.save, '/', '_'),
}
),
'echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(pull)s $${DESTINATION_REGISTRY}/%(root)s/%(name)s/%(pull)s" >> /%(root)s/.images/%(name)s/load.sh' % (
config +
{
pull: def.save,
}
),
],
},
} +
{
name: def.save,
},
defs
) +
std.map(
function(def)
2020-10-23 19:20:40 +00:00
images(config).ssh() {
settings +: {
envs +: [
'registry_domain',
'registry_port',
'registry_password',
'destination_registry',
],
script +: [
login,
'docker pull $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s' % (config + { save: def }),
'docker save $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(save)s -o /%(root)s/.images/%(name)s/built/%(out)s.tar' % (
config +
{
save: def,
out: std.strReplace(def, '/', '_'),
}
),
'echo "docker load %(out)s.tar" >> /%(root)s/.images/%(name)s/built/load.sh' % (
config + {
out: std.strReplace(def, '/', '_'),
}
),
'echo "docker tag $${REGISTRY_DOMAIN}:$${REGISTRY_PORT}/%(root)s/%(name)s/%(pull)s ${DESINATION_REGISTRY}/%(root)s/%(name)s/%(pull)s" >> /%(root)s/.images/%(name)s/built/load.sh' % (
config +
{
pull: def,
}
),
],
},
} +
{
name: def,
},
builtDefs
),
} {
trigger +: {
event +: [
'promote',
],
target +: [
2020-10-23 08:18:51 +00:00
'save',
],
},
}