231 lines
11 KiB
Markdown
231 lines
11 KiB
Markdown
|
|
---
|
|||
|
|
judul: SFA CMS — Deploy 2026-10-06 (Self Registration + Sync Odoo)
|
|||
|
|
proyek: SFA CMS
|
|||
|
|
terkait: Mito · Odoo 18
|
|||
|
|
server: VPS MITO `/var/www/sfa_mito` (ip-172-31-21-236)
|
|||
|
|
kategori: Deploy & Setup
|
|||
|
|
status: Selesai sebagian — lihat §5
|
|||
|
|
tipe: dokumen-internal
|
|||
|
|
tags:
|
|||
|
|
- sfa
|
|||
|
|
- cms
|
|||
|
|
- deploy
|
|||
|
|
- odoo
|
|||
|
|
- self-registration
|
|||
|
|
diperbarui: 2026-10-06
|
|||
|
|
---
|
|||
|
|
[]()
|
|||
|
|
> Index: [[SFA — Index]] · Kategori: **Deploy & Setup**
|
|||
|
|
>
|
|||
|
|
> Log deploy pertama untuk [[SFA — Self Registration]], [[SFA CMS — Sync Master Product dari Odoo]],
|
|||
|
|
> dan [[SFA CMS — Sync Customer dari Odoo]] ke [[SFA CMS — Deployment VPS MITO|VPS MITO]].
|
|||
|
|
> Server **belum production** (masih data uji).
|
|||
|
|
|
|||
|
|
# Deploy 2026-10-06
|
|||
|
|
|
|||
|
|
## 1. Yang Di-deploy
|
|||
|
|
|
|||
|
|
Branch **`develop`** `sfa-cms` sampai commit `8d5f815`:
|
|||
|
|
|
|||
|
|
| Commit | Isi |
|
|||
|
|
|---|---|
|
|||
|
|
| `af6a6e3` | Review & aktivasi Self Registration (migration, Filament, policy, `canAccessPanel`) |
|
|||
|
|
| `647dd0e` | `.gitignore` untuk `.env.*`, secret, dump database |
|
|||
|
|
| `8d5f815` | Sync master product & customer dari Odoo 18 + jadwal harian |
|
|||
|
|
|
|||
|
|
> [!warning] Server mengikuti `main` menurut [[SFA CMS — Deployment VPS MITO]], perubahan ini ada di `develop`
|
|||
|
|
> Sebelum deploy berikutnya: merge `develop` → `main`, atau putuskan server memang ikut `develop`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 2. Langkah yang Dijalankan
|
|||
|
|
|
|||
|
|
Semua perintah aplikasi dijalankan sebagai **`ubuntu`** (user PHP-FPM pool `sfa_mito`), bukan
|
|||
|
|
root — kalau artisan jalan sebagai root, file baru di `storage/` & `bootstrap/cache/` jadi
|
|||
|
|
milik root dan panel bisa error 500.
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd /var/www/sfa_mito
|
|||
|
|
|
|||
|
|
# 1. Backup (pertama kali ada backup DB sfa_mito)
|
|||
|
|
mysqldump -u sfa_mito -p --single-transaction --no-tablespaces --routines --triggers \
|
|||
|
|
sfa_mito > ~/backup_sfa_mito_$(date +%F_%H%M).sql
|
|||
|
|
# → /root/backup_sfa_mito_2026-10-06_0433.sql (7.3 MB)
|
|||
|
|
|
|||
|
|
# 2. .env: ODOO_URL, ODOO_DB, MITO_API_KEY (backup .env.bak_2026-10-06)
|
|||
|
|
|
|||
|
|
# 3. Aplikasi
|
|||
|
|
sudo -u ubuntu composer install --no-dev --optimize-autoloader
|
|||
|
|
sudo -u ubuntu php artisan migrate --force \
|
|||
|
|
--path=database/migrations/2025_10_20_000008_add_denormalized_columns_to_product_table.php
|
|||
|
|
sudo -u ubuntu php artisan migrate --force \
|
|||
|
|
--path=database/migrations/2026_10_01_000001_create_customer_registration_tables.php
|
|||
|
|
sudo -u ubuntu php artisan shield:generate --resource=CustomerRegistrationResource --option=permissions --panel=admin
|
|||
|
|
sudo -u ubuntu php artisan config:clear
|
|||
|
|
sudo -u ubuntu php artisan filament:cache-components
|
|||
|
|
sudo -u ubuntu php artisan route:clear
|
|||
|
|
systemctl reload php8.3-fpm
|
|||
|
|
|
|||
|
|
# 4. Cron (user ubuntu)
|
|||
|
|
crontab -u ubuntu -e
|
|||
|
|
# * * * * * cd /var/www/sfa_mito && php artisan schedule:run >> /dev/null 2>&1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
Verifikasi: tabel `customer_registration*` (3) dan kolom `users.user_type` → OK.
|
|||
|
|
`schedule:list` → `odoo:sync-products` 01:00 & `odoo:sync-customers` 01:15 (Asia/Jakarta).
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 3. Masalah & Penanganan
|
|||
|
|
|
|||
|
|
### 3.1 `php artisan migrate` gagal: `Table 'app_params' already exists`
|
|||
|
|
|
|||
|
|
Tabel DB server dibuat dari dump, bukan migration, jadi tabel `migrations` tidak mencatat
|
|||
|
|
migration rekonstruksi `2025_10_20_000001`–`000009`. `migrate` biasa mencoba membuat ulang
|
|||
|
|
semua tabel dan gagal di langkah pertama (tidak ada yang berubah).
|
|||
|
|
|
|||
|
|
**Penanganan:** jalankan migration yang dibutuhkan saja dengan `--path` (keduanya idempotent):
|
|||
|
|
`000008` (kolom `brand_name`, `product_classification`, `product_category` — dibutuhkan sync
|
|||
|
|
product) dan `2026_10_01_000001` (self registration). `000001`–`000007` & `000009`
|
|||
|
|
**jangan dijalankan** di server.
|
|||
|
|
|
|||
|
|
> [!danger] Sampai diperbaiki, `php artisan migrate` biasa di server ini SELALU gagal
|
|||
|
|
> Fix permanen (belum dikerjakan): buat migration rekonstruksi melewati tabel yang sudah ada
|
|||
|
|
> (`hasTable`), commit, supaya semua server konsisten. Sementara itu selalu pakai `--path`.
|
|||
|
|
|
|||
|
|
### 3.2 Dry-run sync: semua data lama akan dihapus
|
|||
|
|
|
|||
|
|
| | created | updated | deleted |
|
|||
|
|
|---|---|---|---|
|
|||
|
|
| `odoo:sync-products --dry-run` | 639 | 0 | **191** |
|
|||
|
|
| `odoo:sync-customers --dry-run` | 1259 | 0 | **836** |
|
|||
|
|
|
|||
|
|
`updated=0` → tidak ada data server yang dikenali sebagai data Odoo (kunci `product_id` /
|
|||
|
|
`cust_code` masih kode CMS). Sync membuat baris **baru** lalu soft delete yang lama, sehingga
|
|||
|
|
transaksi (SO, jadwal kunjungan, `invent_trans`) tetap menunjuk ke baris lama.
|
|||
|
|
|
|||
|
|
**Keputusan:** server belum production (data uji) → sync dijalankan apa adanya. Backup ada,
|
|||
|
|
penghapusan hanya soft delete. Customer Odoo tidak punya `ref`/`short_code`, jadi kalau nanti
|
|||
|
|
ada data sungguhan yang harus dipertahankan, pencocokan hanya bisa lewat nama/HP.
|
|||
|
|
|
|||
|
|
Master baru yang ikut terbentuk: 15 kategori product, ±37 area/channel (SHOPEE, LAZADA,
|
|||
|
|
TOKOPEDIA, GT, SC, RESELLER, …), grade `D`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 4. Konfigurasi `.env` yang Ditambah
|
|||
|
|
|
|||
|
|
```env
|
|||
|
|
ODOO_URL=…
|
|||
|
|
ODOO_DB=…
|
|||
|
|
MITO_API_KEY=… # = System Parameter mito_base.api_key di Odoo
|
|||
|
|
# ODOO_TIMEOUT=60
|
|||
|
|
```
|
|||
|
|
API Odoo jalan sebagai user di `mito_base.api_user_id` (**Administrator 12**, diisi pakai
|
|||
|
|
nama — rapuh kalau user di-rename; lebih aman pakai id/login).
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 5. Status & Sisa Pekerjaan
|
|||
|
|
|
|||
|
|
| | Hal | Status |
|
|||
|
|
|---|---|---|
|
|||
|
|
| ✅ | Backup DB | `/root/backup_sfa_mito_2026-10-06_0433.sql` — **sekali saja, belum otomatis** |
|
|||
|
|
| ✅ | Migration product (`000008`) & self registration | |
|
|||
|
|
| ✅ | Permission Shield Customer Registration | |
|
|||
|
|
| ✅ | Cron `schedule:run` (user `ubuntu`) | |
|
|||
|
|
| ⬜ | Sync pertama manual (`odoo:sync-products`, `odoo:sync-customers`) | Belum dikonfirmasi — kalau dilewati, jalan otomatis 01:00/01:15 |
|
|||
|
|
| ⬜ | Cek log sync besok pagi | `storage/logs/odoo-sync-products.log`, `odoo-sync-customers.log` → `error=0` |
|
|||
|
|
| ⬜ | Permission role reviewer | Shield → Roles → Customer Registration |
|
|||
|
|
| ⬜ | Bersihkan transaksi uji yang menunjuk ke produk/customer lama | Sebelum go-live |
|
|||
|
|
| ⬜ | Node API `sfa_api_mito` | Merge `feature/self-registration` → `main`, pull, `filePath=/var/www/sfa_mito/storage/app/public/files`, `pm2 restart` |
|
|||
|
|
| ⬜ | Merge `develop` → `main` sfa-cms | Lihat §1 |
|
|||
|
|
| ⬜ | Fix migration rekonstruksi | Lihat §3.1 |
|
|||
|
|
| ✅ | Fix error `Class …SalesTrackingResource\Pages\Pages\ViewSalesTracking not found` | Commit `6ae2249`: namespace View Sales/Stock Tracking salah sejak `7159e53`, dilewati `--optimize-autoloader` |
|
|||
|
|
| ✅ | Skrip `sfa-cms` + deploy key | Lihat §6 |
|
|||
|
|
| ✅ | Jenkins job `SFA-CMS-DEV` + webhook Gitea | Lihat §7 — deploy otomatis tiap push `develop` |
|
|||
|
|
| ✅ | Hapus contoh `inspire` di `routes/console.php` | Commit `4da680a` (sekaligus uji webhook) |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 6. Skrip `sfa-cms` & Deploy Key
|
|||
|
|
|
|||
|
|
Commit `ddf8642` menambah `scripts/sfa-cms.sh`. Dipasang sekali:
|
|||
|
|
`sudo ln -sf /var/www/sfa_mito/scripts/sfa-cms.sh /usr/local/bin/sfa-cms`.
|
|||
|
|
|
|||
|
|
| Perintah | Isi |
|
|||
|
|
|---|---|
|
|||
|
|
| `sfa-cms deploy` | `git pull --ff-only` branch aktif → `composer install --no-dev -o` → migration baru (konfirmasi, `2025_10_20_*` dilewati, per file `--path`) → clear/rebuild cache → reload PHP-FPM |
|
|||
|
|
| `sfa-cms restart` | Perbaiki owner `storage`/`bootstrap/cache`, clear cache, reload PHP-FPM (setelah ubah `.env`) |
|
|||
|
|
| `sfa-cms status` | Branch/commit, nginx/php-fpm/mysql, cron, `schedule:list` |
|
|||
|
|
| `sfa-cms logs` | `tail -f` `laravel.log` + log sync Odoo |
|
|||
|
|
|
|||
|
|
**Akses git server (tanpa password):**
|
|||
|
|
|
|||
|
|
| | |
|
|||
|
|
|---|---|
|
|||
|
|
| Git server | **Gitea** `repo.sinerka.id` (bukan GitLab) |
|
|||
|
|
| Deploy key | `/home/ubuntu/.ssh/sfa_cms_deploy` (ed25519, komentar `vps-mito-sfa-cms`), terdaftar di Gitea → sfa-cms → Settings → Deploy Keys, **read-only** |
|
|||
|
|
| SSH Gitea | Port **222** (port 22 `Connection refused`) — diatur di `/home/ubuntu/.ssh/config` |
|
|||
|
|
| Remote | `git@repo.sinerka.id:MITO/sfa-cms.git` |
|
|||
|
|
|
|||
|
|
Hasil `sfa-cms deploy` pertama: `✔ Deploy selesai (develop @ ddf8642)`, tanpa warning PSR-4.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 7. Jenkins — Job `SFA-CMS-DEV`
|
|||
|
|
|
|||
|
|
Server ini adalah **server develop** (production MITO = 5 server, job `MITO_PRODUCTION`).
|
|||
|
|
Jenkins hanya SSH ke VPS lalu menjalankan `sfa-cms deploy --yes` (`--yes` = migration tanpa
|
|||
|
|
konfirmasi, **tanpa backup otomatis** — keputusan: belum production).
|
|||
|
|
|
|||
|
|
| | |
|
|||
|
|
|---|---|
|
|||
|
|
| Job | `SFA-CMS-DEV` (Pipeline), workspace `/var/jenkins_home/workspace/SFA-CMS-DEV` |
|
|||
|
|
| Credential | ID `vps-mito-sfa-ssh` — *SSH Username with private key*, user `ubuntu` (key `jenkins-deploy-sfa-cms`, public key di `~ubuntu/.ssh/authorized_keys`, private key sudah dihapus dari server) |
|
|||
|
|
| Perintah | `ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new ubuntu@16.79.56.41 'sfa-cms deploy --yes'` |
|
|||
|
|
| Opsi | `disableConcurrentBuilds()`, `timeout 15 menit` |
|
|||
|
|
| Build pertama | ✅ `Deploy selesai (develop @ ddc96b2)` → `Finished: SUCCESS` |
|
|||
|
|
| Trigger | **Otomatis tiap push ke `develop`** (+ Build Now manual). Generic Webhook Trigger diatur lewat UI job (bukan blok `triggers` di script), token `sfa-cms-token` |
|
|||
|
|
| Webhook Gitea | sfa-cms → Settings → Webhooks: `http://108.137.153.186:8080/generic-webhook-trigger/invoke?token=sfa-cms-token`, POST `application/json`, Push Events, **Branch filter `develop`** |
|
|||
|
|
| Uji | Push `4da680a` → webhook → build otomatis ✅ |
|
|||
|
|
|
|||
|
|
```groovy
|
|||
|
|
pipeline {
|
|||
|
|
agent any
|
|||
|
|
options { disableConcurrentBuilds(); timeout(time: 15, unit: 'MINUTES') }
|
|||
|
|
stages {
|
|||
|
|
stage('Deploy SFA CMS (dev)') {
|
|||
|
|
steps {
|
|||
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'vps-mito-sfa-ssh',
|
|||
|
|
keyFileVariable: 'SSH_KEY', usernameVariable: 'SSH_USER')]) {
|
|||
|
|
sh '''
|
|||
|
|
ssh -i "$SSH_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new \
|
|||
|
|
"$SSH_USER"@16.79.56.41 'sfa-cms deploy --yes'
|
|||
|
|
'''
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
> [!danger] `public/storage` di server = SYMLINK (`storage:link`), bukan folder seperti di lokal
|
|||
|
|
> Git melaporkan `D public/storage/.gitignore` karena itu. **Jangan `git checkout -- public/storage/.gitignore`**
|
|||
|
|
> — git mengganti symlink dengan folder kosong → error `DirectoryNotFoundException …/public/storage/backgrounds`
|
|||
|
|
> (terjadi 06-10-2026). Perbaikan: `rm -rf public/storage && php artisan storage:link` (sebagai `ubuntu`), lalu
|
|||
|
|
> `git update-index --skip-worktree public/storage/.gitignore` supaya git tidak melaporkannya lagi.
|
|||
|
|
|
|||
|
|
Catatan server: `git config core.fileMode false` di `/var/www/sfa_mito` (perubahan permission
|
|||
|
|
`.gitignore` di `storage/` bukan perubahan kode); seluruh folder aplikasi milik `ubuntu:ubuntu`.
|
|||
|
|
|
|||
|
|
> [!note] Catatan webhook
|
|||
|
|
> - **Test Delivery Gitea tidak bisa dipakai untuk menguji** webhook ber-branch filter: Gitea memakai
|
|||
|
|
> commit branch default (`main`), event dilewati, *Recent Deliveries* tetap kosong. Uji dengan push ke `develop`.
|
|||
|
|
> - Generic Webhook Trigger menjalankan **semua job dengan token yang sama** — tiap job wajib token
|
|||
|
|
> sendiri (jangan pakai `mito-develop-token` milik DEPLOY MITO-DEV).
|
|||
|
|
> - Filter branch di sisi Jenkins (Optional filter `$ref` ~ `^refs/heads/develop$`) belum dipasang;
|
|||
|
|
> yang menyaring hanya Gitea. Siapa pun yang tahu token bisa memicu deploy dev.
|
|||
|
|
> - Token `sfa-cms-token` & `mito-production-token` mudah ditebak dan dikirim lewat HTTP — untuk
|
|||
|
|
> production pakai token acak.
|