Skip to content
Snippets Groups Projects
Commit bbfda9de authored by Koen's avatar Koen
Browse files

Added CI/CD.

parent 0541ec4a
No related branches found
No related tags found
No related merge requests found
stages:
- deploy
deploy:
stage: deploy
script:
- sh deploy.sh
only:
- master
#!/bin/sh
\ No newline at end of file
#!/bin/sh
DOCUMENT_ROOT=/var/www/sources
# Take site offline
echo "Taking site offline..."
touch $DOCUMENT_ROOT/maintenance.file
# Swap over the content
echo "Deploying content..."
mkdir -p $DOCUMENT_ROOT/Spotify
cp build/SpotifyIcon.png $DOCUMENT_ROOT/Spotify
cp build/SpotifyConfig.json $DOCUMENT_ROOT/Spotify
cp build/SpotifyScript.js $DOCUMENT_ROOT/Spotify
sh sign.sh $DOCUMENT_ROOT/Spotify/SpotifyScript.js $DOCUMENT_ROOT/Spotify/SpotifyConfig.json
# Notify Cloudflare to wipe the CDN cache
echo "Purging Cloudflare cache for zone $CLOUDFLARE_ZONE_ID..."
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 '{"files":["https://plugins.grayjay.app/Spotify/SpotifyIcon.png", "https://plugins.grayjay.app/Spotify/SpotifyConfig.json", "https://plugins.grayjay.app/Spotify/SpotifyScript.js"]}'
# Take site back online
echo "Bringing site back online..."
rm $DOCUMENT_ROOT/maintenance.file
\ No newline at end of file
sign.sh 0 → 100644
#!/bin/sh
# Parameters
JS_FILE_PATH=$1
CONFIG_FILE_PATH=$2
# Decode and save the private key to a temporary file
echo "$SIGNING_PRIVATE_KEY" | base64 -d > tmp_private_key.pem
# Validate private key
if ! openssl rsa -check -noout -in tmp_private_key.pem > /dev/null 2>&1; then
echo "Invalid private key."
rm tmp_private_key.pem
exit 1
fi
# Generate signature for the provided JS file
SIGNATURE=$(cat $JS_FILE_PATH | openssl dgst -sha512 -sign tmp_private_key.pem | base64 -w 0)
# Extract public key from the temporary private key file
PUBLIC_KEY=$(openssl rsa -pubout -outform DER -in tmp_private_key.pem 2>/dev/null | openssl pkey -pubin -inform DER -outform PEM | tail -n +2 | head -n -1 | tr -d '\n')
echo "PUBLIC_KEY: $PUBLIC_KEY"
# Remove temporary key files
rm tmp_private_key.pem
# Update "scriptSignature" and "scriptPublicKey" fields in Config JSON
cat $CONFIG_FILE_PATH | jq --arg signature "$SIGNATURE" --arg publicKey "$PUBLIC_KEY" '. + {scriptSignature: $signature, scriptPublicKey: $publicKey}' > temp_config.json && mv temp_config.json $CONFIG_FILE_PATH
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment