Skip to content

Commit 072b6e3

Browse files
committed
added adeci devblog and fixed cloudflare tunnel conflicting A record issue
1 parent 1085930 commit 072b6e3

File tree

5 files changed

+160
-13
lines changed

5 files changed

+160
-13
lines changed

flake.lock

Lines changed: 109 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
url = "github:natsukium/mcp-servers-nix";
2929
inputs.nixpkgs.follows = "nixpkgs";
3030
};
31+
devblog.url = "github:adeci/devblog";
3132
buildbot-nix = {
3233
url = "github:nix-community/buildbot-nix";
3334
inputs.nixpkgs.follows = "nixpkgs";

inventory/services/cloudflare-tunnel.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _: {
1111
ingress = {
1212
"vault.decio.us" = "http://localhost:8222";
1313
#"auth.decio.us" = "http://localhost:9080";
14+
"adeci.dev" = "http://localhost:3000";
1415
};
1516
};
1617
};

machines/sequoia/configuration.nix

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
_: {
1+
{ inputs, ... }:
2+
{
23
networking = {
34
hostName = "sequoia";
45
};
56

67
time.timeZone = "America/New_York";
8+
9+
# adeci's dev blog
10+
systemd.services.devblog = {
11+
description = "adeci's dev blog";
12+
after = [ "network.target" ];
13+
14+
serviceConfig = {
15+
Type = "simple";
16+
Restart = "always";
17+
RestartSec = "10";
18+
User = "alex";
19+
Group = "users";
20+
ExecStart = "${inputs.devblog.packages.x86_64-linux.default}/bin/devblog";
21+
};
22+
};
23+
24+
# Start the service but don't wait for it during deployment
25+
systemd.targets.multi-user.wants = [ "devblog.service" ];
726
}

modules/cloudflare-tunnel/setup-tunnel.sh

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ for HOSTNAME in $HOSTNAMES; do
121121
# Get everything before the base domain as subdomain
122122
SUBDOMAIN="${HOSTNAME%."$BASE_DOMAIN"}"
123123

124+
# Handle root domain case (when hostname equals base domain)
125+
if [ "$SUBDOMAIN" = "$HOSTNAME" ]; then
126+
SUBDOMAIN="@"
127+
fi
128+
124129
# Get zone ID for this domain
125130
ZONE_RESPONSE=$(curl -sf "https://api.cloudflare.com/client/v4/zones?name=$BASE_DOMAIN" \
126131
-H "Authorization: Bearer $API_TOKEN" \
@@ -133,18 +138,21 @@ for HOSTNAME in $HOSTNAMES; do
133138
exit 1
134139
fi
135140

136-
# Check/Create DNS record
137-
DNS_RECORDS=$(curl -sf \
138-
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=CNAME&name=${HOSTNAME}" \
141+
# Check for existing DNS records (any type)
142+
ALL_RECORDS=$(curl -sf \
143+
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?name=${HOSTNAME}" \
139144
-H "Authorization: Bearer $API_TOKEN" \
140145
-H "Content-Type: application/json")
141146

142-
RECORD_COUNT=$(echo "$DNS_RECORDS" | jq -r '.result | length')
147+
# Check specifically for CNAME records
148+
CNAME_RECORDS=$(echo "$ALL_RECORDS" | jq -r '.result[] | select(.type == "CNAME")')
149+
CNAME_COUNT=$(echo "$CNAME_RECORDS" | jq -s 'length')
150+
143151
TUNNEL_TARGET="$TUNNEL_ID.cfargotunnel.com"
144152

145-
if [ "$RECORD_COUNT" -gt 0 ]; then
146-
RECORD_ID=$(echo "$DNS_RECORDS" | jq -r '.result[0].id')
147-
CURRENT_TARGET=$(echo "$DNS_RECORDS" | jq -r '.result[0].content')
153+
if [ "$CNAME_COUNT" -gt 0 ]; then
154+
RECORD_ID=$(echo "$CNAME_RECORDS" | jq -r '.id')
155+
CURRENT_TARGET=$(echo "$CNAME_RECORDS" | jq -r '.content')
148156

149157
if [ "$CURRENT_TARGET" = "$TUNNEL_TARGET" ]; then
150158
echo "✓ DNS record for ${HOSTNAME} already correct"
@@ -163,6 +171,20 @@ for HOSTNAME in $HOSTNAMES; do
163171
echo "✓ DNS record for ${HOSTNAME} updated"
164172
fi
165173
else
174+
# Check for conflicting A/AAAA records and delete them
175+
CONFLICTING_RECORDS=$(echo "$ALL_RECORDS" | jq -r '.result[] | select(.type == "A" or .type == "AAAA") | .id')
176+
177+
if [ -n "$CONFLICTING_RECORDS" ]; then
178+
echo "Removing conflicting A/AAAA records for ${HOSTNAME}..."
179+
echo "$CONFLICTING_RECORDS" | while read -r record_id; do
180+
if [ -n "$record_id" ]; then
181+
curl -sf -X DELETE \
182+
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$record_id" \
183+
-H "Authorization: Bearer $API_TOKEN" > /dev/null
184+
fi
185+
done
186+
fi
187+
166188
echo "Creating DNS record for ${HOSTNAME}..."
167189
curl -sf -X POST \
168190
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \

0 commit comments

Comments
 (0)