Appearance
Deploy to Production
How Labmin LIMS builds, packages, and swaps PHP (vendor/) and Angular Fusion (dist/) artifacts into production, plus the post-deploy Master checklist.
1. Pre-deploy checks
Before merging to master (CI builds dist/ and vendor/ automatically — no local build is needed):
- Commit lockfiles — Keep
package-lock.jsonandcomposer.lockcommitted and in sync. CI usesnpm cifor frontend installs and caches Composervendor/by hashingcomposer.json+composer.lock. - Verify migrations — On local (
STATE=LOCAL), open?feature=migrationsas a Master user and confirm there are no ungenerated schema changes or unshared edits to already-applied migrations. - Never commit build output —
.gitignoreexcludesdist/,dist-incoming/,dist-previous/,vendor/,vendor-incoming/,vendor-previous/, and.npmrc.
2. How CI/CD deploys (push.yml + post-receive)
Pushing to master triggers .gitea/workflows/push.yml, which builds frontend and PHP dependencies in parallel and deploys them atomically with the server's post-receive hook (<project>.git/hooks/post-receive):
text
Push to master
├── BuildFrontend (Node 24): .npmrc → npm ci → npm run build → dist/ (incl. .vite/manifest.json)
└── BuildVendor (PHP 8.4): cache restore or composer install --no-dev → vendor/
│
▼
PushToProd:
1. rsync dist/ → <DEPLOY_DIR>/dist-incoming/
2. rsync vendor/ → <DEPLOY_DIR>/vendor-incoming/
3. git push to server bare repo → runs hooks/post-receive
│
▼
Server (<project>.git/hooks/post-receive):
1. git pull & git submodule update --init --recursive
2. Swap vendor-incoming/ → vendor/ (old kept in vendor-previous/)
3. composer dump-autoload --optimize --no-dev (rebuilds classmap for pulled PHP)
4. Swap dist-incoming/ → dist/ (old kept in dist-previous/)Important details in the pipeline
- Hidden manifest file:
Fusionreadsdist/.vite/manifest.jsonin production. In CI,actions/upload-artifactmust setinclude-hidden-files: trueso.vite/is not dropped. - Optimized classmap on the server: The server's
post-receivehook runscomposer dump-autoload --optimize --no-devaftergit pullso the classmap covers newly pulled module classes on case-sensitive Linux servers. - Automatic browser cache busting: When
STATEisPRODUCTIONorSTAGING,admin/engine.phpconfiguresFusionwith'development' => false.Fusion::assetVersion()returns the MD5 hash ofdist/.vite/manifest.json, causing any open browser tab to perform a clean reload on its next Fusion navigation.
Required CI secrets & variables
Configure these in Gitea repository/org Actions settings when setting up a new LIMS deployment:
| Name | Kind | Purpose |
|---|---|---|
ADMIN_GITEA_TOKEN | Secret | Gitea PAT (package: Read) used for .npmrc and COMPOSER_AUTH |
SSH_USER | Secret | Deployment SSH user on the production server |
SSH_KEY | Secret | Private SSH key for rsync and git push |
SSH_HOST | Variable | Production server hostname |
SSH_DIR | Variable | Path to the bare Git repo on the server (contains hooks/post-receive) |
DEPLOY_DIR | Variable | Live webroot directory where dist-incoming/ and vendor-incoming/ are staged |
3. Server post-receive hook check (upgrading existing servers)
On Labmin servers, the bare Git repository usually lives next to the webroot as a <project>.git folder (the SSH_DIR variable in CI), with the hook at:
text
/var/www/html/<project>.git/hooks/post-receiveOlder LIMS servers often have a post-receive script that only runs git pull, git submodule update, and composer install. That older hook does not handle dist/ or vendor-incoming/.
Before deploying your first Fusion / new-structure module to an existing server, open <project>.git/hooks/post-receive (ensure it remains executable: chmod +x post-receive) and check these five items:
- Swaps
dist-incoming/→dist/— Required for Fusion pages. Without this, PHP will fail in production withFusion: Vite manifest not found. - Swaps
vendor-incoming/→vendor/(with fallback tocomposer installwhenvendor-incoming/isn't present) — Avoids needing Labmin Composer registry credentials on the production server itself. - Runs
composer dump-autoload --optimize --no-devaftergit pull— Rebuilds the optimized classmap for the newly pulled module classes (critical on case-sensitive Linux servers). - Multi-site
SITES=(...)arrays — If one bare repo deploys to several sites (e.g. production, UAT, staging), make sure CI uploadsdist-incoming/andvendor-incoming/to every site directory (or have the hook copy them before swapping) so every site receives the newdist/andvendor/. - Preserves
exit $overall_success— Ensuresgit pushin CI fails visibly if any site inSITESfails to deploy.
Full post-receive script
Check and update SITES before saving
Always preserve the server's existing SITES=(...) paths — do not overwrite a production server's SITES array with the placeholder below.
If a server lists multiple sites in SITES (for example, production, UAT, and staging), CI's rsync step only uploads dist-incoming/ and vendor-incoming/ to DEPLOY_DIR unless configured for each site — make sure every site in SITES receives its own dist-incoming/ and vendor-incoming/ folders (or copy them from DEPLOY_DIR before swapping).
bash
#!/bin/bash
#
# Server-side post-receive hook for the production bare repo.
# Live copy lives at: /var/www/html/<project>.git/hooks/post-receive
# Keep executable: chmod +x post-receive
#
# CI (.gitea/workflows/push.yml) uploads dist-incoming/ and vendor-incoming/
# into the site folder before pushing. After git pull this hook swaps them in
# atomically, keeping the replaced build in dist-previous/ and vendor-previous/.
# IMPORTANT: Unset Git environment variables so they don't
# interfere with commands run in other directories.
unset GIT_DIR
unset GIT_WORK_TREE
# ==========================
# Configuration
# ==========================
LOG_FILE="/var/log/deployments/$(date '+%Y-%m-%d').log"
# UPDATE THIS to match the site folder(s) on this server!
SITES=(
"/var/www/html/<site>.labmin.online"
)
# ==========================
# Logging function
# ==========================
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# ==========================
# Swap <name>-incoming in as <name>, keeping the old one as <name>-previous
# ==========================
swap_in() {
local site_dir="$1"
local name="$2"
local live="$site_dir/$name"
local incoming="$site_dir/$name-incoming"
local previous="$site_dir/$name-previous"
rm -rf "$previous"
if [ -d "$live" ] && ! mv "$live" "$previous"; then
log "❌ ERROR: Could not move $name aside, keeping the current $name"
return 1
fi
if mv "$incoming" "$live"; then
log "✅ $name swapped in (previous build kept in $name-previous)"
return 0
fi
log "❌ ERROR: Could not move $name-incoming into place, restoring previous $name"
[ -d "$previous" ] && mv "$previous" "$live"
return 1
}
# ==========================
# Deploy function
# ==========================
deploy_site() {
local site_dir="$1"
local exit_code=0
local GIT_EXIT=1
# Resolve real absolute path
SITE_DIR_REAL=$(realpath "$site_dir" 2>/dev/null || echo "$site_dir")
log "==================[ Deployment : $site_dir ]=================="
log "🚀 Starting deployment for $site_dir"
log "ℹ️ Real path resolved: $SITE_DIR_REAL"
log "ℹ️ Running as user: $(whoami)"
log "ℹ️ Current working directory: $(pwd)"
if [ ! -d "$SITE_DIR_REAL" ]; then
log "❌ ERROR: Directory $SITE_DIR_REAL does not exist!"
return 1
fi
GIT_BIN=$(which git)
if [ -z "$GIT_BIN" ]; then
log "❌ ERROR: Git not found in PATH"
return 1
fi
log ""
log "==================[ Git Pull ]=================="
if [ -d "$SITE_DIR_REAL/.git" ]; then
before_hash=$($GIT_BIN -C "$SITE_DIR_REAL" rev-parse HEAD 2>/dev/null || echo "unknown")
log "ℹ️ Current commit: $before_hash"
log "ℹ️ Pulling latest code..."
GIT_OUTPUT=$($GIT_BIN -C "$SITE_DIR_REAL" pull 2>&1)
GIT_EXIT=$?
echo "$GIT_OUTPUT" >> "$LOG_FILE"
if [ $GIT_EXIT -ne 0 ]; then
log "❌ ERROR: Git pull failed (exit code $GIT_EXIT)"
log "ℹ️ Git output: $GIT_OUTPUT"
exit_code=1
else
after_hash=$($GIT_BIN -C "$SITE_DIR_REAL" rev-parse HEAD 2>/dev/null || echo "unknown")
if [ "$before_hash" != "$after_hash" ]; then
log "✅ Code updated: ${before_hash:0:7} → ${after_hash:0:7}"
else
log "ℹ️ No code changes (already up to date)"
fi
fi
log ""
log "==================[ Git Submodules ]=================="
log "ℹ️ Updating Git submodules..."
SUBMODULE_OUTPUT=$($GIT_BIN -C "$SITE_DIR_REAL" submodule update --init --recursive 2>&1)
SUBMODULE_EXIT=$?
echo "$SUBMODULE_OUTPUT" >> "$LOG_FILE"
if [ $SUBMODULE_EXIT -ne 0 ]; then
log "❌ ERROR: Failed to update Git submodules (exit code $SUBMODULE_EXIT)"
log "ℹ️ Submodule output: $SUBMODULE_OUTPUT"
exit_code=1
else
log "✅ Git submodules updated successfully"
fi
else
log "ℹ️ No Git repository found at $SITE_DIR_REAL, skipping Git operations"
fi
log ""
log "==================[ Vendor ]=================="
# Use CI's vendor-incoming when present; otherwise fall back to composer install
if [ -d "$SITE_DIR_REAL/vendor-incoming" ]; then
if [ "$GIT_EXIT" -ne 0 ]; then
log "⚠️ Git pull failed, keeping the current vendor (vendor-incoming left in place)"
exit_code=1
elif ! swap_in "$SITE_DIR_REAL" vendor; then
exit_code=1
fi
elif [ -f "$SITE_DIR_REAL/composer.json" ]; then
log "ℹ️ No vendor-incoming found, installing Composer dependencies on the server..."
composer --working-dir="$SITE_DIR_REAL" global config --no-plugins --no-scripts --no-interaction --unset process-timeout 2>/dev/null
COMPOSER_OUTPUT=$(composer install --working-dir="$SITE_DIR_REAL" --no-dev --optimize-autoloader --no-interaction --no-plugins --no-scripts 2>&1)
COMPOSER_EXIT=$?
echo "$COMPOSER_OUTPUT" >> "$LOG_FILE"
if [ $COMPOSER_EXIT -eq 0 ]; then
log "✅ Composer dependencies installed successfully"
else
log "❌ ERROR: Composer install failed (exit code $COMPOSER_EXIT)"
log "ℹ️ Composer output: $COMPOSER_OUTPUT"
exit_code=1
fi
else
log "ℹ️ No composer.json found in $SITE_DIR_REAL, skipping Composer install"
fi
log ""
log "==================[ Autoloader ]=================="
# Rebuild optimized classmap so newly pulled app classes load on Linux
if [ -f "$SITE_DIR_REAL/composer.json" ] && [ -d "$SITE_DIR_REAL/vendor" ]; then
DUMP_OUTPUT=$(composer dump-autoload --working-dir="$SITE_DIR_REAL" --optimize --no-dev --no-interaction --no-plugins --no-scripts 2>&1)
DUMP_EXIT=$?
echo "$DUMP_OUTPUT" | grep -v "does not comply with psr-4" >> "$LOG_FILE"
if [ $DUMP_EXIT -eq 0 ]; then
log "✅ Optimized autoloader generated"
else
log "❌ ERROR: composer dump-autoload failed (exit code $DUMP_EXIT)"
exit_code=1
fi
fi
log ""
log "==================[ Frontend (dist) ]=================="
if [ -d "$SITE_DIR_REAL/dist-incoming" ]; then
if [ "$GIT_EXIT" -ne 0 ]; then
log "⚠️ Git pull failed, keeping the current dist (dist-incoming left in place)"
exit_code=1
elif ! swap_in "$SITE_DIR_REAL" dist; then
exit_code=1
fi
else
log "ℹ️ No dist-incoming found, keeping the current dist"
fi
log "✅ Deployment completed for $SITE_DIR_REAL (exit code: $exit_code)"
echo ""
return $exit_code
}
# ==========================
# Main deployment
# ==========================
log "🚀 Starting deployment process"
echo "" >> "$LOG_FILE"
log ""
overall_success=0
for site in "${SITES[@]}"; do
if deploy_site "$site"; then
log "✅ Successfully deployed $site"
else
log "❌ Failed to deploy $site"
overall_success=1
fi
log "========================================"
log ""
done
if [ $overall_success -eq 0 ]; then
log "🎉 All deployments finished successfully"
else
log "⚠️ Some deployments failed - check logs above"
fi
log "================[ END ]================="
echo ""
exit $overall_success4. Post-deploy Master checklist
Immediately after deployment, open each updated module (/admin/Modules/<Module>/View) as a Master user. LimsRouter displays warning banners automatically whenever anything is pending:
- Run migrations & seeds — Open
?feature=migrationsand run all pending migrations (and seeds if prompted). - Sync access rights — Open
?feature=accessand sync any new or updatedaccess_config.phpentries.Unsynced permissions are denied in production
Unlike local/staging environments, unsynced actions are blocked in production until synced at
?feature=access. - Sync feature flags — Open
?feature=flags(if the module or any submodule hasflag_config.php), sync new flags, and configure global/role/user settings as needed.
5. Rolling back assets or vendor
Because the server's post-receive hook (swap_in) keeps the previous build alongside the live directories before swapping, you can roll back dist/ or vendor/ instantly on the server if needed:
bash
# Inside the live site directory on the server
mv dist dist-broken && mv dist-previous dist
mv vendor vendor-broken && mv vendor-previous vendor