feat: D1 upgrade: deployment and migration process DONE!
This commit is contained in:
1 parent
0258ae1ddc
commit
3de3640d17
12 files changed
+278
-76
No files matched your search
@@ -41,8 +41,6 @@ jobs:
|
||||
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
|
||||
- nname: TODO migrate and init D1
|
||||
|
||||
- name: Install packages
|
||||
run: |
|
||||
@@ -59,26 +57,48 @@ jobs:
|
||||
run: |
|
||||
npx @cloudflare/next-on-pages
|
||||
|
||||
- name: Create D1 database and tables
|
||||
run: |
|
||||
python3 deploy/init_d1.py # This sets D1_ID in GITHUB_ENV
|
||||
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
|
||||
- name: Migrate state from KV (if needed)
|
||||
run: |
|
||||
python3 deploy/migrate_kv.py
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
D1_ID: ${{ env.D1_ID }}
|
||||
|
||||
- name: Deploy using Terraform
|
||||
# As we don't save terraform state somewhere, we need to import the existing resources
|
||||
run: |
|
||||
terraform init
|
||||
|
||||
KV_ID=$(curl https://api.cloudflare.com/client/v4/accounts/$TF_VAR_CLOUDFLARE_ACCOUNT_ID/storage/kv/namespaces\?per_page\=100 --header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN | jq -r '.result[] | select(.title == "uptimeflare_kv") | .id')
|
||||
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_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..."
|
||||
DO_RESP=$(curl "https://api.cloudflare.com/client/v4/accounts/$TF_VAR_CLOUDFLARE_ACCOUNT_ID/workers/durable_objects/namespaces?per_page=1000" \
|
||||
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN")
|
||||
|
||||
if echo "$DO_RESP" | jq -e '.result[] | select(.script == "uptimeflare_worker" and .class == "RemoteChecker")' > /dev/null; then
|
||||
echo "Existing Durable Object namespace found for uptimeflare_worker RemoteChecker. No migration needed."
|
||||
else
|
||||
echo "KV namespace not found, first-time setup."
|
||||
echo "No existing Durable Object namespace found for uptimeflare_worker RemoteChecker. Need migration."
|
||||
export TF_VAR_enable_do_migration=true
|
||||
fi
|
||||
|
||||
echo "Try importing existing resources..."
|
||||
terraform import cloudflare_d1_database.uptimeflare_d1 "$TF_VAR_CLOUDFLARE_ACCOUNT_ID/$D1_ID"
|
||||
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..."
|
||||
|
||||
terraform apply -auto-approve -input=false
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
|
||||
D1_ID: ${{ env.D1_ID }}
|
||||
|
||||
# Currently Terraform Cloudflare provider doesn't support direct upload, use wrangler to upload instead.
|
||||
- name: Upload pages
|
||||
|
||||
Reference in new issue
Block a user