From a07d3affb03a1ccd27ee2882e60eed5fc7260b12 Mon Sep 17 00:00:00 2001 From: ahdan15 Date: Tue, 20 May 2025 11:34:12 +0700 Subject: [PATCH] env and yml --- Dockerfile | 2 +- docker-compose.yml | 6 +++--- internal/database/database.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f8403fe..2cb3b61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,5 +25,5 @@ WORKDIR /root/ COPY --from=builder /app/main . COPY --from=builder /app/.env . -EXPOSE 8086 +EXPOSE 8080 CMD ["./main"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b6ae3e4..7031550 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,12 +17,12 @@ services: # DATABASE SIMRS V3.0 - SIMRS_STAG_HOST=10.10.123.223 - SIMRS_STAG_PORT=5432 - - SIMRS_STAG_NAME=simrsbackup + - SIMRS_STAG_NAME=simrs-stag - SIMRS_STAG_USER=simtest - SIMRS_STAG_PASS=12345 # DATABASE SATU DATA - SATUDATA_HOST=10.10.123.165 - - SATUDATA_USER=stim - - SATUDATA_PASS=stim*RS54 + - SATUDATA_USERNAME=stim + - SATUDATA_PASSWORD=stim*RS54 - SATUDATA_NAME=satu_db - SATUDATA_PORT=5000 \ No newline at end of file diff --git a/internal/database/database.go b/internal/database/database.go index bd25899..6a66765 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -27,6 +27,11 @@ type service struct { } var ( + hostSimrs = os.Getenv("SIMRS_STAG_HOST") + userNameSimrs = os.Getenv("SIMRS_STAG_USER") + passwordSimrs = os.Getenv("SIMRS_STAG_PASS") + dbNameSimrs = os.Getenv("SIMRS_STAG_NAME") + portSimrs = os.Getenv("SIMRS_STAG_PORT") hostSatudata = os.Getenv("SATUDATA_HOST") userNameSatudata = os.Getenv("SATUDATA_USER") passwordSatudata = os.Getenv("SATUDATA_PASS") @@ -40,7 +45,14 @@ func New() Service { if dbInstance != nil { return dbInstance } + simrs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSimrs, userNameSimrs, passwordSimrs, dbNameSimrs, portSimrs) + SimrsDB, err := gorm.Open(postgres.Open(simrs), &gorm.Config{}) + if err != nil { + log.Fatal("Failed to connect to SIM database: ", err) + } else { + log.Println("Successfully connected to the database") + } satudata := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSatudata, userNameSatudata, passwordSatudata, dbNameSatudata, portSatudata) SatudataDB, err := gorm.Open(postgres.Open(satudata), &gorm.Config{}) @@ -50,6 +62,7 @@ func New() Service { log.Println("Successfully connected to the database") } dbInstance = &service{ + simrsDB: SimrsDB, satuDataDB: SatudataDB, } return dbInstance