Skip to content

Commit 0cd6cba

Browse files
committed
update cicd pipeline
1 parent c5a81a8 commit 0cd6cba

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

.github/workflows/cicd.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ jobs:
105105
RATE_LIMIT_AUTH_MAX: ${{ secrets.RATE_LIMIT_AUTH_MAX }}
106106
DB_POOL_MAX: ${{ secrets.DB_POOL_MAX }}
107107
SYNC_ALTER: ${{ secrets.SYNC_ALTER }}
108+
109+
- name: Run seed inside container
110+
run: docker exec vlow-api npm run seed
111+
108112
- name: Add Containers to Tunnel
109113
run: |
110114
docker network connect ${{ secrets.TUNNEL_NAME }} vlow-api || true

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ server/.env
1010
/.pnp
1111
.pnp.js
1212

13-
server/seed.js
1413
server/logs
1514

1615
# testing

client/vite.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export default defineConfig(({ mode }) => {
99
proxy: {
1010
"/api": {
1111
target:
12-
mode === "development"
13-
? "http://localhost:5000"
14-
: "https://myjek-api.srv1213369.hstgr.cloud",
12+
mode === "development" ? "http://localhost:5000" : "https://vlow-api.portproject.my.id",
1513
changeOrigin: true,
1614
secure: mode !== "development",
1715
ws: true,

client/vlow_nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server {
22
listen 8080;
3-
server_name vlow.srv1213369.hstgr.cloud;
3+
server_name vlow.portproject.my.id;
44

55
root /usr/share/nginx/html;
66
index index.html;

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"start": "node server.js",
9+
"seed": "node seed.js",
910
"dev": "nodemon server.js"
1011
},
1112
"keywords": [],

server/seed.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import sequelize from "./config/database.js";
2+
import User from "./models/User.js";
3+
import dotenv from "dotenv";
4+
5+
dotenv.config();
6+
7+
const seedAdmin = async () => {
8+
try {
9+
// 1. Konek Database
10+
await sequelize.authenticate();
11+
console.log("🔌 Database Connected...");
12+
13+
// 2. Pastikan Tabel Ada
14+
await sequelize.sync();
15+
16+
// 3. Cek apakah Admin sudah ada?
17+
const adminExists = await User.findOne({ where: { email: process.env.ADMIN_EMAIL } });
18+
19+
if (adminExists) {
20+
console.log("⚠️ Admin user already exists. Skipping...");
21+
process.exit(0);
22+
}
23+
24+
// 4. Buat Admin Baru
25+
// Password default diset di .env atau hardcoded di sini
26+
const adminPassword = process.env.ADMIN_PASSWORD || "Admin123!";
27+
28+
await User.create({
29+
name: "Super Administrator",
30+
email: process.env.ADMIN_EMAIL || "admin@gmail.com",
31+
password: adminPassword,
32+
role: "admin",
33+
isActive: true,
34+
isFirstLogin: false, // Admin seed tidak perlu ganti password saat login pertama
35+
});
36+
37+
console.log("✅ Super Admin Created Successfully!");
38+
console.log(`📧 Email: ${process.env.ADMIN_EMAIL || "admin@cekat.local"}`);
39+
console.log(`🔑 Pass : ${adminPassword}`);
40+
console.log("-----------------------------------");
41+
console.log("Please login and change your password immediately.");
42+
43+
process.exit(0);
44+
} catch (error) {
45+
console.error("❌ Seeding Failed:", error.message);
46+
process.exit(1);
47+
}
48+
};
49+
50+
seedAdmin();

0 commit comments

Comments
 (0)