infra/.drone.yml
2025-03-09 13:40:20 +00:00

114 lines
3.8 KiB
YAML

kind: pipeline
type: kubernetes
name: default
concurrency:
limit: 1
trigger:
event:
- push
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
- "git-crypt unlock /tmp/key"
- name: Terraform apply
image: hashicorp/terraform:latest
environment:
TF_VAR_prod: "true"
commands:
- "env"
- "terraform init"
- "terraform apply -target=module.kubernetes_cluster -auto-approve"
- 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"
- "git commit -m 'Drone CI deploy commit [CI SKIP]' || echo 'No changes'"
- "GIT_SSH_COMMAND='ssh -i ./secrets/deploy_key -o IdentitiesOnly=yes' git push origin master"
- name: slack
image: plugins/slack
settings:
webhook:
from_secret: slack_webhook
channel: general
when:
status: [success, failure]
---
kind: pipeline
type: kubernetes
name: build-cli
concurrency:
limit: 1
trigger:
event:
include:
- push
steps:
- name: Build image
image: plugins/docker
settings:
username: "viktorbarzin"
password:
from_secret: dockerhub-pat
repo: viktorbarzin/infra
dockerfile: cli/Dockerfile
context: cli
auto_tag: true
---
kind: pipeline
type: kubernetes
name: renew-tls-certificate
trigger:
event:
- cron
cron:
- renew-tls-certificate
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
- "git-crypt unlock /tmp/key"
- name: Run renew script
image: alpine
environment:
TF_VAR_prod: "true"
TECHNITIUM_API_KEY:
from_secret: TECHNITIUM_API_KEY
CLOUDFLARE_TOKEN:
from_secret: CLOUDFLARE_TOKEN
CLOUDFLARE_ZONE_ID:
from_secret: CLOUDFLARE_ZONE_ID
commands:
- "apk update && apk add git certbot expect curl gzip wget jq"
# Install terraform cli
# - "curl https://releases.hashicorp.com/terraform/1.10.3/terraform_1.10.3_linux_amd64.zip | gzip -d > /usr/local/bin/terraform && chmod 775 /usr/local/bin/terraform"
- "wget -O terraform_1.10.3_linux_amd64.zip https://releases.hashicorp.com/terraform/1.10.3/terraform_1.10.3_linux_amd64.zip && unzip -o terraform_1.10.3_linux_amd64.zip && mv terraform /usr/local/bin/ && chmod 775 /usr/local/bin/terraform"
- "/usr/local/bin/terraform init"
- "./modules/kubernetes/setup_tls_secret/renew2.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'"
- "GIT_SSH_COMMAND='ssh -i ./secrets/deploy_key -o IdentitiesOnly=yes' git pull --rebase origin master"
- "GIT_SSH_COMMAND='ssh -i ./secrets/deploy_key -o IdentitiesOnly=yes' git push origin master"