Merge pull request #40 from maite-l/dev #45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.webstoemp.com/blog/github-actions-deploy-craftcms/ | |
# https://swharden.com/blog/2022-04-24-github-actions-ftp/ | |
name: 🚀 Craft & React Deploy | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
APP_PATH: ~/craft/kortrijk2030 | |
WEB_PATH: ~/subsites/integration.maite-lejeune.be | |
SERVER_PATH: "server" | |
CLIENT_PATH: "client" | |
VITE_API_IMAGES_URL: "https://integration.maite-lejeune.be/files/images/" | |
VITE_API_MAGAZINES_URL: "https://integration.maite-lejeune.be/files/magazines/" | |
jobs: | |
ftp-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🛒 Checkout | |
uses: actions/checkout@v3 | |
# Comment out this section if you deploy your frontend somewhere else | |
- name: 🏗️ Build React app | |
run: | | |
cd ${{env.CLIENT_PATH}} | |
npm install | |
npm run build | |
# Setup container with private SSH Key (used by rsync) | |
- name: 🔑 Load private SSH key | |
uses: webfactory/ssh-agent@v0.7.0 | |
with: | |
ssh-private-key: ${{ secrets.SSH_KEY }} | |
# RSYNC | |
# - rsync [options] ~/localdir ssh_user@ssh_host:destination_directory | |
# - exclude web/uploads is there to avoid deleting user uploaded files w/ --delete-after | |
# - StrictHostKeyChecking=no will automatically add new host keys to the user known hosts files. | |
- name: 🚢 Deploy craft project with rsync | |
run: | | |
rsync -azh --delete-after --exclude={"/.env","/.ddev/","/node_modules/","/.git/","/.github/"} -e "ssh -o StrictHostKeyChecking=no" ./${{env.SERVER_PATH}}/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{env.APP_PATH}} | |
- name: 🚢 Deploy web files with rsync | |
run: | | |
rsync -azh --delete-after --exclude={"index.php","assets","files"} -e "ssh -o StrictHostKeyChecking=no" ./${{env.SERVER_PATH}}/web/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{env.WEB_PATH}} | |
# Comment out this section if you deploy your frontend somewhere else | |
- name: 🚢 Deploy react build wit rsync | |
run: | | |
rsync -azh --delete-after --exclude={"index.php",".htaccess","cpresources","files"} -e "ssh -o StrictHostKeyChecking=no" ./${{env.CLIENT_PATH}}/dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{env.WEB_PATH}} | |
# execute commands on remote server | |
- name: 💻 Execute SSH commmands on remote server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
cd ${{ env.APP_PATH }} | |
mkdir -p storage | |
composer install --no-interaction --no-progress --optimize-autoloader | |
chmod a+x craft | |
php craft db/backup | |
php craft update/composer-install --interactive=0 | |
php craft migrate/all --no-content --interactive=0 | |
php craft project-config/apply | |
php craft migrate --track=content --interactive=0 | |
php craft clear-caches/all |