feat: configured

BREAKING CHANGE: new api config function
This commit is contained in:
Giles 2020-09-23 19:58:49 +01:00
parent ebd87a2e0e
commit 527aa4128d
3 changed files with 122 additions and 119 deletions

View File

@ -6,107 +6,109 @@ local util = import 'lib/util.libsonnet';
local overide = function(overides, name) local overide = function(overides, name)
({ [name]: {}} + overides)[name]; ({ [name]: {}} + overides)[name];
function(
name, function(config)
root, function(
buildSecrets, name,
publicSecrets, root,
secretSecrets, buildSecrets,
droneSecrets, publicSecrets,
imageOverides = {}, secretSecrets,
) droneSecrets,
{ imageOverides = {},
kind: 'pipeline', )
type: 'docker', {
name: 'deploy', kind: 'pipeline',
clone: { type: 'docker',
disable: false, name: 'deploy',
depth: 0, clone: {
}, disable: false,
services: [ depth: 0,
images.docker(overide(imageOverides, 'docker')) { },
privileged: true, services: [
volumes: [ images(config).docker(overide(imageOverides, 'docker')) {
{ privileged: true,
name: 'dockersock', volumes: [
path: '/var/run', {
}, name: 'dockersock',
{ path: '/var/run',
name: 'ca', },
{
name: 'ca',
path: '/etc/docker/certs.d',
},
],
},
],
volumes: [
{
name: 'dockersock',
temp: {},
},
{
name: 'ca',
host: {
path: '/etc/docker/certs.d', path: '/etc/docker/certs.d',
}, },
],
},
],
volumes: [
{
name: 'dockersock',
temp: {},
},
{
name: 'ca',
host: {
path: '/etc/docker/certs.d',
}, },
}, ],
], steps:[
steps:[ compose(
compose( std.map(
std.map( function(secret) util.printEnv('env-%s' % name, secret),
function(secret) util.printEnv('env-%s' % name, secret), buildSecrets +
buildSecrets + publicSecrets +
publicSecrets + secretSecrets
secretSecrets )
) )
) (
( images(config).ssh(overide(imageOverides, 'ssh')) {
images.ssh(overide(imageOverides, 'ssh')) { settings +: {
settings +: { script +: [
script +: [ 'rm -f env-%s' % name,
'rm -f env-%s' % name, ],
], },
}, },
) {
name: 'print env',
}, },
) { images(config).scp(overide(imageOverides, 'scp'))(
name: 'print env', '%(root)s%(name)s' % { root: root, name: name }
},
images.scp(overide(imageOverides, 'scp'))(
'%(root)s%(name)s' % { root: root, name: name }
),
images.wait(overide(imageOverides, 'alpine'))(15),
build(overide(imageOverides, 'docker'))(buildSecrets),
compose(
std.map(
function(secret) environment.envSet(secret),
publicSecrets + secretSecrets + buildSecrets,
), ),
)( images(config).wait(overide(imageOverides, 'alpine'))(15),
images.ssh(overide(imageOverides, 'ssh')) { build(config)(overide(imageOverides, 'docker'))(buildSecrets),
name: 'deploy', compose(
settings +: { std.map(
envs +: std.map( function(secret) environment.envSet(secret),
environment.env, publicSecrets + secretSecrets + buildSecrets,
droneSecrets, ),
), )(
script +: images(config).ssh(overide(imageOverides, 'ssh')) {
std.map( name: 'deploy',
function(secret) settings +: {
'export %(env)s=$${%(env)s}' % { envs +: std.map(
env: environment.environment(secret) environment.env,
}, droneSecrets,
secretSecrets + publicSecrets + buildSecrets + droneSecrets, ),
) + script +:
[ std.map(
'set -e', function(secret)
'cd %(root)s%(name)s' % { root: root, name: name }, 'export %(env)s=$${%(env)s}' % {
'sh .drone/login.sh', env: environment.environment(secret)
'sh .drone/pull.sh', },
'sh .drone/deploy.sh', secretSecrets + publicSecrets + buildSecrets + droneSecrets,
] ) +
} [
}, 'set -e',
), 'cd %(root)s%(name)s' % { root: root, name: name },
], 'sh .drone/login.sh',
} 'sh .drone/pull.sh',
'sh .drone/deploy.sh',
]
}
},
),
],
}

View File

@ -1,22 +1,23 @@
local images = import 'images.libsonnet'; local images = import 'images.libsonnet';
local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet'; local environment = import 'node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
function(overide) function(config)
function(secrets) function(overide)
images.docker(overide) { function(secrets)
name +: 'build:', images(config).docker(overide) {
environment +: environment.environmentSecrets(secrets), name +: 'build:',
volumes: [ environment +: environment.environmentSecrets(secrets),
{ volumes: [
name: 'dockersock', {
path: '/var/run', name: 'dockersock',
}, path: '/var/run',
], },
commands: [ ],
'set -e', commands: [
'sh .drone/login.sh', 'set -e',
'sh .drone/build.sh', 'sh .drone/login.sh',
'sh .drone/push.sh', 'sh .drone/build.sh',
'sh .drone/logout.sh', 'sh .drone/push.sh',
], 'sh .drone/logout.sh',
} ],
}

View File

@ -1,11 +1,11 @@
{ function(config) {
docker(overide): { docker(overide): {
name: 'docker', name: 'docker',
image: 'docker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f', image: '%(registry)sdocker:19.03.12-dind@sha256:8dded163e463f4a59bf305b3dca98e312b2cfb89a43da3872e48f95a7554c48f' % config,
} + overide, } + overide,
scp(overide): function(target) { scp(overide): function(target) {
name: 'scp', name: 'scp',
image: 'appleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47', image: '%(registry)sappleboy/drone-scp:1.6.2@sha256:bd37a55f4b97e7742b0de7333669b96220b3cc422d366e1fa8c34059b736ab47' % config,
settings +: { settings +: {
command_timeout: '2m', command_timeout: '2m',
target: target, target: target,
@ -15,7 +15,7 @@
}, },
} + overide, } + overide,
ssh(overide): { ssh(overide): {
image: 'appleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea', image: '%(registry)sappleboy/drone-ssh:1.6.2@sha256:b801dc2cd238c192b6e99acfa7bc3f5b9a03f312bd2feb1e10b3a7a28a1b80ea' % config,
settings +: { settings +: {
envs: [ envs: [
'drone_tag', 'drone_tag',
@ -28,7 +28,7 @@
}, },
} + overide, } + overide,
wait(overide): function(delay) { wait(overide): function(delay) {
image: 'alpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1', image: '%(registry)salpine:3.12.0@sha256:90baa0922fe90624b05cb5766fa5da4e337921656c2f8e2b13bd3c052a0baac1',
name: 'wait', name: 'wait',
commands: [ commands: [
'sleep %s' % delay, 'sleep %s' % delay,