This repository has been archived on 2020-08-11. You can view files and clone it, but cannot push or open issues or pull requests.
stack/.drone.star

65 lines
1.4 KiB
Plaintext
Raw Normal View History

2020-04-24 10:29:25 +00:00
def fromSecret(name):
return {
"from_secret": name
}
2020-04-24 11:53:10 +00:00
def environment(env):
2020-04-24 11:52:21 +00:00
return dict(
[(x.replace("-", "_").upper(), fromSecret(x)) for x in env]
)
2020-04-24 13:37:38 +00:00
def map(fn, l):
2020-04-24 13:41:26 +00:00
return [fn(x) for x in l]
2020-04-24 13:47:19 +00:00
def echo(x):
2020-04-24 13:49:13 +00:00
return "echo {secret}=${environment} >> env-stack".format(secret = x, environment = x.replace("-", "_").upper())
2020-04-24 11:42:31 +00:00
def printSecrets(env):
2020-04-24 13:30:51 +00:00
2020-04-24 10:29:25 +00:00
return {
2020-04-24 11:56:35 +00:00
"name": "print secrets",
2020-04-24 10:29:25 +00:00
"image": "appleboy/drone-ssh",
2020-04-24 11:50:26 +00:00
"environment": environment(env),
2020-04-24 10:29:25 +00:00
"settings": {
2020-04-25 18:57:07 +00:00
"envs": [x.replace("-", "_") for x in env ],
2020-04-24 10:29:25 +00:00
"host": fromSecret("ssh-host"),
"port": fromSecret("ssh-port"),
"username": fromSecret("ssh-user"),
"password": fromSecret("ssh-password"),
2020-04-24 13:31:41 +00:00
"script": [
2020-04-24 13:47:19 +00:00
"rm -f env.stack",
] + map(echo, env)
2020-04-24 10:29:25 +00:00
}
}
2020-04-25 18:57:07 +00:00
def wait(delay, name):
return {
name,
"image": "alpine",
"commands": "sleep {delay}".format(delay = delay),
}
2020-04-24 12:06:53 +00:00
def steps(name, dependsOn):
2020-04-24 10:07:57 +00:00
return {
"kind": "pipeline",
2020-04-24 10:10:50 +00:00
"name": name,
2020-04-24 12:06:53 +00:00
"depends_on": dependsOn,
2020-04-24 10:07:57 +00:00
"steps": [
2020-04-24 11:42:31 +00:00
printSecrets([
"local-docker-registry",
"ssh-host",
"ssh-user",
"ssh-port",
]),
2020-04-25 18:57:07 +00:00
wait(15, "wait"),
2020-04-24 10:07:57 +00:00
{
"name": "build",
"image": "alpine",
"commands": [
"echo hello 'star lark'",
],
},
],
}
2020-04-24 06:58:20 +00:00
2020-04-24 06:32:20 +00:00
def main(ctx):
2020-04-24 10:10:50 +00:00
return [
2020-04-24 12:06:53 +00:00
steps('first', []),
steps('second', ['first']),
2020-04-24 10:10:50 +00:00
]
2020-04-24 09:56:09 +00:00