Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy Project-CL

on:
push:
branches:
- main

jobs:
deploy:
name: Build and Deploy
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create env
run: |
echo "${{ secrets.DB_HOST }}" > .env

- name: Restart docker
run: |
echo "Restarting docker"
docker compose down
docker compose up -d --build
echo "Docker restarted"

- name: Clean up
run: |
echo "Cleaning up"
docker image prune -f
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
.idea
.env*
.idea
docker-compose.override.yml
2 changes: 0 additions & 2 deletions Backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ WORKDIR /app

# Ambil hasil build dari Tahap 1
COPY --from=builder /app/server .
# Copy file .env juga (PENTING biar connect DB)
COPY .env .

# Buka Port 8080 (Sesuaikan kalau main.go kamu pakai port lain)
EXPOSE 8080
Expand Down
12 changes: 9 additions & 3 deletions Backend/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ var DB *gorm.DB
func ConnectDB() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
err = godotenv.Load("../.env")
}

dbHost := "db"
if err != nil {
fmt.Println("⚠️ Warning: No .env file found. Relying on System/Docker Environment Variables.")
} else {
fmt.Println("✅ Success loading .env file")
}

dbHost := os.Getenv("DB_HOST")
dbUser := os.Getenv("DB_USER")
dbPass := os.Getenv("DB_PASSWORD")
dbName := os.Getenv("DB_NAME")
dbPort := "5432"
dbPort := os.Getenv("DB_PORT")

dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", dbHost, dbUser, dbPass, dbName, dbPort)

Expand Down
3 changes: 2 additions & 1 deletion Frontend/project-CL/src/services/api.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from "axios";

const api = axios.create({
baseURL: "http://100.111.195.90:8080/api",
baseURL: import.meta.env.VITE_API_BASE_URL,
withCredentials: true,
timeout: 5000,
headers: {
"Content-Type": "application/json",
Expand Down
9 changes: 2 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ services:
restart: always
ports:
- "8080:8080"
env_file:
- .env
depends_on:
- db
environment:
# PENTING: Koneksi ke DB pakai nama service 'db', bukan localhost
DB_HOST: db
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
DB_NAME: ${DB_NAME}
DB_PORT: 5432
networks:
- erp_network

Expand Down