Skip to content

Commit

Permalink
feat: add deploy directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sgonzalez-at-wiris committed Oct 23, 2023
1 parent da9956c commit 0a1d595
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
"date": "$(date -u +"%FT%T.000Z")",
"published": true,
"url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/mathtype-tinymce-wordpress_${{ github.event.inputs.version }}.zip",
"storename": "MT_WP"
"storename": "MT_WP_TINY"
},
{
"tech": ["php"],
Expand All @@ -78,7 +78,7 @@ jobs:
"date": "$(date -u +"%FT%T.000Z")",
"published": true,
"url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/wordpress-wiris_${{ github.event.inputs.version }}.zip",
"storename": "MT_WP_TINY"
"storename": "MT_WP"
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions deploy/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 0.0
os: linux
files:
- source: manifest.json
destination: /tmp/

file_exists_behavior: OVERWRITE
hooks:
AfterInstall:
- location: postdeploy.sh
runas: root
timeout: 300
68 changes: 68 additions & 0 deletions deploy/postdeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
# Parses manifest.json

## Valid JSON
if ! jq empty /tmp/manifest.json
then
echo "Invalid JSON. Exiting..."
exit 1
fi

NOW=$(date +%Y%m%d)
INPUT=/var/srv/store-manifests/wordpress.json
SQLTMP=/tmp/update.sql
OUTPUT=/var/log/store-dl-upgrades/wordpress.log # use /var/log and logrotate!
ITEMS=($(jq -c '.items[]' /tmp/manifest.json))

# Check if pkg version has changed
for i in ${!ITEMS[@]}
do
STORENAME=$(jq ".items[$i].storename" /tmp/manifest.json)
VERSION=$(jq ".items[$i].version" /tmp/manifest.json)

if [ -z $(jq ".items[] | select(.storename == $STORENAME) | .storename" /var/srv/store-manifests/wordpress.json) ] || \
[ ! -z $(jq ".items[] | select(.storename == $STORENAME) | select(.version!=$VERSION) | .version" /var/srv/store-manifests/wordpress.json) ]
then
UPDATE=true
fi
done

if [ ! $UPDATE ]
then
echo "No Update needed"
exit 0
fi

# Copy manifest to store manifests directory
mkdir -p /var/srv/store-manifests && cp /tmp/manifest.json $INPUT
mkdir -p /var/log/store-dl-upgrades

# Get all storenames and use them as index loop by object
objects=$(jq -r '.[] | .[] | .storename' $INPUT)

for storetag in $objects ; do
echo "Now processing $storetag..."
object=$(jq -r '.items[] | select(.storename=="'$storetag'")' $INPUT)

published=$(echo -n $object | jq -r '.published')

if [[ $published == "false" ]]
then
echo "Skipping $storetag due to \"published == false\""
continue
fi

url=$(echo -n $object | jq -r '.url' | sed 's/downloads.wiris.com/downloads.wiris.kitchen/')
version=$(echo -n $object | jq -r '.version' | awk 'BEGIN {FS=OFS="."} {if (NF=="4") {NF--; print} else {print}}')

echo "UPDATE downloads SET link='$url', timestamp=CURRENT_TIMESTAMP(), version='$version' WHERE name='$storetag';" >> $SQLTMP
done

echo "Importing resulting SQL $SQLTMP into DB..."
mysql store < $SQLTMP


echo -e "===== $(date -Iseconds) =====" >> $OUTPUT
cat $SQLTMP >> $OUTPUT

rm $SQLTMP

0 comments on commit 0a1d595

Please sign in to comment.