portainer/.drone-home.jsonnet

212 lines
4.4 KiB
Plaintext
Raw Normal View History

2020-07-28 16:09:34 +00:00
local publicSecrets = [
'ssh-host',
'ssh-user',
];
local secretSecrets = [
'ssh-passwoprd',
2020-07-28 15:34:37 +00:00
];
2020-07-28 14:44:13 +00:00
local util = {
2020-07-28 15:34:37 +00:00
// the head of an array
head(array): array[0],
// the tail of an array
tail(array): std.makeArray(
std.length(array) -1,
function(x) array[x + 1],
),
// compose an array of functions
compose(functions):
local compose(functions) =
if std.length(functions) == 0
then
local ret(object) = object;
ret
else
local ret(object) = compose(
2020-07-28 15:35:16 +00:00
util.tail(
2020-07-28 15:34:37 +00:00
functions,
)
)(
2020-07-28 15:35:16 +00:00
util.head(
2020-07-28 15:34:37 +00:00
functions,
)(object)
);
ret;
compose(functions),
2020-07-28 14:44:13 +00:00
fromSecret(secret): {
from_secret: secret,
},
2020-07-28 15:06:47 +00:00
secret(secret): std.asciiLower(
std.strReplace(
secret,
'_',
'-',
),
),
environment(secret): std.asciiUpper(
std.strReplace(
secret,
'-',
'_',
),
),
env(secret): std.asciiLower(
std.strReplace(
secret,
'-',
'_',
),
),
2020-07-28 16:09:34 +00:00
envSet(env): function(step) step {
2020-07-28 15:01:03 +00:00
environment +: {
2020-07-28 15:06:47 +00:00
[util.environment(env)]: util.fromSecret(
util.secret(env)
2020-07-28 15:01:03 +00:00
),
},
settings +: {
envs +: [
2020-07-28 15:06:47 +00:00
util.env(env),
2020-07-28 15:01:03 +00:00
],
2020-07-28 16:09:34 +00:00
},
},
2020-07-28 16:10:36 +00:00
printEnv(file, env): function(step) util.envSet(env)(step) {
2020-07-28 16:09:34 +00:00
settings +: {
2020-07-28 15:01:03 +00:00
script +: [
2020-07-28 15:09:56 +00:00
'echo "export %(environment)s=\'$${%(environment)s}\'" >> %(file)s # "%(secret)s"' % {
2020-07-28 15:06:47 +00:00
environment: util.environment(env),
2020-07-28 15:01:03 +00:00
file: file,
2020-07-28 15:06:47 +00:00
secret: util.secret(env),
2020-07-28 15:01:03 +00:00
},
],
},
},
2020-07-28 14:44:13 +00:00
};
2020-07-28 13:09:17 +00:00
local images = {
docker: {
2020-07-28 14:32:32 +00:00
name: 'docker',
2020-07-28 13:09:17 +00:00
image: 'docker:dind',
},
2020-07-28 14:32:32 +00:00
scp(target): {
name: 'scp',
image: 'appleboy/drone-scp',
settings: {
host: {
from_secret: 'ssh-host',
},
username: {
from_secret: 'ssh-user',
},
password: {
from_secret: 'ssh-password',
},
port: {
from_secret: 'ssh-port',
},
command_timeout: '2m',
target: target,
source: [
'.',
],
},
},
2020-07-28 14:44:13 +00:00
ssh: {
image: 'appleboy/drone-ssh',
settings: {
host: util.fromSecret("ssh-host"),
port: util.fromSecret("ssh-port"),
username: util.fromSecret("ssh-user"),
password: util.fromSecret("ssh-password"),
script: [],
},
},
2020-07-28 14:35:58 +00:00
wait(delay): {
image: 'alpine',
name: 'wait',
commands: [
'sleep %s' % delay,
],
}
2020-07-28 13:09:17 +00:00
};
2020-07-28 13:03:09 +00:00
[
{
kind: 'pipeline',
type: 'docker',
name: 'build',
clone: {
disable: false,
depth: 0,
},
services: [
images.docker {
privileged: true,
volumes: [
{
name: 'dockersock',
path: '/var/run',
},
{
name: 'ca',
path: '/etc/docker/certs.d',
},
],
},
],
volumes: [
{
name: 'dockersock',
temp: {},
},
{
name: 'ca',
host: {
path: '/etc/docker/certs.d',
},
},
],
2020-07-28 14:32:32 +00:00
steps:[
2020-07-28 14:35:58 +00:00
images.scp(
'/stack/root'
),
images.wait(15),
2020-07-28 15:34:37 +00:00
util.compose(
std.map(
2020-07-28 15:38:12 +00:00
function(secret) util.printEnv('afile', secret),
2020-07-28 15:34:37 +00:00
secrets,
)
2020-07-28 15:01:03 +00:00
)(
images.ssh {
2020-07-28 15:34:37 +00:00
name: 'will print ssh-host again',
2020-07-28 15:38:12 +00:00
settings +: {
script +: [
2020-07-28 15:34:37 +00:00
'rm afile'
2020-07-28 15:38:12 +00:00
],
},
2020-07-28 15:01:03 +00:00
},
2020-07-28 16:09:34 +00:00
),/*
images.ssh {
name: 'deploy portainer',
"environment": environment(secrets),
"settings": {
"envs": [x.replace("-", "_") for x in secrets ],
username: util.fromSecret("ssh-root-user"),
password: util.fromSecret("ssh-root-password"),
script: [
'set -e',
'echo go',
] +
map(export, secrets) +
[
"export DRONE_REPO_LINK=$${{DRONE_GITEA_SERVER}}/{namespace}/{name}".format(name=ctx.repo.name, namespace=ctx.repo.namespace),
"export DRONE_COMMIT={commit}".format(commit=ctx.build.commit),
"docker network prune -f",
"cd {folder}".format(folder=folder),
"docker stack rm {name}".format(name = name),
"sleep 30",
"docker stack deploy -c {filename} {name}".format(name= name, filename = filename),
] + commands
}
}*/
2020-07-28 14:32:32 +00:00
],
2020-07-28 13:03:09 +00:00
}
]