From fb22623632672dfde77a374ee5851f65d7e654f9 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 18 Dec 2021 18:32:44 +0000 Subject: [PATCH 01/28] Disable some potentially destructive steps --- .github/workflows/deploy.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3c9c469d..354e5859 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy +name: Deploy (Test) on: release: @@ -6,7 +6,7 @@ on: jobs: deploy: - name: Deploy + name: Deploy (Test) runs-on: ubuntu-latest env: repository: 'jonnybarnes/jonnybarnes.uk' @@ -83,7 +83,7 @@ jobs: key: ${{ secrets.KEY }} script: | cd ${{ env.newReleaseDir }} - php artisan migrate --force + #php artisan migrate --force - name: 🙏 Bless release uses: appleboy/ssh-action@master @@ -94,14 +94,14 @@ jobs: script: | ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; cd ${{ env.newReleaseDir }} - php artisan horizon:terminate + #php artisan horizon:terminate php artisan config:cache php artisan event:cache php artisan route:cache php artisan view:cache - sudo systemctl restart php-fpm.service - sudo supervisorctl restart all + #sudo systemctl restart php-fpm.service + #sudo supervisorctl restart all - name: 🚾 Clean up old releases uses: appleboy/ssh-action@master From 8aa14c5bbf3e9a81fc0955e8c3d7c86d6498be25 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 18 Dec 2021 18:49:26 +0000 Subject: [PATCH 02/28] Access secrets correctly --- .github/workflows/deploy.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 354e5859..70beafeb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,6 +8,7 @@ jobs: deploy: name: Deploy (Test) runs-on: ubuntu-latest + environment: Deployments env: repository: 'jonnybarnes/jonnybarnes.uk' host: 'jonnybarnes.uk' @@ -27,7 +28,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | [ -d ${{ env.releasesDir }} ] || mkdir ${{ env.releasesDir }} [ -d ${{ env.persistentDir }}/storage ] || mkdir ${{ env.persistentDir }}/storage @@ -49,7 +50,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }} composer install --prefer-dist --no-scripts --no-dev --no-progress --optimize-autoloader --quiet --no-interaction @@ -59,7 +60,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | # Import the environment config cd ${{ env.newReleaseDir }}; @@ -70,7 +71,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }}; php artisan clear-compiled; @@ -80,7 +81,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }} #php artisan migrate --force @@ -90,7 +91,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; cd ${{ env.newReleaseDir }} @@ -108,7 +109,7 @@ jobs: with: host: ${{ env.host }} username: ${{ env.username }} - key: ${{ secrets.KEY }} + key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R jonny .; From 72b49564cab03858b5465c579fd026ef2703eb90 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 20 Dec 2021 18:48:31 +0000 Subject: [PATCH 03/28] Specify ssh details in env secrets --- .github/workflows/deploy.yml | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 70beafeb..864269c5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,8 +26,9 @@ jobs: - name: 🔄 Clone Repository uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | [ -d ${{ env.releasesDir }} ] || mkdir ${{ env.releasesDir }} @@ -48,8 +49,9 @@ jobs: - name: 🎵 Run Composer uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }} @@ -58,8 +60,9 @@ jobs: - name: 🔗 Update Symlinks uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | # Import the environment config @@ -69,8 +72,9 @@ jobs: - name: ✨ Optimize Installation uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }}; @@ -79,8 +83,9 @@ jobs: - name: 🙈 Migrate database uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }} @@ -89,8 +94,9 @@ jobs: - name: 🙏 Bless release uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; @@ -107,8 +113,9 @@ jobs: - name: 🚾 Clean up old releases uses: appleboy/ssh-action@master with: - host: ${{ env.host }} - username: ${{ env.username }} + host: ${{ secrets.DEPLOYMENT_HOST }} + port: ${{ secrets.DEPLOYMENT_PORT }} + username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} From 0d4103d64483ba007037d6a7f43c88a34885d85f Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 20 Dec 2021 18:50:25 +0000 Subject: [PATCH 04/28] Specify target deployment directory in an env secret --- .github/workflows/deploy.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 864269c5..e81a3c71 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,17 +11,14 @@ jobs: environment: Deployments env: repository: 'jonnybarnes/jonnybarnes.uk' - host: 'jonnybarnes.uk' - username: 'jonny' - baseDir: '/var/websites/jonnybarnes.uk-test' newReleaseName: '${{ github.run_id }}' steps: - name: 🌍 Set Environment Variables run: | - echo "releasesDir=${{ env.baseDir }}/releases" >> $GITHUB_ENV - echo "persistentDir=${{ env.baseDir }}/persistent" >> $GITHUB_ENV - echo "currentDir=${{ env.baseDir }}/current" >> $GITHUB_ENV + echo "releasesDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/releases" >> $GITHUB_ENV + echo "persistentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent" >> $GITHUB_ENV + echo "currentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/current" >> $GITHUB_ENV echo "newReleaseDir=${{ env.releasesDir }}/${{ env.newReleaseName }}" >> $GITHUB_ENV - name: 🔄 Clone Repository uses: appleboy/ssh-action@master @@ -67,7 +64,7 @@ jobs: script: | # Import the environment config cd ${{ env.newReleaseDir }}; - ln -nfs ${{ env.baseDir }}/.env .env; + ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/.env .env; - name: ✨ Optimize Installation uses: appleboy/ssh-action@master From 02a38a237f3f443929a875a8fa86000bce5bac73 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 23 Dec 2021 13:23:05 +0000 Subject: [PATCH 05/28] Trying to get directories sorted --- .github/workflows/deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e81a3c71..c38206a0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,10 +29,15 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | [ -d ${{ env.releasesDir }} ] || mkdir ${{ env.releasesDir }} + [ -d ${{ env.persistentDir }} ] || mkdir ${{ env.persistentDir }} [ -d ${{ env.persistentDir }}/storage ] || mkdir ${{ env.persistentDir }}/storage cd ${{ env.releasesDir }} + # A littlw debugging + echo "${{ env.releasesDir }}" + echo "${{ env.newReleaseDir }}" + # Create new release directory mkdir ${{ env.newReleaseDir }} From 1d14f181b048983b66bb48f45c959fad4b0912b5 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 23 Dec 2021 13:28:48 +0000 Subject: [PATCH 06/28] Try setting derived env variable in second step --- .github/workflows/deploy.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c38206a0..2b1471c7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,8 @@ jobs: echo "releasesDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/releases" >> $GITHUB_ENV echo "persistentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent" >> $GITHUB_ENV echo "currentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/current" >> $GITHUB_ENV + - name: 🌎 Set Environment Variables Part 2 + run: | echo "newReleaseDir=${{ env.releasesDir }}/${{ env.newReleaseName }}" >> $GITHUB_ENV - name: 🔄 Clone Repository uses: appleboy/ssh-action@master @@ -34,7 +36,7 @@ jobs: cd ${{ env.releasesDir }} - # A littlw debugging + # A little debugging echo "${{ env.releasesDir }}" echo "${{ env.newReleaseDir }}" From e267534ced4caff6730d97649504323060101d83 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 23 Dec 2021 14:07:47 +0000 Subject: [PATCH 07/28] Only manual deployments --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2b1471c7..2791f3cf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,6 @@ name: Deploy (Test) on: - release: workflow_dispatch: jobs: From d9b4c15c0091e476fcb85200368cb8974da83ae9 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 27 Dec 2021 12:14:54 +0000 Subject: [PATCH 08/28] Remove debugging step for helping set env variables --- .github/workflows/deploy.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2791f3cf..f3c88b9a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,10 +35,6 @@ jobs: cd ${{ env.releasesDir }} - # A little debugging - echo "${{ env.releasesDir }}" - echo "${{ env.newReleaseDir }}" - # Create new release directory mkdir ${{ env.newReleaseDir }} From 0c230d6a62141e88bd6733725f8001a4fe7242e9 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 27 Dec 2021 13:10:29 +0000 Subject: [PATCH 09/28] Use deplopyment user in tifying up step --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f3c88b9a..d1816c73 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -118,5 +118,5 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} - ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R jonny .; + ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.DEPLOYMENT_USER }} .; ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf; From f260b5465e565c136d94c77ec0a1559dd8aa0088 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Tue, 28 Dec 2021 15:02:50 +0000 Subject: [PATCH 10/28] Clone over https --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d1816c73..6c9cc90b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -39,7 +39,7 @@ jobs: mkdir ${{ env.newReleaseDir }} # Clone app - git clone --depth 1 git@github.com:${{ env.repository }} ${{ env.newReleaseName }} + git clone --depth 1 https://github.com/${{ env.repository }} ${{ env.newReleaseName }} # Mark release cd ${{ env.newReleaseDir }} From abd4593bfe4097e49fb05b32afbb3d4be14676da Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 29 Dec 2021 14:46:26 +0000 Subject: [PATCH 11/28] Pull in the main branch instead of develop --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6c9cc90b..9a9aaa88 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -39,7 +39,7 @@ jobs: mkdir ${{ env.newReleaseDir }} # Clone app - git clone --depth 1 https://github.com/${{ env.repository }} ${{ env.newReleaseName }} + git clone --depth 1 --branch main https://github.com/${{ env.repository }} ${{ env.newReleaseName }} # Mark release cd ${{ env.newReleaseDir }} From e2385123122d51528911211c362272ee30ddef6e Mon Sep 17 00:00:00 2001 From: Jonathan Barnes Date: Wed, 29 Dec 2021 17:00:05 +0000 Subject: [PATCH 12/28] Add all persistent data necessary --- .github/workflows/deploy.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9a9aaa88..8f27c682 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -68,6 +68,24 @@ jobs: cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/.env .env; + # Remove the storage directory and replace with persistent data + rm -rf ${{ env.newReleaseDir }}/storage; + cd ${{ env.newReleaseDir }}; + ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; + + # Remove the public/profile-images directory and replace with persistent data + rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; + cd ${{ env.newReleaseDir }}; + ln -nfs ${{ env.baseDir }}/persistent/profile-images public/assets/profile-images; + + # Add the persistent files data + cd ${{ env.newReleaseDir }}; + ln -nfs ${{ env.baseDir }}/persistent/files public/files; + + # Add the persistent fonts data + cd ${{ env.newReleaseDir }}; + ln -nfs ${{ env.baseDir }}/persistent/fonts public/fonts; + - name: ✨ Optimize Installation uses: appleboy/ssh-action@master with: From 750eafea0455cfb1dea18574837532b046efc032 Mon Sep 17 00:00:00 2001 From: Jonathan Barnes Date: Wed, 29 Dec 2021 17:52:38 +0000 Subject: [PATCH 13/28] Set storage link writable as http user --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8f27c682..2382ca4b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,6 +72,7 @@ jobs: rm -rf ${{ env.newReleaseDir }}/storage; cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; + sudo chown --no-dereference ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; From 9f84a9db788d5aaa5e047a12b21a7d9e0541cff2 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 29 Dec 2021 18:03:18 +0000 Subject: [PATCH 14/28] Try relying on underlying permissions --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2382ca4b..8f27c682 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,7 +72,6 @@ jobs: rm -rf ${{ env.newReleaseDir }}/storage; cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; - sudo chown --no-dereference ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; From e03dc5d7d596913586303c730f86045538962a01 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 29 Dec 2021 18:14:14 +0000 Subject: [PATCH 15/28] Try normal chown of storage dir symlink --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8f27c682..dd56b3e8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,6 +72,7 @@ jobs: rm -rf ${{ env.newReleaseDir }}/storage; cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; + sudo chown ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; From 67d48ad69756c8d3712a638fac1bc7eda678d97d Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 29 Dec 2021 18:15:07 +0000 Subject: [PATCH 16/28] Add a debugging line for permissions --- .github/workflows/deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dd56b3e8..4cf1eb3f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,7 +72,8 @@ jobs: rm -rf ${{ env.newReleaseDir }}/storage; cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; - sudo chown ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage + sudo chown ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage; + ls -l | grep storage # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; From e0fd8948cdcc03e48e70b645064546da721a68ef Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 10:33:46 +0000 Subject: [PATCH 17/28] Remove chown of symlink --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4cf1eb3f..8f27c682 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,8 +72,6 @@ jobs: rm -rf ${{ env.newReleaseDir }}/storage; cd ${{ env.newReleaseDir }}; ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage; - sudo chown ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} storage; - ls -l | grep storage # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; From 9fbfc466c050f094eed7867ec3b469a70cd6be0a Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 11:02:48 +0000 Subject: [PATCH 18/28] Run the commands as the HTTP_USER --- .github/workflows/deploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8f27c682..487a3c34 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -95,7 +95,7 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }}; - php artisan clear-compiled; + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan clear-compiled; - name: 🙈 Migrate database uses: appleboy/ssh-action@master @@ -119,10 +119,10 @@ jobs: ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; cd ${{ env.newReleaseDir }} #php artisan horizon:terminate - php artisan config:cache - php artisan event:cache - php artisan route:cache - php artisan view:cache + sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan config:cache + sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan event:cache + sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan route:cache + sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan view:cache #sudo systemctl restart php-fpm.service #sudo supervisorctl restart all From 9f8d9282052f0d11ce1f76d5a18362d2b1c1df3b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 11:08:14 +0000 Subject: [PATCH 19/28] Fix malformed commands due to missing space --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 487a3c34..9f5195f7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -119,10 +119,10 @@ jobs: ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; cd ${{ env.newReleaseDir }} #php artisan horizon:terminate - sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan config:cache - sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan event:cache - sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan route:cache - sudo runuser -u ${{ secrets.HTTP_USER }} --php artisan view:cache + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan config:cache + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan event:cache + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan route:cache + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan view:cache #sudo systemctl restart php-fpm.service #sudo supervisorctl restart all From 1c9d1ed63fa435e495fb1e3abbc15aecfb950902 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 13:13:16 +0000 Subject: [PATCH 20/28] Fix directory permissions for cache directory --- .github/workflows/deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f5195f7..47fae31c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -45,6 +45,9 @@ jobs: cd ${{ env.newReleaseDir }} echo "${{ env.newReleaseName }}" > public/release-name.txt + # Fix cache directory permissions + sudo chown -R ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} bootstrap/cache + - name: 🎵 Run Composer uses: appleboy/ssh-action@master with: From c1874efeaa29b4199a178baa0eb0af7cf1a818a2 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 15:10:02 +0000 Subject: [PATCH 21/28] Use correct base dir for symlinks --- .github/workflows/deploy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 47fae31c..64872ccf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -79,15 +79,15 @@ jobs: # Remove the public/profile-images directory and replace with persistent data rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images; cd ${{ env.newReleaseDir }}; - ln -nfs ${{ env.baseDir }}/persistent/profile-images public/assets/profile-images; + ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/profile-images public/assets/profile-images; # Add the persistent files data cd ${{ env.newReleaseDir }}; - ln -nfs ${{ env.baseDir }}/persistent/files public/files; + ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/files public/files; # Add the persistent fonts data cd ${{ env.newReleaseDir }}; - ln -nfs ${{ env.baseDir }}/persistent/fonts public/fonts; + ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/fonts public/fonts; - name: ✨ Optimize Installation uses: appleboy/ssh-action@master From 428252957a2c19a02a3a1cb845566a6d6c253599 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 17:15:37 +0000 Subject: [PATCH 22/28] =?UTF-8?q?Don=E2=80=99t=20change=20permissions=20ba?= =?UTF-8?q?ck=20to=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 64872ccf..995e8306 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -139,5 +139,4 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} - ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.DEPLOYMENT_USER }} .; ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf; From b58fc8a98b5134c66f9e2d9690167907d09def72 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 17:39:17 +0000 Subject: [PATCH 23/28] Change just the cache folder --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 995e8306..abf10433 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -139,4 +139,5 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} + ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} ./bootstrap/cache; ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf; From 7beddd11e894249d137a168c87679ce196523c06 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 17:47:46 +0000 Subject: [PATCH 24/28] Use the right user when chown-ing for deletion --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index abf10433..f401a9f2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -139,5 +139,5 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.releasesDir }} - ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} ./bootstrap/cache; + ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.DEPLOYMENT_USER }}:${{ secrets.DEPLOYMENT_USER }} ./bootstrap/cache; ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf; From 3b096e473d772bb7991761c3df978d0dfc5d65a8 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 30 Dec 2021 20:03:18 +0000 Subject: [PATCH 25/28] Final deployment script hopefully --- .github/workflows/deploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f401a9f2..8d39cffe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,7 +5,7 @@ on: jobs: deploy: - name: Deploy (Test) + name: Deploy runs-on: ubuntu-latest environment: Deployments env: @@ -109,7 +109,7 @@ jobs: key: ${{ secrets.DEPLOYMENT_KEY }} script: | cd ${{ env.newReleaseDir }} - #php artisan migrate --force + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan migrate --force - name: 🙏 Bless release uses: appleboy/ssh-action@master @@ -121,14 +121,14 @@ jobs: script: | ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }}; cd ${{ env.newReleaseDir }} - #php artisan horizon:terminate + sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan horizon:terminate sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan config:cache sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan event:cache sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan route:cache sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan view:cache - #sudo systemctl restart php-fpm.service - #sudo supervisorctl restart all + sudo systemctl restart php-fpm.service + sudo supervisorctl restart all - name: 🚾 Clean up old releases uses: appleboy/ssh-action@master From 761a32806a32a02cb31a51cf72710df983df7845 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 31 Dec 2021 07:58:33 +0000 Subject: [PATCH 26/28] Fix name as well --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8d39cffe..5a6f727f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy (Test) +name: Deploy on: workflow_dispatch: From 35f30fa5818ab6e37db6423fd7769bb4f2bc118b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 31 Dec 2021 12:39:44 +0000 Subject: [PATCH 27/28] Improve the tidy up step of the deployment --- .github/workflows/deploy.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a6f727f..e659fcbe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -138,6 +138,5 @@ jobs: username: ${{ secrets.DEPLOYMENT_USER }} key: ${{ secrets.DEPLOYMENT_KEY }} script: | - cd ${{ env.releasesDir }} - ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" sudo chown -R ${{ secrets.DEPLOYMENT_USER }}:${{ secrets.DEPLOYMENT_USER }} ./bootstrap/cache; - ls -dt ${{ env.releasesDir }}/* | tail -n +4 | xargs -d "\n" rm -rf; + fd '.+' ${{ env.releasesDir }} -d 1 | head -n -3 | xargs -d "\n" -I'{}' sudo chown -R ${{ secrets.DEPLOYMENT_USER }}:${{ secrets.DEPLOYMENT_USER }} {}/bootstrap/cache; + fd '.+' ${{ env.releasesDir }} -d 1 | head -n -3 | xargs -d "\n" -I'{}' rm -rf {}; From 7194010f1d651c70f45b42ad3bad265bac37240e Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 31 Dec 2021 18:15:17 +0000 Subject: [PATCH 28/28] Use systemd instead of supervisord --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e659fcbe..a482785a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -128,7 +128,7 @@ jobs: sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan view:cache sudo systemctl restart php-fpm.service - sudo supervisorctl restart all + sudo systemctl restart jbuk-horizon.service - name: 🚾 Clean up old releases uses: appleboy/ssh-action@master