From 0cf41c9024372cbd22200335dfb2631686a38bd6 Mon Sep 17 00:00:00 2001 From: Emyr298 Date: Wed, 26 Jun 2024 23:21:55 +0700 Subject: [PATCH] cicd: add dockerfile --- .gitignore | 3 ++- Dockerfile | 13 +++++++++++++ src/main.go | 16 +++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 64ae7f3..d1dfc2c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ go.work go.work.sum # env file -.env \ No newline at end of file +.env +.env.docker diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..20cee5e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.22.4-alpine3.20 + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY src ./src + +RUN CGO_ENABLED=0 GOOS=linux go build -C src -o /pixel-tactics-match + +EXPOSE 8000 +CMD ["/pixel-tactics-match"] diff --git a/src/main.go b/src/main.go index 8099d14..28e44a5 100644 --- a/src/main.go +++ b/src/main.go @@ -1,7 +1,7 @@ package main import ( - "log" + "net/http" ws "pixeltactics.com/match/src/websocket" @@ -10,20 +10,22 @@ import ( ) func main() { - err := godotenv.Load() - if err != nil { - log.Println("Error in loading .env file") - return - } + _ = godotenv.Load() clientHub := ws.NewClientHub() go clientHub.Run() router := gin.Default() + router.GET("/", func(context *gin.Context) { + context.JSON(http.StatusOK, map[string]string{ + "message": "match service", + }) + }) + router.GET("/ws", func(context *gin.Context) { ws.ServeWebSocket(clientHub, context.Writer, context.Request) }) - router.Run("localhost:8000") + router.Run("0.0.0.0:8000") }