Skip to content

Commit

Permalink
chore: use docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrest1 committed Feb 6, 2024
1 parent 28b3905 commit 6d1bfc3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ main
/bin/

.env

.dockerignore
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ WORKDIR /app
# Copy built app to work directory
COPY --from=builder /app/main .

# Copy env file
COPY .env .env

# Expose port
EXPOSE 9090

Expand Down
15 changes: 5 additions & 10 deletions controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/dkrest1/task-manager/configs"
"github.com/dkrest1/task-manager/models"
"github.com/dkrest1/task-manager/utils"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv"
"gorm.io/gorm"
)

Expand All @@ -24,12 +24,7 @@ type AuthController struct{
}

func NewAuthController () *AuthController {
//load env
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}



return &AuthController{
DB: configs.DB,
}
Expand Down Expand Up @@ -71,10 +66,10 @@ func(c *AuthController) Login(w http.ResponseWriter, r *http.Request) {
return
}

secretKey, exist := os.LookupEnv("JWT_SECRET_KEY")
secretKey := os.Getenv("JWT_SECRET_KEY")

if !exist {
log.Fatal("JWT_SECRET_KEY not set in env")
if secretKey == "" {
log.Printf("JWT_SECRET_KEY is empty")
}

token, err := utils.GenerateToken(existingUser.ID, existingUser.Email, secretKey)
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

services:
app:
image: dkrest/task-manager:latest
ports:
- "9090:9090"
environment:
- PORT=${PORT}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
log.Fatal("Error loading .env file:", err)
}


// init DB
configs.InitDB()

Expand All @@ -35,9 +36,9 @@ func main() {
// enable cors
handler := cors.Default().Handler(appRoutes)

port, exist := os.LookupEnv("PORT")
port := os.Getenv("PORT")

if !exist {
if port == "" {
log.Fatal("PORT not set in env")
}

Expand Down
6 changes: 1 addition & 5 deletions middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (


func Auth(next http.HandlerFunc) http.HandlerFunc {
secretKey, exist := os.LookupEnv("JWT_SECRET_KEY")

if !exist {
log.Fatal("JWT_SECRET_KEY not set in env")
}
secretKey := os.Getenv("JWT_SECRET_KEY")

if secretKey == "" {
log.Printf("JWT_SECRET_KEY is empty")
Expand Down

0 comments on commit 6d1bfc3

Please sign in to comment.