diff --git a/.deployer/hooks/1-building.sh b/.deployer/hooks/1-building.sh new file mode 100644 index 0000000..66a0287 --- /dev/null +++ b/.deployer/hooks/1-building.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# +# Building - Runs immediately after updating the code +# ---- +# +# Environment variables provided by Deployer PHP: +# DEPLOYER_RELEASE_PATH - Absolute path to the new release directory +# DEPLOYER_SHARED_PATH - Absolute path to the shared/ directory +# DEPLOYER_CURRENT_PATH - Absolute path to the current/ symlink +# DEPLOYER_REPO_PATH - Path to the git cache (bare) repository +# DEPLOYER_DOMAIN - Site domain (example.com) +# DEPLOYER_BRANCH - Git branch being deployed +# DEPLOYER_PHP_VERSION - PHP version selected for this site (e.g. 8.4) +# DEPLOYER_PHP - Absolute path to the PHP binary (e.g. /usr/bin/php8.4) +# +# You're automatically in the DEPLOYER_RELEASE_PATH directory at this point: + +echo "→ Building release..." + +if [[ -f composer.json ]]; then + echo "→ Installing Composer dependencies..." + + composer_bin="$(command -v composer || true)" + "${DEPLOYER_PHP}" "${composer_bin}" install --no-interaction --no-dev --optimize-autoloader +fi + +if [[ -f package.json ]]; then + echo "→ Installing frontend dependencies..." + bun install --frozen-lockfile + + echo "→ Building frontend assets..." + bun run build +fi diff --git a/.deployer/hooks/2-releasing.sh b/.deployer/hooks/2-releasing.sh new file mode 100644 index 0000000..ecb867a --- /dev/null +++ b/.deployer/hooks/2-releasing.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# +# Releasing - Runs immediately after building and right before the new release is activated +# ---- +# +# Environment variables provided by Deployer PHP: +# DEPLOYER_RELEASE_PATH - Absolute path to the new release directory +# DEPLOYER_SHARED_PATH - Absolute path to the shared/ directory +# DEPLOYER_CURRENT_PATH - Absolute path to the current/ symlink +# DEPLOYER_REPO_PATH - Path to the git cache (bare) repository +# DEPLOYER_DOMAIN - Site domain (example.com) +# DEPLOYER_BRANCH - Git branch being deployed +# DEPLOYER_PHP_VERSION - PHP version selected for this site (e.g. 8.4) +# DEPLOYER_PHP - Absolute path to the PHP binary (e.g. /usr/bin/php8.4) +# +# You're automatically in the DEPLOYER_RELEASE_PATH directory at this point: + +echo "→ Preparing release..." + +# ---- +# Framework Detection +# ---- + +if [[ -f artisan ]]; then + framework="laravel" +elif [[ -f bin/console ]]; then + framework="symfony" +elif [[ -f spark ]]; then + framework="codeigniter" +fi + +# ---- +# Laravel +# ---- + +if [[ $framework == "laravel" ]]; then + + # + # Ensure shared data + # ---- + + echo "→ Ensuring shared data..." + + mkdir -p "${DEPLOYER_SHARED_PATH}/storage/"{app,framework,logs} + mkdir -p "${DEPLOYER_SHARED_PATH}/storage/framework/"{cache,sessions,views} + "${DEPLOYER_PHP}" artisan storage:link + + echo "→ Ensuring shared sqlite database..." + mkdir -p "${DEPLOYER_SHARED_PATH}/database" + + shared_db="${DEPLOYER_SHARED_PATH}/database/database.sqlite" + touch "${shared_db}" + + release_db="${DEPLOYER_RELEASE_PATH}/database/database.sqlite" + if [ ! -e "${release_db}" ] && [ ! -L "${release_db}" ]; then + ln -s "${shared_db}" "${release_db}" + fi + + echo "→ Ensuring app key exists..." + php artisan key:generate || true + + # + # Run migrations + # ---- + + echo "→ Running migrations..." + "${DEPLOYER_PHP}" artisan migrate --force + + # + # Code caching + # ---- + + echo "→ Optimizing..." + "${DEPLOYER_PHP}" artisan optimize + +fi + +# ---- +# Symfony +# ---- +# Uncomment as needed + +# if [[ $framework == "symfony" ]]; then +# # Ensure shared data +# echo "→ Ensuring shared data..." +# mkdir -p "${DEPLOYER_SHARED_PATH}/var/"{cache,log,sessions} +# +# # Run migrations +# echo "→ Running migrations..." +# "${DEPLOYER_PHP}" bin/console doctrine:migrations:migrate --no-interaction +# +# # Code caching +# echo "→ Clearing cache..." +# "${DEPLOYER_PHP}" bin/console cache:clear +# fi + +# ---- +# CodeIgniter +# ---- +# Uncomment as needed + +# if [[ $framework == "codeigniter" ]]; then +# # Ensure shared data +# echo "→ Ensuring shared data..." +# mkdir -p "${DEPLOYER_SHARED_PATH}/writable/"{cache,logs,session,uploads} +# +# # Run migrations +# echo "→ Running migrations..." +# "${DEPLOYER_PHP}" spark migrate --all +# +# # Code caching +# echo "→ Optimizing..." +# "${DEPLOYER_PHP}" spark optimize +# fi diff --git a/.deployer/hooks/3-finishing.sh b/.deployer/hooks/3-finishing.sh new file mode 100644 index 0000000..258afb9 --- /dev/null +++ b/.deployer/hooks/3-finishing.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +# +# Finishing - Runs after the new release is activated (at this point we're done) +# ---- +# +# Environment variables provided by Deployer PHP: +# DEPLOYER_RELEASE_PATH - Absolute path to the new release directory +# DEPLOYER_SHARED_PATH - Absolute path to the shared/ directory +# DEPLOYER_CURRENT_PATH - Absolute path to the current/ symlink +# DEPLOYER_REPO_PATH - Path to the git cache (bare) repository +# DEPLOYER_DOMAIN - Site domain (example.com) +# DEPLOYER_BRANCH - Git branch being deployed +# DEPLOYER_PHP_VERSION - PHP version selected for this site (e.g. 8.4) +# DEPLOYER_PHP - Absolute path to the PHP binary (e.g. /usr/bin/php8.4) +# +# You're automatically in the DEPLOYER_RELEASE_PATH directory at this point. +# +# Also, PHP-FPM is automatically reloaded for you so you don't have to do it manually: +# sudo systemctl reload "php${DEPLOYER_PHP_VERSION}-fpm" +# + +echo "→ Finished releasing..." diff --git a/README.md b/README.md index a52d500..4da65ac 100644 --- a/README.md +++ b/README.md @@ -44,4 +44,4 @@ This message displays on the page. ## License -MIT +MIT License - see [LICENSE](LICENSE) for details. diff --git a/deployer.yml b/deployer.yml new file mode 100644 index 0000000..67d6b47 --- /dev/null +++ b/deployer.yml @@ -0,0 +1,2 @@ +servers: [] +sites: []