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

198 lines
4.8 KiB
Plaintext
Raw Normal View History

2020-04-26 13:11:56 +00:00
load("@this//:from-secret.star", "fromSecret")
load("@this//:print-secrets.star", "printSecrets")
2020-04-26 13:44:08 +00:00
load("@this//:map.star", "map")
load("@this//:environment.star", "environment")
load("@this//:echo.star", "echo")
load("@this//:export.star", "export")
load("@this//:echo-secret.star", "echoSecret")
2020-04-26 13:58:26 +00:00
load("@this//:wait.star", "wait")
load("@this//:build.star", "build")
load("@this//:scp.star", "scp")
2020-04-26 16:11:26 +00:00
load("@this//:public-secrets.star", "publicSecrets")
load("@this//:secret-secrets.star", "secretSecrets")
2020-04-26 12:24:13 +00:00
2020-04-25 20:49:57 +00:00
def buildHome():
return {
"name": "build-nginx-home",
"image": "docker:dind",
"volumes": [
{
"name": "dockersock",
"path": "/var/run",
},
],
"environment": environment([
"local-docker-registry",
]),
"commands": [
2020-04-25 21:24:24 +00:00
"cd letsencrypt-nginx",
2020-04-25 21:37:21 +00:00
"sh build.home.sh $${{LOCAL_DOCKER_REGISTRY}}".format(),
2020-04-25 20:49:57 +00:00
],
}
2020-04-25 20:44:43 +00:00
def buildNginx(name):
return {
"name": "build-nginx-{name}".format(name=name),
"image": "docker:dind",
"volumes": [
{
"name": "dockersock",
"path": "/var/run",
},
],
"environment": environment([
"local-docker-registry",
]),
"commands": [
2020-04-25 21:34:03 +00:00
"cd letsencrypt-nginx",
2020-04-25 20:46:58 +00:00
"sh build.sh {name} $${{LOCAL_DOCKER_REGISTRY}}".format(name = name),
2020-04-25 20:44:43 +00:00
],
}
2020-04-26 16:44:57 +00:00
def pull(
images,
):
2020-04-26 17:00:45 +00:00
secrets = [ "local-docker-registry"]
2020-04-26 16:44:57 +00:00
return {
"name": "pull",
"image": "appleboy/drone-ssh",
"environment": environment(secrets),
"settings": {
"envs": [x.replace("-", "_") for x in secrets ],
"host": fromSecret("ssh-host"),
"port": fromSecret("ssh-port"),
"username": fromSecret("ssh-root-user"),
"password": fromSecret("ssh-root-password"),
"script": [
"set -e"
] +
map(export, secrets) +
["docker pull $${{LOCAL_DOCKER_REGISTRY}}{image}".format(image=image) for image in images ]
}
}
2020-04-25 20:44:43 +00:00
2020-04-26 10:52:28 +00:00
def deploy(
filename,
folder,
2020-04-26 16:37:22 +00:00
):
2020-04-25 21:24:24 +00:00
return {
"name": "deploy",
"image": "appleboy/drone-ssh",
2020-04-26 16:11:26 +00:00
"environment": environment(publicSecrets + secretSecrets),
2020-04-25 21:24:24 +00:00
"settings": {
2020-04-26 16:12:48 +00:00
"envs": [x.replace("-", "_") for x in publicSecrets + secretSecrets ],
2020-04-25 21:24:24 +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-26 16:37:22 +00:00
] +
map(export, publicSecrets + secretSecrets) +
[
2020-04-25 21:24:24 +00:00
"docker network prune -f",
2020-04-26 10:52:28 +00:00
"cd {folder}".format(folder=folder),
2020-04-25 21:57:48 +00:00
"docker stack rm gitea",
2020-04-26 13:11:56 +00:00
"sleep 30",
2020-04-26 10:52:28 +00:00
"docker stack deploy -c {filename} gitea".format(filename = filename),
2020-04-25 21:24:24 +00:00
]
}
}
2020-04-26 10:39:42 +00:00
def pipeline(name, steps, dependsOn):
2020-04-25 20:14:33 +00:00
return {
"kind": "pipeline",
"name": name,
"depends_on": dependsOn,
"steps": [
2020-04-26 08:54:48 +00:00
printSecrets(
"env-stack",
2020-04-26 16:11:26 +00:00
publicSecrets,
secretSecrets,
2020-04-26 08:54:48 +00:00
),
2020-04-25 21:57:48 +00:00
wait(15, "wait"),
2020-04-26 10:39:42 +00:00
] + steps,
2020-04-25 20:07:36 +00:00
"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",
},
},
],
2020-04-24 10:07:57 +00:00
}
2020-04-24 06:58:20 +00:00
2020-04-24 06:32:20 +00:00
def main(ctx):
2020-04-26 08:22:49 +00:00
if ctx.build.branch == 'home-deploy':
2020-04-26 08:19:22 +00:00
return [
2020-04-26 10:39:42 +00:00
pipeline(
2020-04-26 10:52:28 +00:00
'home-deploy',
[
#build("guacamole-postgresql"),
#build("ngrok-gitea"),
#build("letsencrypt-nginx"),
2020-04-26 17:00:45 +00:00
#build("drone-starlark"),
2020-04-26 10:52:28 +00:00
#buildHome(),
#buildNginx("blog"),
#buildNginx("drone"),
#buildNginx("git"),
#buildNginx("remote"),
#buildNginx("chat"),
2020-04-26 12:59:31 +00:00
scp("~/gitea-drone-stack"),
2020-04-26 16:44:57 +00:00
pull([
"letsencrypt-git",
"letsencrypt-chat",
"letsencrypt-drone",
"letsencrypt-remote",
"letsencrypt-blog",
"nginx-home1",
"drone-starlark",
]),
2020-04-26 10:52:28 +00:00
deploy(
"docker-compose-home.yml",
2020-04-26 13:00:59 +00:00
"/home/giles/gitea-drone-stack",
2020-04-26 10:52:28 +00:00
),
],
[],
),
]
if ctx.build.branch == 'do':
return [
pipeline(
'do-deploy',
2020-04-26 10:39:42 +00:00
[
build("guacamole-postgresql"),
build("letsencrypt-nginx"),
buildHome(),
buildNginx("blog"),
buildNginx("drone"),
buildNginx("git"),
buildNginx("remote"),
buildNginx("chat"),
2020-04-26 10:52:28 +00:00
scp("~/stack-deploy"),
#deploy("docker-compose-do.yml", "~/stack-deploy"),
2020-04-26 10:39:42 +00:00
],
[],
),
2020-04-26 08:19:22 +00:00
]
2020-04-24 09:56:09 +00:00