def fromSecret(name): return { "from_secret": name } def environment(env): return dict( [(x.replace("-", "_").upper(), fromSecret(x)) for x in env] ) def map(fn, l): return [fn(x) for x in l] def echo(x): return "echo {secret}=${environment} >> env-stack".format(secret = x, environment = x.replace("-", "_").upper()) def printSecrets(env): return { "name": "print secrets", "image": "appleboy/drone-ssh", "environment": environment(env), "settings": { "envs": [x.replace("-", "_") for x in env ], "host": fromSecret("ssh-host"), "port": fromSecret("ssh-port"), "username": fromSecret("ssh-user"), "password": fromSecret("ssh-password"), "script": [ "rm -f env.stack", ] + map(echo, env) } } def wait(delay, name): return { "name": name, "image": "alpine", "commands": [ "sleep {delay}".format(delay = delay), ], } def build(name): return { "name": "build-{name}".format(name=name), "image": "docker:dind", "volumes": [ { "name": "dockersock", "path": "/var/run", }, ], "environment": environment([ "local-docker-registry", ]), "commands": [ "cd {name}".format(name=name), "docker build . -t $${{LOCAL_DOCKER_REGISTRY}}{name}".format(name=name), "docker push $${{LOCAL_DOCKER_REGISTRY}}{name}".format(name=name), ], } def steps(name, dependsOn): return { "kind": "pipeline", "name": name, "depends_on": dependsOn, "steps": [ printSecrets([ "local-docker-registry", "ssh-host", "ssh-user", "ssh-port", ]), wait(15, "wait"), build("guacamole-postgresql"), build("ngrok-gitea"), { "name": "build", "image": "alpine", "commands": [ "echo hello 'star lark'", ], }, ], "services": [ { "name": "docker", "image": "docker:dind", "privileged": True, "volumes": [ { "name": "dockersock", "path": "/var/run", }, { "name": "ca", "path": "/etc/docker/certs.d", }, ], } ], "volumes": [ { "name": "dockersock", "temp": {}, }, { "name": "ca", "host": { "path": "/home/giles/gitea-drone-stack/.ca", }, }, ], } def main(ctx): return [ steps('first', []), steps('second', ['first']), ]