From ea9e87e65b595c7e2766d0382e50b19d37a8eb2d Mon Sep 17 00:00:00 2001 From: darius Date: Tue, 25 Feb 2025 18:48:29 +0100 Subject: [PATCH] improved env in deploy --- .github/workflows/Deploy-docker.yml | 2 ++ main.go | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Deploy-docker.yml b/.github/workflows/Deploy-docker.yml index b4b2e7e..377d602 100644 --- a/.github/workflows/Deploy-docker.yml +++ b/.github/workflows/Deploy-docker.yml @@ -14,6 +14,8 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Setup env file + run: echo ${{secrets.envFile}} >> .env - name: Build the Docker image run: docker compose build - name: Docker login diff --git a/main.go b/main.go index 242d27e..80c3502 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "github.com/rs/cors" "log" "net/http" + "os" "portfolio/api" "portfolio/database" "portfolio/web" @@ -12,10 +13,12 @@ import ( func main() { // load .env in runtime environment - err := godotenv.Load() - if err != nil { - log.Fatalf(".env not found: %v", err) - return + if os.Getenv("ENVIRONMENT") != "docker" { + err := godotenv.Load() + if err != nil { + log.Fatalf(".env not found: %v", err) + return + } } //connect to database and migrate @@ -25,7 +28,7 @@ func main() { webMux := web.Routes() // Run web server go func() { - err = http.ListenAndServe(":4000", cors.AllowAll().Handler(webMux)) + err := http.ListenAndServe(":4000", cors.AllowAll().Handler(webMux)) if err != nil { log.Fatal(err) @@ -50,7 +53,7 @@ func main() { apiMux := api.Routes() //run api server go func() { - err = http.ListenAndServe(":4001", c.Handler(apiMux)) + err := http.ListenAndServe(":4001", c.Handler(apiMux)) if err != nil { log.Fatal(err) }