Prepare Alpine artifact deploy workflow
This commit is contained in:
121
docs/deploy-alpine-update.md
Normal file
121
docs/deploy-alpine-update.md
Normal file
@ -0,0 +1,121 @@
|
||||
# Update Deploy Alpine
|
||||
|
||||
Panduan ini untuk server production Alpine Linux x86_64 RAM 1 GB. Server tidak menjalankan build/compile.
|
||||
|
||||
## 1. Build Artifact Di Mesin Lokal/Build Machine
|
||||
|
||||
Mesin build harus punya Docker.
|
||||
|
||||
```bash
|
||||
./deploy/scripts/build-linux-release.sh
|
||||
```
|
||||
|
||||
Script memakai `node:20-alpine`, menjalankan `npm ci`, `prisma generate`, `next build`, lalu membuat artifact bertanggal:
|
||||
|
||||
```bash
|
||||
abelbirdnest-release-YYYYMMDD-HHMMSS.tar.gz
|
||||
```
|
||||
|
||||
## 2. Upload Artifact Ke Server
|
||||
|
||||
```bash
|
||||
./deploy/scripts/upload-linux-release.sh abelbirdnest@SERVER_IP /opt/abelbirdnest-web
|
||||
```
|
||||
|
||||
Script otomatis memilih artifact terbaru dengan pola `abelbirdnest-release-*.tar.gz`, upload artifact, extract ke:
|
||||
|
||||
```bash
|
||||
/opt/abelbirdnest-web/releases/<timestamp>
|
||||
```
|
||||
|
||||
Lalu update symlink:
|
||||
|
||||
```bash
|
||||
/opt/abelbirdnest-web/current
|
||||
```
|
||||
|
||||
## 3. Prasyarat Server Alpine
|
||||
|
||||
Jalankan sekali di server:
|
||||
|
||||
```bash
|
||||
sudo apk add --no-cache nodejs openssl
|
||||
```
|
||||
|
||||
Pastikan env production ada di:
|
||||
|
||||
```bash
|
||||
/var/www/abelbirdnest-web/AbelBirdNest-Stock/.env.production
|
||||
```
|
||||
|
||||
## 4. Setup Service OpenRC
|
||||
|
||||
Copy template service dari mesin lokal/build machine:
|
||||
|
||||
```bash
|
||||
scp deploy/openrc/abelbirdnest-web abelbirdnest@SERVER_IP:/tmp/abelbirdnest-web
|
||||
ssh abelbirdnest@SERVER_IP
|
||||
sudo mv /tmp/abelbirdnest-web /etc/init.d/abelbirdnest-web
|
||||
sudo chmod +x /etc/init.d/abelbirdnest-web
|
||||
sudo rc-update add abelbirdnest-web default
|
||||
```
|
||||
|
||||
Service menjalankan:
|
||||
|
||||
```bash
|
||||
cd /var/www/abelbirdnest-web/AbelBirdNest-Stock/current
|
||||
PORT=3007 NODE_ENV=production NODE_OPTIONS=--max-old-space-size=512 node server.js
|
||||
```
|
||||
|
||||
## 5. Setelah Upload
|
||||
|
||||
Masuk server:
|
||||
|
||||
```bash
|
||||
ssh abelbirdnest@SERVER_IP
|
||||
cd /var/www/abelbirdnest-web/AbelBirdNest-Stock/current
|
||||
```
|
||||
|
||||
Artifact release dibuat ramping untuk runtime Next.js standalone. Jangan menjalankan `npm install`, `npm run build`, atau `prisma migrate deploy` di server kecil.
|
||||
|
||||
Jika update berikutnya membawa migration database, jalankan migration dari mesin build/admin yang punya dependency lengkap dan akses ke database production. Untuk update UI/app tanpa migration, langsung restart service.
|
||||
|
||||
Load env hanya jika perlu tes manual:
|
||||
|
||||
```bash
|
||||
set -a
|
||||
. /var/www/abelbirdnest-web/AbelBirdNest-Stock/.env.production
|
||||
set +a
|
||||
```
|
||||
|
||||
Restart service:
|
||||
|
||||
```bash
|
||||
sudo rc-service abelbirdnest-web restart
|
||||
sudo rc-service abelbirdnest-web status
|
||||
```
|
||||
|
||||
## 6. Verifikasi
|
||||
|
||||
```bash
|
||||
curl -I http://127.0.0.1:3007/login
|
||||
tail -n 100 /var/log/abelbirdnest-web.err
|
||||
tail -n 100 /var/log/abelbirdnest-web.log
|
||||
```
|
||||
|
||||
Jika memakai reverse proxy, cek domain public setelah service sehat.
|
||||
|
||||
## 7. Rollback Cepat
|
||||
|
||||
Lihat release yang tersedia:
|
||||
|
||||
```bash
|
||||
ls -lt /var/www/abelbirdnest-web/AbelBirdNest-Stock/releases
|
||||
```
|
||||
|
||||
Arahkan `current` ke release sebelumnya:
|
||||
|
||||
```bash
|
||||
sudo ln -sfn /var/www/abelbirdnest-web/AbelBirdNest-Stock/releases/NAMA_RELEASE_LAMA /var/www/abelbirdnest-web/AbelBirdNest-Stock/current
|
||||
sudo rc-service abelbirdnest-web restart
|
||||
```
|
||||
Reference in New Issue
Block a user