selfprivacy-nixos-infect/.drone.yml

147 lines
6.7 KiB
YAML
Raw Normal View History

2023-11-18 02:47:34 +00:00
kind: pipeline
type: exec
name: default
2023-12-04 13:09:11 +00:00
clone:
disable: true
2023-11-18 02:47:34 +00:00
steps:
- name: deploy
environment:
PASSWORD:
from_secret: HETZNER_TOKEN
DOMAIN:
from_secret: DOMAIN
CLOUDFLARE_TOKEN:
from_secret: CLOUDFLARE_TOKEN
USER_PASS:
from_secret: USER_PASS
INFECT_SOURCE_BRANCH: ${DRONE_SOURCE_BRANCH}
2023-11-18 02:47:34 +00:00
commands:
# Create infect user script and then push it to a remote machine on server creation.
2023-11-18 03:27:02 +00:00
- echo '#! /usr/bin/env bash' > infect.sh
- echo "curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$INFECT_SOURCE_BRANCH/nixos-infect | PROVIDER=hetzner DOMAIN=$DOMAIN LUSER=cicdcicd USER_PASS=\"$USER_PASS\" CF_TOKEN=$CLOUDFLARE_TOKEN DB_PASSWORD=\"$USER_PASS\" API_TOKEN=\"$USER_PASS\" HOSTNAME=selfprivacy-ci-test DNS_PROVIDER_TYPE=CLOUDFLARE STAGING_ACME=true NIX_VERSION=2.18.1 NIXOS_CONFIG_NAME=sp-nixos CONFIG_URL=https://git.selfprivacy.org/api/v1/repos/SelfPrivacy/selfprivacy-nixos-template/archive/master.tar.gz SSH_AUTHORIZED_KEY=\"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMBb3yVhYF4slhf1iQCiGLOVcbGKP/MmkQiEMl2un+4K\" bash 2>&1 | tee /root/infect.log" >> infect.sh
2023-11-18 15:16:32 +00:00
- http -v --check-status --ignore-stdin POST https://api.hetzner.cloud/v1/servers Authorization:"Bearer $PASSWORD" name=ci-sibling server_type=cx11 start_after_create:=true image=ubuntu-20.04 user_data=@infect.sh automount:=false location=fsn1
2023-11-18 02:47:34 +00:00
- name: dns
environment:
PASSWORD:
from_secret: HETZNER_TOKEN
CLOUDFLARE_TOKEN:
from_secret: CLOUDFLARE_TOKEN
DOMAIN:
from_secret: DOMAIN
ZONE_ID:
from_secret: ZONE_ID
commands:
2023-11-18 15:16:32 +00:00
# Read all available machines and export IP of 'ci-sibling'
2023-11-18 02:47:34 +00:00
# Create DNS entires for main domain and subdomains
- >
curl -s -H "Authorization: Bearer $PASSWORD" 'https://api.hetzner.cloud/v1/servers' > .machine.json
- >
2023-11-18 15:16:32 +00:00
export machineip=$( for i in {0..24}; do jq 'if .servers['$i'].name == "ci-sibling" then .servers['$i'].public_net.ipv4.ip else null end' .machine.json; done | grep -v null | sed 's/"//' | sed 's/"//' )
2023-11-18 02:47:34 +00:00
- echo $machineip
- >
curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$DOMAIN"
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
2023-11-18 14:32:35 +00:00
-H "Content-Type: application/json"
2023-11-18 02:47:34 +00:00
- >
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
-H "Content-Type: application/json"
--data '{"type":"A","name":"@","content":"'"$$machineip"'","ttl":3600,"priority":10,"proxied":false}'
- >
http --check-status --ignore-stdin POST https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records Authorization:"Bearer $CLOUDFLARE_TOKEN" type=A name=api content=$machineip ttl:=3600 priority:=10 proxied:=false
- >
http --check-status --ignore-stdin POST https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records Authorization:"Bearer $CLOUDFLARE_TOKEN" type=A name=cloud content=$machineip ttl:=3600 priority:=10 proxied:=false
- >
http --check-status --ignore-stdin POST https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records Authorization:"Bearer $CLOUDFLARE_TOKEN" type=A name=password content=$machineip ttl:=3600 priority:=10 proxied:=false
- >
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
-H "Content-Type: application/json"
--data '{"type":"MX","name":"@","content":"'"$$DOMAIN"'","ttl":3600,"priority":10,"proxied":false}'
- >
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
-H "Content-Type: application/json"
--data '{"type":"TXT","name":"_dmarc","content":"v=DMARC1; p=none","ttl":18000,"priority":10,"proxied":false}'
- >
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
-H "Content-Type: application/json"
--data '{"type":"TXT","name":"'"$$DOMAIN"'","content":"v=spf1 a mx ip4:$machineip -all","ttl":18000,"priority":10,"proxied":false}'
- name: sleep
commands:
2023-11-25 19:05:34 +00:00
- sleep 600
2023-11-18 02:47:34 +00:00
- name: test
environment:
DOMAIN:
from_secret: DOMAIN
USER_PASS:
from_secret: USER_PASS
TEST_EMAIL_PASS:
from_secret: TEST_EMAIL_PASS
commands:
- >
dig api.$DOMAIN
- >
http -v --verify=false --check-status --ignore-stdin GET https://api.$DOMAIN/services/status Authorization:"Bearer $USER_PASS"
- >
2023-11-24 10:20:45 +00:00
swaks --to ci@$DOMAIN -s selfprivacy.org -tls -au test@selfprivacy.org -ap $TEST_EMAIL_PASS -ahp
2023-11-18 02:47:34 +00:00
- >
http -v --verify=false --check-status --ignore-stdin GET https://cloud.$DOMAIN/ocs/v2.php/apps/serverinfo/api/v1/info?format=json -a admin:$USER_PASS
- >
echo "File to test nextcloud upload" > file
- >
http -v --verify=false --check-status --ignore-stdin PUT https://cloud.$DOMAIN/remote.php/dav/files/admin/file @file -a admin:$USER_PASS
- >
http -v --verify=false --check-status --ignore-stdin GET https://cloud.$DOMAIN/remote.php/dav/files/admin/file -a admin:$USER_PASS
#- >
#http -v --verify=false --check-status --ignore-stdin GET https://password.$DOMAIN/admin/diagnostics
- name: teardown
environment:
PASSWORD:
from_secret: HETZNER_TOKEN
CLOUDFLARE_TOKEN:
from_secret: CLOUDFLARE_TOKEN
DOMAIN:
from_secret: DOMAIN
ZONE_ID:
from_secret: ZONE_ID
commands:
2023-11-18 15:16:32 +00:00
# Delete our machine called 'ci-sibling' and all the found DNS records on it.
2023-11-18 02:47:34 +00:00
- >
curl -s "https://api.hetzner.cloud/v1/servers" -H "Authorization: Bearer $PASSWORD" > .hetzner_servers.json
- >
2023-11-18 15:16:32 +00:00
export machineid=$( for i in {0..24}; do jq 'if .servers['$i'].name == "ci-sibling" then .servers['$i'].id else null end' .hetzner_servers.json; done | grep -v null | sed 's/"//g')
2023-11-18 02:47:34 +00:00
- >
curl -s -X DELETE "https://api.hetzner.cloud/v1/servers/$machineid" -H "Authorization: Bearer $PASSWORD"
- >
json=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" -H "Authorization: Bearer $CLOUDFLARE_TOKEN" -H "Content-Type: application/json")
- >
echo "$json" > .dns-records.json
- >
result=$(jq -r ".result" <<< "$json")
- >
echo "$ZONE_ID"
- >
echo "$result" | jq '.[] | "\(.id)"' | while read id ; do echo "Deleting $id"; http -v --check-status --ignore-stdin DELETE https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$(echo $id | cut -f 2 -d '"') Authorization:"Bearer $CLOUDFLARE_TOKEN"; done
when:
status:
- failure
- success
- name: switch
environment:
CHANNEL_SWITCHER_KEY:
from_secret: CHANNEL_SWITCHER_KEY
commands:
- >
curl -X POST -H "Authorization: $CHANNEL_SWITCHER_KEY" 'https://channel.selfprivacy.org/nixos-selfpricacy/upgrade'