Skip to content

SSH Deploy

SSH Deploy #6

Workflow file for this run

# Based on this tutorial: https://github.com/marketplace/actions/ssh-deploy
name: SSH Deploy
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v1
# Install PHP
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: composer:v2
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, dom, filter, gd, iconv, json, mbstring, pdo
env:
update: true
- name: Check PHP Version
run: php -v
# Install backend dependencies (Composer)
- name: Validate composer.json and composer.lock
run: composer validate
working-directory: ./app
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install
working-directory: ./app
# Prepare .env file for production
- name: Make production envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_APP_ENV: prod
envkey_APP_DEBUG: false
envkey_APP_SECRET: ${{ secrets.APP_SECRET }}
file_name: .env
# Copying files and artifacts via SSH
- name: Copying files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
passphrase: ''
rm: true
source: "./"
target: ${{ secrets.REMOTE_TARGET }}
# Run commands on production
- name: Executing remote ssh commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
passphrase: ''
script: |
rsync -a --exclude={'var','temp'} --delete ${{ secrets.REMOTE_TARGET }} ${{ secrets.REMOTE_TARGET_DEPLOY }}
cd ${{ secrets.REMOTE_TARGET }} && php8.2 bin/console cache:clear