Skip to content

Commit

Permalink
Merge pull request #441 from kenjis/update-deploy.sh
Browse files Browse the repository at this point in the history
chore: improve deploy workflow
  • Loading branch information
kenjis authored May 18, 2024
2 parents 9bb8e6f + 291ba41 commit baad5ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
#!/bin/sh -e

# Deploys to the production server.
# Deploys the official site to the production server.
# See ../workflows/deploy.yml

REPO="/opt/website"
RELEASE_DIR="/home/public_html/site/releases"
SHARED_DIR="/home/public_html/site/shared"
USERGUIDE_DIR="/home/public_html/userguides"
CONFIG_FILE="/home/public_html/config/.env.site"

if [ "$(id -u)" = "0" ]; then
echo "Cannot be run as root. Please run as the user for deployment."
exit 1
fi

RELEASE=`date +"%Y-%m-%d-%H-%M-%S"`

echo $'Update website repository\n'
echo 'Update website repository\n'
cd $REPO
git switch master
git pull

echo $'Copy current release\n'
echo 'Copy current release\n'
cd $RELEASE_DIR
sudo cp -pr $REPO ./$RELEASE

echo $'Install composer dependencies\n'
echo 'Install composer dependencies\n'
cd $RELEASE_DIR/$RELEASE
composer install --no-dev

if [ ! -d "$SHARED_DIR" ]; then
echo $'Create shared directory\n'
echo 'Create shared directory\n'
sudo mkdir -p "$SHARED_DIR"
echo $'Setup folder permissions\n'
echo 'Setup folder permissions\n'
sudo chown -R www-data:www-data writable
sudo chmod -R 755 writable
sudo cp -rp writable "$SHARED_DIR"
fi

echo $'Link writable\n'
echo 'Link writable\n'
sudo rm -rf writable
sudo ln -nsf "$SHARED_DIR/writable" writable

echo $'Link .env\n'
echo 'Link .env\n'
sudo ln -nsf $CONFIG_FILE .env

echo $'Link user guides\n'
echo 'Link user guides\n'
ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
ln -nsf $USERGUIDE_DIR/userguide3 public/userguide3
ln -nsf $USERGUIDE_DIR/userguide2 public/userguide2

echo $'Deploy: update symlink\n'
echo 'Deploy: update symlink\n'
cd $RELEASE_DIR
sudo ln -nsf $RELEASE_DIR/$RELEASE "../current"

echo $'Reload PHP8.1-FPM\n'
echo 'Reload PHP8.1-FPM\n'
sudo service php8.1-fpm reload
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
fingerprint: ${{ secrets.FINGERPRINT }}
script: /opt/website/.github/scripts/deploy.sh

0 comments on commit baad5ea

Please sign in to comment.