Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,51 @@

# Deploys to the production server.

RELEASE_DIR="/home/public_html/site/releases/"
RSYNC_DIR="/home/public_html/site/latest/"
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"

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

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

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

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

echo $'Setup FS\n'
cd $RELEASE_DIR/$RELEASE
sudo chmod -R 777 writable
sudo chmod -R a+rx vendor
if [ ! -d "$SHARED_DIR" ]; then
echo $'Create shared directory\n'
sudo mkdir -p "$SHARED_DIR"
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'
sudo rm -rf writable
sudo ln -nsf "$SHARED_DIR/writable" writable

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

echo $'Link current user guide\n'
sudo ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
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 $'Set up Links\n'
echo $'Deploy: update symlink\n'
cd $RELEASE_DIR
sudo ln -nsf $RELEASE_DIR/$RELEASE "../current"

echo $'Reload PHP8.1-FPM\n'
sudo service php8.1-fpm reload
29 changes: 6 additions & 23 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,11 @@ jobs:
with:
ref: master

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_KEY }}
name: id_rsa
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}

- name: Deploy to Webserver
uses: yeshan333/rsync-deploy-action@v1
id: rsync-deploy-action
with:
ssh_login_username: ${{ secrets.DEPLOY_USER }}
remote_server_ip: ${{ secrets.DEPLOY_SSH_BOX }}
ssh_port: ${{ secrets.DEPLOY_PORT }}
ssh_private_key: ${{ secrets.DEPLOY_KEY }}
source_path: "./*"
destination_path: "/home/public_html/site/latest"

- name: Finalize deployment
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_SSH_BOX }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
script: /home/public_html/site/latest/.github/scripts/deploy.sh
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: /opt/website/.github/scripts/deploy.sh