[WIP] terraform cloudflare provider v5 works! more performance/migration/deployment work todo
This commit is contained in:
1 parent
8295edd35d
commit
45d86424b2
7 files changed
+115
-107
No files matched your search
@@ -41,6 +41,8 @@ jobs:
|
||||
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
|
||||
- nname: TODO migrate and init D1
|
||||
|
||||
- name: Install packages
|
||||
run: |
|
||||
@@ -57,26 +59,6 @@ jobs:
|
||||
run: |
|
||||
npx @cloudflare/next-on-pages
|
||||
|
||||
- name: Remove durable objects bindings (temporary workaround)
|
||||
continue-on-error: true
|
||||
# This is a workaround to fix Cloudflare provider 4.x import crash when there's a durable object binding.
|
||||
run: |
|
||||
# Get bindings without durable objects
|
||||
NEW_BINDINGS=$(curl --request GET --fail-with-body \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
--header 'Content-Type: application/json' | jq '.result.bindings | map(select(.type != "durable_object_namespace"))' -jc)
|
||||
echo "New bindings: $NEW_BINDINGS"
|
||||
|
||||
# Remove durable objects bindings
|
||||
curl --request PATCH --fail-with-body \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
-F 'settings={"bindings":'$NEW_BINDINGS'}'
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
|
||||
- name: Deploy using Terraform
|
||||
# As we don't save terraform state somewhere, we need to import the existing resources
|
||||
run: |
|
||||
@@ -86,8 +68,8 @@ jobs:
|
||||
if [ -n "$KV_ID" ]; then
|
||||
echo "Importing existing resources..."
|
||||
terraform import cloudflare_workers_kv_namespace.uptimeflare_kv "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/$KV_ID"
|
||||
terraform import cloudflare_worker_script.uptimeflare "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/uptimeflare_worker" || echo "WARNING: Worker script import failed, continuing..."
|
||||
terraform import cloudflare_worker_cron_trigger.uptimeflare_worker_cron "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/uptimeflare_worker" || echo "WARNING: Cron trigger import failed, continuing..."
|
||||
terraform import cloudflare_workers_script.uptimeflare_worker "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/uptimeflare_worker" || echo "WARNING: Worker script import failed, continuing..."
|
||||
terraform import cloudflare_workers_cron_trigger.uptimeflare_worker_cron "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/uptimeflare_worker" || echo "WARNING: Cron trigger import failed, continuing..."
|
||||
terraform import cloudflare_pages_project.uptimeflare "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/uptimeflare" || echo "WARNING: Pages project import failed, continuing..."
|
||||
else
|
||||
echo "KV namespace not found, first-time setup."
|
||||
@@ -98,40 +80,6 @@ jobs:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
|
||||
# Terraform Cloudflare provider 4.x doesn't support durable objects, provider 5.x has unresolved issues blocking the deployment. (cloudflare/terraform-provider-cloudflare#5412)
|
||||
# So I have to manually add durable objects bindings here.
|
||||
- name: Add durable objects bindings
|
||||
run: |
|
||||
# Get current bindings
|
||||
CURRENT_BINDINGS=$(curl --request GET --fail-with-body \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
--header 'Content-Type: application/json' | jq '.result.bindings' -jc)
|
||||
CURRENT_BINDINGS="${CURRENT_BINDINGS:1:-1}"
|
||||
echo "Current bindings: $CURRENT_BINDINGS"
|
||||
|
||||
# Try migration first (required for the new durable object class, ignore failures)
|
||||
curl --request PATCH \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
-F 'settings={"bindings":[{"type":"durable_object_namespace","name":"REMOTE_CHECKER_DO","class_name":"RemoteChecker"},'$CURRENT_BINDINGS'],"migrations":{"new_sqlite_classes":["RemoteChecker"],"new_tag":"v1"}}'
|
||||
|
||||
# Actually add the binding
|
||||
curl --request PATCH --fail-with-body \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
-F 'settings={"bindings":[{"type":"durable_object_namespace","name":"REMOTE_CHECKER_DO","class_name":"RemoteChecker"},'$CURRENT_BINDINGS']}'
|
||||
|
||||
# By the ways enable logs
|
||||
curl --request PATCH \
|
||||
--url https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/script-settings \
|
||||
--header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN \
|
||||
--header 'Content-Type: application/json' \
|
||||
-d '{"observability":{"enabled":true}}'
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
|
||||
# Currently Terraform Cloudflare provider doesn't support direct upload, use wrangler to upload instead.
|
||||
- name: Upload pages
|
||||
run: |
|
||||
|
||||
Reference in new issue
Block a user