# Staging Proxmox (Linux standard + Apache + systemd)

Stack sans Docker:
- `storefront` (Next.js) via `systemd`
- `commerce` (Medusa) via `systemd`
- `postgresql` natif
- `redis` natif
- `cms` build statique servi par Apache (optionnel)

## Fichiers fournis

- Playbook YAML: `deploy/staging/linux/proxmox-staging.yml`
- Units systemd: `deploy/staging/linux/files/systemd`
- Vhosts Apache: `deploy/staging/linux/files/apache`
- Exemples env: `deploy/staging/linux/env`
- Script deploy: `deploy/staging/linux/scripts/deploy-staging.sh`
- Script bootstrap CT (one-shot): `deploy/staging/linux/scripts/bootstrap-proxmox-ct.sh`

## Option rapide: script unique dans `/root` du CT

Copie le script sur le CT puis execute:

```bash
chmod +x /root/bootstrap-proxmox-ct.sh
REPO_URL="git@github.com:<org>/<repo>.git" /root/bootstrap-proxmox-ct.sh
```

Exemple avec options:

```bash
REPO_URL="git@github.com:<org>/<repo>.git" \
REPO_BRANCH="main" \
DOMAIN_STOREFRONT="staging.stylunique.fr" \
DOMAIN_COMMERCE="api-staging.stylunique.fr" \
DOMAIN_CMS="cms-staging.stylunique.fr" \
DB_PASSWORD="motdepasse-fort" \
ENABLE_CMS=1 \
/root/bootstrap-proxmox-ct.sh
```

## 1) Provision serveur (Ansible)

Depuis ta machine d'admin:

```bash
ansible-playbook -i <inventory> deploy/staging/linux/proxmox-staging.yml
```

Le playbook installe Apache/PostgreSQL/Redis/Node 20, copie les vhosts et units, puis active les services.

## 2) Installer le code sur la VM/LXC

```bash
sudo mkdir -p /var/www/stylunique
sudo chown -R stylunique:stylunique /var/www/stylunique
sudo -u stylunique git clone <repo_url> /var/www/stylunique
cd /var/www/stylunique
npm ci
npm run build
```

## 3) Variables d'environnement

```bash
sudo cp deploy/staging/linux/env/storefront.env.example /etc/stylunique/env/storefront.env
sudo cp deploy/staging/linux/env/commerce.env.example /etc/stylunique/env/commerce.env
sudo cp deploy/staging/linux/env/cms.env.example /etc/stylunique/env/cms.env
```

Edite les fichiers et renseigne les secrets (`JWT_SECRET`, `COOKIE_SECRET`, Stripe, S3, Mondial Relay).

## 4) Base PostgreSQL

```bash
sudo -u postgres psql
CREATE USER stylunique WITH PASSWORD 'change-me';
CREATE DATABASE stylunique OWNER stylunique;
\q
```

Adapte ensuite `DATABASE_URL` dans `/etc/stylunique/env/commerce.env`.

## 5) Activation des services

```bash
sudo systemctl daemon-reload
sudo systemctl enable --now stylunique-commerce
sudo systemctl enable --now stylunique-storefront
sudo systemctl restart apache2
```

## 6) CMS (optionnel, statique)

```bash
cd /var/www/stylunique
set -a; source /etc/stylunique/env/cms.env; set +a
npm run build -w @stylunique/cms
sudo rsync -a --delete apps/cms/dist/ /var/www/cms-staging/
```

## 7) Mise a jour staging

```bash
chmod +x deploy/staging/linux/scripts/deploy-staging.sh
deploy/staging/linux/scripts/deploy-staging.sh
```

## 8) SSL (recommande)

Ajoute Certbot sur Apache:

```bash
sudo apt-get install -y certbot python3-certbot-apache
sudo certbot --apache -d staging.stylunique.fr -d api-staging.stylunique.fr -d cms-staging.stylunique.fr
```
