Expanded CF DNS setup.

This commit is contained in:
2025-01-01 10:28:09 -05:00
parent 8ec5cdb552
commit 47cca145c4
+31 -21
View File
@@ -43,33 +43,43 @@ jobs:
- name: Setup yq
uses: dcarbone/install-yq-action@v1
- name: Setup go
uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version: 'stable'
- name: Subdomain Check/Creation
id: domain-check
- name: Grab subdomains from Compose
id: compose-domains
env:
CF_API_KEY: ${{ secrets.CF_API_TOKEN }}
CF_API_EMAIL: ${{ secrets.CF_API_EMAIL }}
run: |
echo "Installing flarectl..."
if [ -z $(go env GOBIN) ]; then
export GOBIN=${{ github.workspace }}
yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}') > compose_subdomains.txt
- name: Retrieve subdomains in Cloudflare
uses: addnab/docker-run-action@v3
with:
image: quay.io/aminvakil/flarectl:latest
options: -v ${{ github.workspace }}:/workspace -e CF_API_KEY=${{ secrets.CF_API_TOKEN }} -e CF_API_EMAIL=${{ secrets.CF_API_EMAIL }}
run: |
--json dns list --zone ${{ secrets.CF_ZONE_ID }} --type CNAME --content "trez.wtf" | jq '.[].Name' | sed -e 's|.trez.wtf||g' -e 's|"||g' | sort -u > cloudflare_subdomains.txt
- name: Compare & Create Missing Subdomains
id: compare-subdomains
run: |
diff compose_subdomains.txt cloudflare_subdomains.txt | awk '{print $2}' | sed -e 's|.||g' > missing_subdomains.txt
if [ -s missing_subdomains.txt ]; then
echo "Missing subdomains found. Please add them to Cloudflare."
echo "Missing subdomains:"
cat missing_subdomains.txt
exit 1
else
echo "No missing subdomains found."
fi
go install github.com/cloudflare/cloudflare-go/cmd/flarectl@latest 2>&1
echo "Grabbing most up-to-date subdomain list from Cloudflare..."
./flarectl d l --zone trez.wtf --type CNAME --content trez.wtf | egrep -v 'ID' | awk '{print $5}' > cf_subdomain_list.txt
swag_urls=$(yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}')
for subdomain in $(echo ${swag_urls}); do
if grep -q ${subdomain} cf_subdomain_list.txt; then
echo "Subdomain ${subdomain}.trez.wtf already exists in Cloudflare. Skipping..."
else
echo "Subdomain ${subdomain}.trez.wtf does not exist in Cloudflare. Creating..."
flarectl d c --zone trez.wtf --name ${subdomain} --type CNAME --content trez.wtf --proxy
fi
cat > ${{ github.workspace }}/cloudflare.env <<EOF
CF_API_KEY=${{ secrets.CF_API_TOKEN }}
CF_API_EMAIL=${{ secrets.CF_API_EMAIL }}
EOF
for subdomain in $(cat missing_subdomains.txt); do
echo "Adding ${subdomain} to Cloudflare..."
docker run -it --rm --env-file cloudflare.env quay.io/aminvakil/flarectl:latest dns creeate --zone ${{ secrets.CF_ZONE_ID }} --type CNAME --name "${subdomain}" --content "trez.wtf" --proxy true
done
# docker-compose-test:
# name: Docker Compose Test