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-04-26 17:06:31 +00:00
|
|
|
"name": "deploy",
|
|
|
|
"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),
|
|
|
|
"docker stack rm {name}".format(name = name),
|
2020-04-26 17:06:31 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
}
|