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-starlark/repos/deploy.star

42 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2020-04-26 17:06:31 +00:00
load("@this//:from-secret.star", "fromSecret")
load("@this//:map.star", "map")
load("@this//:environment.star", "environment")
load("@this//:export.star", "export")
def deploy(
filename,
2020-04-27 22:48:48 +00:00
name,
2020-04-26 17:06:31 +00:00
folder,
2020-04-28 08:27:15 +00:00
secrets,
2020-04-28 19:22:17 +00:00
commands,
2020-04-29 14:52:52 +00:00
ctx
2020-04-26 17:06:31 +00:00
):
2020-04-27 20:52:58 +00:00
return {
2020-05-01 22:57:00 +00:00
"name": "deploy {name}".format(name = name),
2020-04-26 17:06:31 +00:00
"image": "appleboy/drone-ssh",
2020-04-28 08:27:15 +00:00
"environment": environment(secrets),
2020-04-26 17:06:31 +00:00
"settings": {
2020-04-29 14:31:48 +00:00
"envs": [x.replace("-", "_") for x in secrets ],
2020-04-26 17:06:31 +00:00
"host": fromSecret("ssh-host"),
"port": fromSecret("ssh-port"),
"username": fromSecret("ssh-root-user"),
"password": fromSecret("ssh-root-password"),
"script": [
"set -e"
] +
2020-04-28 08:27:15 +00:00
map(export, secrets) +
2020-04-26 17:06:31 +00:00
[
2020-04-29 15:30:50 +00:00
"export DRONE_REPO_LINK=$${{DRONE_GITEA_SERVER}}/{namespace}/{name}".format(name=ctx.repo.name, namespace=ctx.repo.namespace),
2020-04-29 14:58:22 +00:00
"export DRONE_COMMIT={commit}".format(commit=ctx.build.commit),
2020-04-26 17:06:31 +00:00
"docker network prune -f",
2020-04-29 10:05:39 +00:00
"cd {folder}".format(folder=folder),
2020-05-08 09:28:32 +00:00
"docker stack rm proxy",
"sleep 30",
"docker stack deploy -c docker-compose-proxy.yml proxy",
2020-05-05 21:08:39 +00:00
"docker stack rm {name}".format(name = name),
"sleep 30",
2020-04-29 10:05:39 +00:00
"docker stack deploy -c {filename} {name}".format(name= name, filename = filename),
2020-04-28 19:22:17 +00:00
] + commands
2020-04-26 17:06:31 +00:00
}
}