Skip to content

Commit 9d9d5a2

Browse files
authored
Merge pull request #439 from kenjis/update-deploy-workflow
chore: update deploy workflow
2 parents 8dfe4b6 + 355f4c7 commit 9d9d5a2

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

.github/scripts/deploy.sh

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,51 @@
22

33
# Deploys to the production server.
44

5-
RELEASE_DIR="/home/public_html/site/releases/"
6-
RSYNC_DIR="/home/public_html/site/latest/"
5+
REPO="/opt/website"
6+
RELEASE_DIR="/home/public_html/site/releases"
7+
SHARED_DIR="/home/public_html/site/shared"
78
USERGUIDE_DIR="/home/public_html/userguides"
89
CONFIG_FILE="/home/public_html/config/.env.site"
910

10-
cd ~/
11-
RELEASE=`date +"%d-%m-%Y-%H-%M-%S"`
11+
RELEASE=`date +"%Y-%m-%d-%H-%M-%S"`
12+
13+
echo $'Update website repository\n'
14+
cd $REPO
15+
git switch master
16+
git pull
1217

1318
echo $'Copy current release\n'
1419
cd $RELEASE_DIR
15-
cp -r ../latest ./$RELEASE
20+
sudo cp -pr $REPO ./$RELEASE
1621

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

21-
echo $'Setup FS\n'
22-
cd $RELEASE_DIR/$RELEASE
23-
sudo chmod -R 777 writable
24-
sudo chmod -R a+rx vendor
26+
if [ ! -d "$SHARED_DIR" ]; then
27+
echo $'Create shared directory\n'
28+
sudo mkdir -p "$SHARED_DIR"
29+
echo $'Setup folder permissions\n'
30+
sudo chown -R www-data:www-data writable
31+
sudo chmod -R 755 writable
32+
sudo cp -rp writable "$SHARED_DIR"
33+
fi
34+
35+
echo $'Link writable\n'
36+
sudo rm -rf writable
37+
sudo ln -nsf "$SHARED_DIR/writable" writable
38+
39+
echo $'Link .env\n'
2540
sudo ln -nsf $CONFIG_FILE .env
2641

27-
echo $'Link current user guide\n'
28-
sudo ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
42+
echo $'Link user guides\n'
43+
ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
44+
ln -nsf $USERGUIDE_DIR/userguide3 public/userguide3
45+
ln -nsf $USERGUIDE_DIR/userguide2 public/userguide2
2946

30-
echo $'Set up Links\n'
47+
echo $'Deploy: update symlink\n'
3148
cd $RELEASE_DIR
3249
sudo ln -nsf $RELEASE_DIR/$RELEASE "../current"
50+
51+
echo $'Reload PHP8.1-FPM\n'
3352
sudo service php8.1-fpm reload

.github/workflows/deploy.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,11 @@ jobs:
1313
with:
1414
ref: master
1515

16-
- name: Install SSH key
17-
uses: shimataro/ssh-key-action@v2
18-
with:
19-
key: ${{ secrets.DEPLOY_KEY }}
20-
name: id_rsa
21-
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
22-
23-
- name: Deploy to Webserver
24-
uses: yeshan333/rsync-deploy-action@v1
25-
id: rsync-deploy-action
26-
with:
27-
ssh_login_username: ${{ secrets.DEPLOY_USER }}
28-
remote_server_ip: ${{ secrets.DEPLOY_SSH_BOX }}
29-
ssh_port: ${{ secrets.DEPLOY_PORT }}
30-
ssh_private_key: ${{ secrets.DEPLOY_KEY }}
31-
source_path: "./*"
32-
destination_path: "/home/public_html/site/latest"
33-
34-
- name: Finalize deployment
16+
- name: executing remote ssh commands using ssh key
3517
uses: appleboy/ssh-action@v1
3618
with:
37-
host: ${{ secrets.DEPLOY_SSH_BOX }}
38-
username: ${{ secrets.DEPLOY_USER }}
39-
key: ${{ secrets.DEPLOY_KEY }}
40-
script: /home/public_html/site/latest/.github/scripts/deploy.sh
19+
host: ${{ secrets.HOST }}
20+
username: ${{ secrets.USERNAME }}
21+
key: ${{ secrets.KEY }}
22+
port: ${{ secrets.PORT }}
23+
script: /opt/website/.github/scripts/deploy.sh

0 commit comments

Comments
 (0)