mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect.git
synced 2024-11-14 06:53:16 +00:00
147 lines
6.7 KiB
YAML
147 lines
6.7 KiB
YAML
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
|
|
INFECT_SOURCE_BRANCH: $DRONE_SOURCE_BRANCH
|
|
|
|
commands:
|
|
# Create infect user script and then export it to a remote machine on server creation.
|
|
- echo '#! /usr/bin/env bash' > infect.sh
|
|
- echo 'exec &> >(tee >(nc -N 128.140.94.125 8443))' >> infect.sh
|
|
- echo 'echo "Hello, NetCat!"' >> 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 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
|
|
- echo 'cat /etc/nixos/hardware-configuration.nix' >> infect.sh
|
|
- 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
|
|
|
|
- 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:
|
|
# Read all available machines and export IP of 'ci-sibling'
|
|
# Create DNS entires for main domain and subdomains
|
|
- >
|
|
curl -s -H "Authorization: Bearer $PASSWORD" 'https://api.hetzner.cloud/v1/servers' > .machine.json
|
|
- >
|
|
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/"//' )
|
|
- echo $machineip
|
|
- >
|
|
curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$DOMAIN"
|
|
-H "Authorization: Bearer $CLOUDFLARE_TOKEN"
|
|
-H "Content-Type: application/json"
|
|
- >
|
|
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:
|
|
- sleep 600
|
|
|
|
- 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:
|
|
# Delete our machine called 'ci-sibling' and all the found DNS records on it.
|
|
- >
|
|
curl -s "https://api.hetzner.cloud/v1/servers" -H "Authorization: Bearer $PASSWORD" > .hetzner_servers.json
|
|
- >
|
|
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')
|
|
- >
|
|
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'
|