infra/.drone.yml

112 lines
3.3 KiB
YAML
Raw Normal View History

2021-02-12 21:42:16 +00:00
kind: pipeline
type: kubernetes
name: default
2021-04-09 21:16:57 +01:00
concurrency:
limit: 1
2021-04-08 19:07:04 +01:00
trigger:
event:
- push
2021-02-12 21:42:16 +00:00
steps:
2021-02-14 18:23:49 +00:00
- name: Prepare terraform files
2021-02-12 21:42:16 +00:00
image: alpine
commands:
2021-02-14 13:17:24 +00:00
- "apk update && apk add jq curl git git-crypt"
2021-02-12 21:42:16 +00:00
- |
curl -k https://10.0.20.100:6443/api/v1/namespaces/drone/configmaps/git-crypt-key -H "Authorization:Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" | jq -r .data.key | base64 -d > /tmp/key
2021-02-14 13:17:24 +00:00
- "git-crypt unlock /tmp/key"
2021-02-12 21:42:16 +00:00
- name: Terraform apply
image: hashicorp/terraform:latest
2021-02-14 13:17:24 +00:00
environment:
TF_VAR_prod: "true"
2021-02-12 21:42:16 +00:00
commands:
2021-05-05 19:17:56 +01:00
- "env"
2021-02-13 02:10:39 +00:00
- "terraform init"
2021-02-14 18:23:49 +00:00
- "terraform apply -target=module.kubernetes_cluster -auto-approve"
2021-02-13 02:10:39 +00:00
2021-02-14 18:23:49 +00:00
- name: Push commit
image: alpine
commands:
- "apk update && apk add openssh-client git git-crypt"
- "mkdir ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts"
- 'chmod 400 secrets/deploy_key'
- "git add ."
- "git remote set-url origin git@github.com:ViktorBarzin/infra.git"
2021-02-19 19:16:31 +00:00
- "git commit -m 'Drone CI deploy commit [CI SKIP]' || echo 'No changes'"
2021-02-14 18:23:49 +00:00
- "GIT_SSH_COMMAND='ssh -i ./secrets/deploy_key -o IdentitiesOnly=yes' git push origin master"
2023-01-22 17:18:57 +00:00
- name: slack
image: plugins/slack
settings:
webhook:
from_secret: slack_webhook
channel: general
when:
status: [ success, failure ]
2021-02-16 00:01:14 +00:00
---
kind: pipeline
type: kubernetes
name: build-cli
2021-04-09 21:16:57 +01:00
concurrency:
limit: 1
trigger:
event:
include:
- push
steps:
- name: Build image
image: plugins/docker
settings:
username: "viktorbarzin"
password:
from_secret: dockerhub_password
repo: viktorbarzin/infra
dockerfile: cli/Dockerfile
context: cli
auto_tag: true
---
kind: secret
name: dockerhub_password
data: 9Gn6YOfsRTMHP3oxQ06d6JsRaZSbUyEYZ256Iiem2ROPy8THs2gsDyL5cgC5gsOt
2021-02-16 00:01:14 +00:00
---
kind: pipeline
type: kubernetes
name: renew-tls-certificate
2021-02-19 00:32:27 +00:00
trigger:
event:
- cron
cron:
2021-04-08 19:07:04 +01:00
- renew-tls-certificate
2021-02-16 00:01:14 +00:00
steps:
- name: Prepare terraform files
image: alpine
commands:
- "apk update && apk add jq curl git git-crypt"
- |
curl -k https://10.0.20.100:6443/api/v1/namespaces/drone/configmaps/git-crypt-key -H "Authorization:Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" | jq -r .data.key | base64 -d > /tmp/key
2021-02-16 00:01:14 +00:00
- "git-crypt unlock /tmp/key"
- name: Run renew script
image: alpine
environment:
TF_VAR_prod: "true"
commands:
- "apk update && apk add git certbot expect curl gzip"
# Install terraform cli
- "curl https://releases.hashicorp.com/terraform/0.14.6/terraform_0.14.6_linux_amd64.zip | gzip -d > /usr/local/bin/terraform && chmod 775 /usr/local/bin/terraform"
- "terraform init"
- "./modules/kubernetes/setup_tls_secret/renew.sh"
- name: Commit updated certificates
image: alpine
commands:
- "apk update && apk add openssh-client git git-crypt"
- "mkdir ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts"
- 'chmod 400 secrets/deploy_key'
- "git add ."
- "git remote set-url origin git@github.com:ViktorBarzin/infra.git"
- "git commit -m 'Drone CI Update TLS Certificates Commit' || echo 'No changes'"
2021-02-16 00:01:14 +00:00
- "GIT_SSH_COMMAND='ssh -i ./secrets/deploy_key -o IdentitiesOnly=yes' git push origin master"