2023-11-18 02:47:34 +00:00
kind : pipeline
type : exec
name : default
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
2023-11-18 03:07:28 +00:00
DRONE_SOURCE_BRANCH : $DRONE_SOURCE_BRANCH
2023-11-18 02:47:34 +00:00
commands :
# Create infect user script and then export it to a remote machine on server creation.
2023-11-18 03:27:02 +00:00
- echo '#! /usr/bin/env bash' > infect.sh
2023-11-18 03:07:28 +00:00
- echo 'exec &> >(tee >(nc -N 128.140.94.125 8443))' >> infect.sh
2023-11-18 03:43:41 +00:00
- echo 'echo "Hello, NetCat!"' >> infect.sh
2023-11-18 03:49:17 +00:00
- echo "curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$DRONE_SOURCE_BRANCH/nixos-infect | PROVIDER=hetzner DOMAIN=$DOMAIN LUSER=cicdcicd ENCODED_PASSWORD=\"$(printf $USER_PASS | base64)\" CF_TOKEN=$CLOUDFLARE_TOKEN DB_PASSWORD=$USER_PASS API_TOKEN=$USER_PASS HOSTNAME=selfprivacy-ci-test DNS_PROVIDER_TYPE=CLOUDFLARE STAGING_ACME=false NIX_VERSION=2.18.1 NIXOS_CONFIG_NAME=sp-nixos CONFIG_URL=https://git.selfprivacy.org/api/v1/repos/alexoundos/selfprivacy-nixos-top-level/archive/master.tar.gz bash 2>&1 | tee /root/infect.log" >> infect.sh
2023-11-18 15:04:58 +00:00
- echo 'cat /etc/nixos/hardware-configuration.nix' >> 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-18 05:14:02 +00:00
- sleep 360
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"
- >
swaks --to ci@$DOMAIN -s selfprivacy.org -tls -au test@selfprivacy.org -ap $TEST_EMAIL_PASS
- >
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'