Server Deployment
This guide explains how to deploy PCH-SIG on the production server (serveur-production).
Server architecture
Production server
| Parameter | Value |
|---|---|
| IP | serveur-production |
| OS | Windows Server |
| Docker | Docker Toolbox + VirtualBox |
| Docker VM | 192.168.99.100 |
| Project path | C:\pch-sig |
Port mapping
| External port | Destination | Service |
|---|---|---|
| 3000 | 192.168.99.100:80 | Frontend |
| 8000 | 192.168.99.100:8000 | Backend API |
| 8025 | 192.168.99.100:8025 | Mailpit |
| 3001 | 192.168.99.100:3001 | Grafana |
Prerequisites
Server access
PowerShell Remote connection:
$cred = Get-Credential # AdminREDISSEII / Admin1REDISSEIInetwork1
Enter-PSSession -ComputerName serveur-production -Credential $cred
Docker Machine started
docker-machine status default
# Expected: Running
If stopped:
docker-machine start default
Frontend Deployment
Step 1: Local build
On your development machine:
cd frontend
npm install
npm run build
Step 2: Copy to server
# Create a session
$cred = Get-Credential
$session = New-PSSession -ComputerName serveur-production -Credential $cred
# Copy the build
Copy-Item -Path ".\frontend\build\*" -Destination "C:\pch-sig\frontend\build" -ToSession $session -Recurse -Force
# Close the session
Remove-PSSession $session
Step 3: Restart frontend container
On the server:
docker-machine ssh default "cd /c/pch-sig/deploy && docker compose restart frontend"
Backend Deployment
Step 1: Copy files
# Copy backend
Copy-Item -Path ".\backend\*" -Destination "C:\pch-sig\backend" -ToSession $session -Recurse -Force
Step 2: Install dependencies
On the server:
docker exec -it pch_backend composer install --no-dev --optimize-autoloader
Step 3: Run migrations
docker exec -it pch_backend php bin/console doctrine:migrations:migrate --no-interaction
Step 4: Clear cache
docker exec -it pch_backend php bin/console cache:clear --env=prod
docker exec -it pch_backend php bin/console cache:warmup --env=prod
Deployment script
deploy.ps1
# PCH-SIG deployment script
param(
[string]$Component = "all" # all, frontend, backend
)
$ServerIP = "serveur-production"
$RemotePath = "C:\pch-sig"
# Create session
$cred = Get-Credential
$session = New-PSSession -ComputerName $ServerIP -Credential $cred
try {
if ($Component -eq "all" -or $Component -eq "frontend") {
Write-Host "Deploying Frontend..." -ForegroundColor Cyan
# Build
Set-Location frontend
npm run build
Set-Location ..
# Copy
Copy-Item -Path ".\frontend\build\*" -Destination "$RemotePath\frontend\build" -ToSession $session -Recurse -Force
Write-Host "Frontend deployed!" -ForegroundColor Green
}
if ($Component -eq "all" -or $Component -eq "backend") {
Write-Host "Deploying Backend..." -ForegroundColor Cyan
# Copy
Copy-Item -Path ".\backend\src\*" -Destination "$RemotePath\backend\src" -ToSession $session -Recurse -Force
Copy-Item -Path ".\backend\config\*" -Destination "$RemotePath\backend\config" -ToSession $session -Recurse -Force
Write-Host "Backend deployed!" -ForegroundColor Green
}
# Restart services
Invoke-Command -Session $session -ScriptBlock {
& docker-machine ssh default "cd /c/pch-sig/deploy && docker compose restart"
}
Write-Host "Deployment complete!" -ForegroundColor Green
}
finally {
Remove-PSSession $session
}
Port Proxy Configuration
Add redirections
# Frontend
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=80 connectaddress=192.168.99.100
# Backend
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=0.0.0.0 connectport=8000 connectaddress=192.168.99.100
# Mailpit
netsh interface portproxy add v4tov4 listenport=8025 listenaddress=0.0.0.0 connectport=8025 connectaddress=192.168.99.100
# Grafana
netsh interface portproxy add v4tov4 listenport=3001 listenaddress=0.0.0.0 connectport=3001 connectaddress=192.168.99.100
Verify redirections
netsh interface portproxy show all
Remove a redirection
netsh interface portproxy delete v4tov4 listenport=3000 listenaddress=0.0.0.0
Deployment verification
Test access
| Test | URL | Expected |
|---|---|---|
| Frontend | https://sig.ucp-pch.org | Login page |
| API | https://sig.ucp-pch.org/api | API Doc |
| Health | https://sig.ucp-pch.org/api/health | Status OK |
Check containers
docker-machine ssh default "docker ps"
View logs
docker-machine ssh default "docker logs pch_backend --tail 50"
Service Worker Update
After frontend deployment, users must clear their cache:
-
Increment version in
frontend/public/service-worker.js:const CACHE_NAME = 'pch-sig-cache-v3'; // Increment -
Inform users to press
Ctrl+Shift+R
Rollback
Restore a previous version
# Backups are in C:\pch-sig\backups\
# Restore frontend
Copy-Item -Path "C:\pch-sig\backups\frontend-2024-01-15\*" -Destination "C:\pch-sig\frontend\build" -Recurse -Force
# Restart
docker-machine ssh default "cd /c/pch-sig/deploy && docker compose restart frontend"