From 56662e7e9f9b9d16490dd73a0e4bfef8d2763e1a Mon Sep 17 00:00:00 2001 From: Koen Date: Wed, 28 Jun 2023 12:23:38 +0200 Subject: [PATCH] Fixed CI/CD to work with Cloudflare. --- receivers/electron/.gitlab-ci.yml | 8 ++------ receivers/electron/deploy.sh | 33 ++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/receivers/electron/.gitlab-ci.yml b/receivers/electron/.gitlab-ci.yml index 999130e..4807b43 100644 --- a/receivers/electron/.gitlab-ci.yml +++ b/receivers/electron/.gitlab-ci.yml @@ -1,11 +1,7 @@ buildAndDeployElectron: stage: buildAndDeployElectron before_script: - - cd receivers/electron/packaging + - cd receivers/electron script: - - npm install - - sh package-all.sh - - cp fcast-receiver-*.zip /var/www/html/fcastreceiver/ - - cp ../package.json /var/www/html/fcastreceiver/ - - cp -r ../dist /var/www/html/fcastreceiver/ + - sh deploy.sh when: manual \ No newline at end of file diff --git a/receivers/electron/deploy.sh b/receivers/electron/deploy.sh index 7f83dea..de404f0 100644 --- a/receivers/electron/deploy.sh +++ b/receivers/electron/deploy.sh @@ -1,7 +1,30 @@ #!/bin/sh +DOCUMENT_ROOT=/var/www/html + +# Build content +echo "Building content..." npm install -npm run build -cp package.json /var/www/html/fcastreceiver/ -cp -r dist /var/www/html/fcastreceiver/ -ls /var/www/html/fcastreceiver -ls /var/www/html/fcastreceiver/dist +cd packaging +sh package-all.sh + +# Take site offline +echo "Taking site offline..." +touch $DOCUMENT_ROOT/maintenance.file + +# Swap over the content +echo "Deploying content..." +cp fcast-receiver-*.zip $DOCUMENT_ROOT/fcastreceiver/ +cd .. +cp package.json $DOCUMENT_ROOT/fcastreceiver/ +cp -r dist $DOCUMENT_ROOT/fcastreceiver/ + +# Notify Cloudflare to wipe the CDN cache +echo "Purging Cloudflare cache..." +curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" \ + -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"purge_everything":true}' + +# Take site back online +echo "Bringing site back online..." +rm $DOCUMENT_ROOT/maintenance.file \ No newline at end of file