Update aupload-build-npm.md
This commit is contained in:
parent
8be909ab4e
commit
ea0a1f5eea
|
|
@ -0,0 +1,226 @@
|
|||
Mantap 👍
|
||||
Dengan **SvelteKit + Nginx + Gitea**, setup **paling bersih & profesional** adalah:
|
||||
|
||||
> **Auto-deploy via Gitea Actions → build → replace semua file di server**
|
||||
|
||||
Aku susun **end-to-end**, dari SvelteKit sampai Nginx & Gitea Actions. Tinggal copas.
|
||||
|
||||
---
|
||||
|
||||
## 1️⃣ Pastikan SvelteKit mode STATIC (wajib)
|
||||
|
||||
Di `svelte.config.js`:
|
||||
|
||||
```js
|
||||
import adapter from '@sveltejs/adapter-static';
|
||||
|
||||
export default {
|
||||
kit: {
|
||||
adapter: adapter({
|
||||
pages: 'build',
|
||||
assets: 'build',
|
||||
fallback: null
|
||||
})
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Kalau belum:
|
||||
|
||||
```bash
|
||||
npm i -D @sveltejs/adapter-static
|
||||
```
|
||||
|
||||
Build test lokal:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Pastikan folder `build/` muncul.
|
||||
|
||||
---
|
||||
|
||||
## 2️⃣ Setup Nginx (static site)
|
||||
|
||||
Contoh config:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name domainkamu.com;
|
||||
|
||||
root /var/www/sveltekit;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reload:
|
||||
|
||||
```bash
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
📌 Folder target deploy:
|
||||
|
||||
```
|
||||
/var/www/sveltekit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3️⃣ Siapkan server untuk auto-deploy
|
||||
|
||||
### a. Buat user deploy (opsional tapi recommended)
|
||||
|
||||
```bash
|
||||
sudo adduser deploy
|
||||
sudo chown -R deploy:deploy /var/www/sveltekit
|
||||
```
|
||||
|
||||
### b. Setup SSH key (WAJIB)
|
||||
|
||||
Di local / runner:
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519
|
||||
```
|
||||
|
||||
Copy public key:
|
||||
|
||||
```bash
|
||||
ssh-copy-id deploy@SERVER_IP
|
||||
```
|
||||
|
||||
Pastikan bisa login tanpa password:
|
||||
|
||||
```bash
|
||||
ssh deploy@SERVER_IP
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4️⃣ Setup Gitea Actions (CI/CD)
|
||||
|
||||
Di repo SvelteKit kamu, buat folder:
|
||||
|
||||
```bash
|
||||
.gitea/workflows/deploy.yml
|
||||
```
|
||||
|
||||
Isi **FULL deploy pipeline** 👇
|
||||
|
||||
```yaml
|
||||
name: Deploy SvelteKit
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build SvelteKit
|
||||
run: npm run build
|
||||
|
||||
- name: Deploy to server
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USER }}
|
||||
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||
script: |
|
||||
rm -rf /var/www/sveltekit/*
|
||||
rsync -av --delete build/ /var/www/sveltekit/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5️⃣ Set Secrets di Gitea
|
||||
|
||||
Repo → **Settings → Secrets**:
|
||||
|
||||
| Name | Value |
|
||||
| ---------------- | ------------------- |
|
||||
| `SERVER_HOST` | IP / domain server |
|
||||
| `SERVER_USER` | deploy |
|
||||
| `SERVER_SSH_KEY` | **private key SSH** |
|
||||
|
||||
⚠️ SSH key **tanpa passphrase** untuk CI.
|
||||
|
||||
---
|
||||
|
||||
## 6️⃣ Alur yang terjadi otomatis 🚀
|
||||
|
||||
1. `git push origin main`
|
||||
2. Gitea Actions jalan
|
||||
3. `npm run build`
|
||||
4. Server:
|
||||
|
||||
* hapus semua file lama
|
||||
* upload build baru
|
||||
5. Nginx langsung serve versi terbaru
|
||||
|
||||
**ZERO manual upload. ZERO drama.**
|
||||
|
||||
---
|
||||
|
||||
## 7️⃣ Struktur final di server
|
||||
|
||||
```bash
|
||||
/var/www/sveltekit
|
||||
├── index.html
|
||||
├── _app/
|
||||
├── assets/
|
||||
└── favicon.png
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8️⃣ Upgrade level (opsional tapi keren)
|
||||
|
||||
Kalau mau **zero-downtime deploy**:
|
||||
|
||||
```bash
|
||||
/var/www/releases/20260204/
|
||||
ln -sfn releases/20260204 current
|
||||
```
|
||||
|
||||
Atau pakai **versioned deploy + rollback** (tinggal ganti symlink).
|
||||
|
||||
---
|
||||
|
||||
## Ringkasannya 🔥
|
||||
|
||||
✅ Static SvelteKit
|
||||
✅ Nginx simple & cepat
|
||||
✅ Gitea Actions auto deploy
|
||||
✅ Replace semua file server
|
||||
✅ Aman & scalable
|
||||
|
||||
Kalau kamu mau:
|
||||
|
||||
* **subdomain staging**
|
||||
* **HTTPS (Certbot)**
|
||||
* **rollback 1 klik**
|
||||
* **deploy multi environment**
|
||||
|
||||
Loading…
Reference in New Issue