Currently, my Flarum code is hosted on Github.
I test all modifications on my development environment. Once my developments validated, I commit modifications on my main branch and Gitub Actions deploy code on my production server using Deployer.
If you are interested in this approach, I share here my configuration.
First install Deployer:
composer require --dev deployer/deployer
My Github Actions configuration, using the deployer action:
name: DevOps
on:
[push, pull_request]
env:
phpVersion: '8.1'
jobs:
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ env.phpVersion }}
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install PHP dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-scripts
- name: Deploy
uses: deployphp/action@v1
env:
DEP_PATH: ${{ secrets.DEP_PATH }}
with:
private-key: ${{ secrets.SSH_PRIVATE_KEY }}
known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
dep: deploy -v
My Deployer configuration:
<?php
namespace Deployer;
require 'recipe/composer.php';
require 'contrib/cachetool.php';
// Project
set('application', 'forums');
set('repository', 'git@github.com:Me/{{application}}.git');
// Shared files/dirs between deploys
add('shared_files', [
'config.php',
]);
add('shared_dirs', [
'public/assets',
'public/sitemaps',
'storage'
]);
// Writable dirs by web server
add('writable_dirs', []);
// Path
set('deploy_path', getenv('DEP_PATH'));
// Hosts
host('xxx')
->setRemoteUser('xxx')
->setPort(xxx);
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// ------------------------------------------------------------- Task: cachetool
set('bin/cachetool', '/usr/local/bin/cachetool.phar');
set('cachetool', '/var/run/php-fpm/www.sock');
after('deploy:symlink', 'cachetool:clear:opcache');
after('deploy:symlink', 'cachetool:clear:apcu');
after('deploy:symlink', 'cachetool:clear:stat');
// ---------------------------------------------------------------- Task: deploy
desc('Call flarum to rebuild cache.');
task('deploy:rebuild_cache', function () {
run('{{bin/php}} {{release_path }}/flarum migrate');
run('{{bin/php}} {{release_path }}/flarum assets:publish');
run('{{bin/php}} {{release_path }}/flarum cache:clear');
});
before('deploy:symlink', 'deploy:rebuild_cache');
I use deployer for after each deployment for:
- Purge opcache.
- Purge Flarum cache.
- Migrate Flarum.
- Publish assets.