2020-08-15 09:43:20 +00:00
|
|
|
local build = import 'lib/build.libsonnet';
|
|
|
|
local images = import 'lib/images.libsonnet';
|
2020-08-19 20:12:35 +00:00
|
|
|
local environment = import 'lib/node_modules/@sigyl/jsonnet-drone-environment/environment.libsonnet';
|
2020-08-19 20:01:46 +00:00
|
|
|
local compose = import 'lib/node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
|
2020-08-15 09:43:20 +00:00
|
|
|
local util = import 'lib/util.libsonnet';
|
|
|
|
|
2020-09-23 18:58:49 +00:00
|
|
|
|
|
|
|
function(config)
|
|
|
|
function(
|
|
|
|
name,
|
|
|
|
root,
|
|
|
|
buildSecrets,
|
|
|
|
publicSecrets,
|
|
|
|
secretSecrets,
|
|
|
|
droneSecrets,
|
|
|
|
)
|
|
|
|
{
|
|
|
|
kind: 'pipeline',
|
|
|
|
type: 'docker',
|
|
|
|
name: 'deploy',
|
|
|
|
clone: {
|
|
|
|
disable: false,
|
|
|
|
depth: 0,
|
|
|
|
},
|
|
|
|
services: [
|
2020-09-24 12:48:43 +00:00
|
|
|
images(config).docker {
|
2020-09-23 18:58:49 +00:00
|
|
|
privileged: true,
|
|
|
|
volumes: [
|
|
|
|
{
|
|
|
|
name: 'dockersock',
|
|
|
|
path: '/var/run',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ca',
|
|
|
|
path: '/etc/docker/certs.d',
|
|
|
|
},
|
2020-10-22 12:10:13 +00:00
|
|
|
{
|
|
|
|
name: 'daemonjson',
|
|
|
|
path: '/etc/docker/daemon.json',
|
|
|
|
},
|
2020-09-23 18:58:49 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
volumes: [
|
|
|
|
{
|
|
|
|
name: 'dockersock',
|
|
|
|
temp: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ca',
|
|
|
|
host: {
|
2020-08-15 09:43:20 +00:00
|
|
|
path: '/etc/docker/certs.d',
|
|
|
|
},
|
|
|
|
},
|
2020-10-22 12:10:13 +00:00
|
|
|
{
|
|
|
|
name: 'daemonjson',
|
|
|
|
host: {
|
|
|
|
path: '/etc/docker/daemon.json',
|
|
|
|
},
|
|
|
|
},
|
2020-09-23 18:58:49 +00:00
|
|
|
],
|
|
|
|
steps:[
|
|
|
|
compose(
|
|
|
|
std.map(
|
|
|
|
function(secret) util.printEnv('env-%s' % name, secret),
|
|
|
|
buildSecrets +
|
|
|
|
publicSecrets +
|
|
|
|
secretSecrets
|
|
|
|
)
|
2020-08-15 09:43:20 +00:00
|
|
|
)
|
2020-09-23 18:58:49 +00:00
|
|
|
(
|
2020-09-24 12:48:43 +00:00
|
|
|
images(config).ssh {
|
2020-09-23 18:58:49 +00:00
|
|
|
settings +: {
|
|
|
|
script +: [
|
|
|
|
'rm -f env-%s' % name,
|
|
|
|
],
|
|
|
|
},
|
2020-08-15 09:43:20 +00:00
|
|
|
},
|
2020-09-23 18:58:49 +00:00
|
|
|
) {
|
|
|
|
name: 'print env',
|
2020-08-15 09:43:20 +00:00
|
|
|
},
|
2020-09-24 12:48:43 +00:00
|
|
|
images(config).scp(
|
2020-09-23 18:58:49 +00:00
|
|
|
'%(root)s%(name)s' % { root: root, name: name }
|
2020-08-15 09:43:20 +00:00
|
|
|
),
|
2020-09-24 12:48:43 +00:00
|
|
|
images(config).wait(15),
|
|
|
|
build(config)(buildSecrets),
|
2020-09-23 18:58:49 +00:00
|
|
|
compose(
|
|
|
|
std.map(
|
|
|
|
function(secret) environment.envSet(secret),
|
|
|
|
publicSecrets + secretSecrets + buildSecrets,
|
|
|
|
),
|
|
|
|
)(
|
2020-09-24 12:48:43 +00:00
|
|
|
images(config).ssh{
|
2020-09-23 18:58:49 +00:00
|
|
|
name: 'deploy',
|
|
|
|
settings +: {
|
|
|
|
envs +: std.map(
|
|
|
|
environment.env,
|
|
|
|
droneSecrets,
|
|
|
|
),
|
|
|
|
script +:
|
|
|
|
std.map(
|
|
|
|
function(secret)
|
|
|
|
'export %(env)s=$${%(env)s}' % {
|
|
|
|
env: environment.environment(secret)
|
|
|
|
},
|
|
|
|
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',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|