Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/netlify-ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- restore-devsy-sh
- find-dl-site
- add-dl-custom-domain
- find-images-site
- add-images-custom-domain

jobs:
restore-devsy-sh:
Expand Down Expand Up @@ -136,3 +138,106 @@ jobs:
echo ""
echo "Full site info:"
echo "$BODY" | jq '{id, name, custom_domain, subdomain, url, ssl_url}'

find-images-site:
name: Find or Create images.devsy.sh Netlify Site
if: inputs.operation == 'find-images-site'
runs-on: ubuntu-latest
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
steps:
- name: Find or create images.devsy.sh site and output ID
run: |
echo "Listing Netlify sites..."
SITES_RESP=$(curl -s -w "\n%{http_code}" -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
"https://api.netlify.com/api/v1/sites?per_page=100")
SITES_HTTP=$(echo "$SITES_RESP" | tail -1)
SITES=$(echo "$SITES_RESP" | sed '$d')
if [ "$SITES_HTTP" != "200" ]; then
echo "ERROR: Failed to list sites (HTTP $SITES_HTTP)"
echo "$SITES"
exit 1
fi

IMAGES_SITE_ID=$(echo "$SITES" | \
jq -r '.[] | select(.custom_domain == "images.devsy.sh" or .name == "images-devsy-sh") | .id' | head -1)

if [ -n "$IMAGES_SITE_ID" ] && [ "$IMAGES_SITE_ID" != "null" ]; then
IMAGES_SITE_NAME=$(echo "$SITES" | jq -r ".[] | select(.id == \"$IMAGES_SITE_ID\") | .name")
echo "Found existing site: $IMAGES_SITE_NAME"
else
echo "Site not found. Listing all sites for reference:"
echo "$SITES" | jq '.[] | {id, name, custom_domain, url}' | head -100
echo ""
echo "Creating images-devsy-sh..."
CREATE_RESP_RAW=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "images-devsy-sh"}' \
"https://api.netlify.com/api/v1/sites")
CREATE_HTTP=$(echo "$CREATE_RESP_RAW" | tail -1)
CREATE_RESP=$(echo "$CREATE_RESP_RAW" | sed '$d')
if [ "$CREATE_HTTP" != "200" ] && [ "$CREATE_HTTP" != "201" ]; then
echo "ERROR: Site creation failed (HTTP $CREATE_HTTP)"
echo "$CREATE_RESP"
exit 1
fi
IMAGES_SITE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty')
if [ -z "$IMAGES_SITE_ID" ]; then
echo "ERROR: Site created but no id returned"
echo "$CREATE_RESP"
exit 1
fi
echo "Created: $(echo "$CREATE_RESP" | jq '{id, name, url}')"
fi

echo ""
echo "========================================"
echo "NETLIFY_IMAGES_SITE_ID = $IMAGES_SITE_ID"
echo "========================================"
echo "Run: gh secret set NETLIFY_IMAGES_SITE_ID --org devsy-org --visibility all --body \"$IMAGES_SITE_ID\""

add-images-custom-domain:
name: Add images.devsy.sh Custom Domain to images-devsy-sh Site
if: inputs.operation == 'add-images-custom-domain'
runs-on: ubuntu-latest
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
IMAGES_SITE_ID: ${{ secrets.NETLIFY_IMAGES_SITE_ID }}
steps:
- name: Add custom domain and report DNS instructions
run: |
if [ -z "$IMAGES_SITE_ID" ]; then
echo "ERROR: NETLIFY_IMAGES_SITE_ID secret is not set. Run find-images-site first."
exit 1
fi
echo "Adding images.devsy.sh as custom domain to site $IMAGES_SITE_ID..."
RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"custom_domain": "images.devsy.sh"}' \
"https://api.netlify.com/api/v1/sites/$IMAGES_SITE_ID")

HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | sed '$d')

if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "201" ]; then
echo "ERROR: Custom domain update failed (HTTP $HTTP_CODE)"
echo "$BODY"
exit 1
fi

echo "Custom domain set (HTTP $HTTP_CODE)"
NETLIFY_SUBDOMAIN=$(echo "$BODY" | jq -r '.subdomain // .name')
echo ""
echo "========================================"
echo "CUSTOM DOMAIN CONFIGURED: images.devsy.sh"
echo "========================================"
echo ""
echo "DNS action required — add this DNS record:"
echo " Type: CNAME"
echo " Name: images"
echo " Value: ${NETLIFY_SUBDOMAIN}.netlify.app"
echo ""
echo "Full site info:"
echo "$BODY" | jq '{id, name, custom_domain, subdomain, url, ssl_url}'
2 changes: 2 additions & 0 deletions sites/images-devsy-sh/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
12 changes: 12 additions & 0 deletions sites/images-devsy-sh/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Devsy Images</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions sites/images-devsy-sh/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build]
base = "sites/images-devsy-sh/"
publish = "dist"
command = "npm install && npm run build"

[[headers]]
for = "/catalog.json"
[headers.values]
Access-Control-Allow-Origin = "*"
Cache-Control = "public, max-age=60"
Loading
Loading