Skip to content

Commit a09ab51

Browse files
committed
dockerize
1 parent 81b8d61 commit a09ab51

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

collab/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.20
2+
3+
WORKDIR /collab-service
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
# Build
11+
RUN CGO_ENABLED=0 GOOS=linux go build -o /collab-service/app
12+
13+
# Run
14+
CMD ["/collab-service/app"]

collab/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module gin-gonic/gin
22

3-
go 1.23.1
3+
go 1.20
44

55
require (
66
github.com/bytedance/sonic v1.11.6 // indirect

collab/main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"log"
66
"net/http"
7+
"os"
78
"sync"
89

910
"github.com/gin-gonic/gin"
@@ -38,7 +39,11 @@ type Message struct {
3839

3940
func verifyToken(token string) bool {
4041
client := &http.Client{}
41-
req, err := http.NewRequest("GET", "http://localhost:3001/auth/verify-token", nil)
42+
USER_SERVICE_URI := os.Getenv("USER_SERVICE_URI")
43+
if USER_SERVICE_URI == "" {
44+
USER_SERVICE_URI = "http://localhost:3001"
45+
}
46+
req, err := http.NewRequest("GET", USER_SERVICE_URI + "/auth/verify-token", nil)
4247
if err != nil {
4348
log.Println("Error creating request:", err)
4449
return false
@@ -140,8 +145,6 @@ func handleMessages(client *Client, hub *Hub) {
140145
break
141146
}
142147

143-
log.Printf("Received")
144-
145148
var msgData map[string]interface{}
146149
if err := json.Unmarshal(message, &msgData); err != nil {
147150
log.Printf("Failed to parse message: %v", err)
@@ -168,7 +171,6 @@ func handleMessages(client *Client, hub *Hub) {
168171
}
169172

170173
if msgData["type"] == "close_session" {
171-
log.Println("It's time")
172174
closeMessage := Message{
173175
roomID: client.roomID,
174176
content: []byte("The session has been closed by a user."),
@@ -224,5 +226,9 @@ func main() {
224226
// Status endpoint
225227
r.GET("/status", statusHandler(hub))
226228

227-
r.Run(":4000")
229+
PORT := os.Getenv("PORT")
230+
if PORT == "" {
231+
PORT = ":4000"
232+
}
233+
r.Run(PORT)
228234
}

compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ services:
115115
target: storage-blob-api/app
116116
depends_on:
117117
- redis
118+
119+
collab:
120+
build: collab
121+
env_file:
122+
- collab/.env
123+
ports:
124+
- "4000:4000"
125+
develop:
126+
watch:
127+
- action: rebuild
128+
path: collab
129+
target: collab/app
118130
# mongo:
119131
# image: "mongo:latest"
120132
# ports:

matching-service-api/log/matching_service_api.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ time="2024-10-28T14:17:49+08:00" level=info msg="request from user 67188e6ebe712
9292
time="2024-10-28T14:17:49+08:00" level=info msg="request from user 6702c9a3f1217a1b2123575b successfully published"
9393
time="2024-10-28T14:17:50+08:00" level=info msg="request from user 671f1ba30b0e2619aaa4dd7a successfully published"
9494
time="2024-10-28T14:17:50+08:00" level=info msg="request from user 671f1bdf0b0e2619aaa4dd85 successfully published"
95+
time="2024-10-28T14:20:11+08:00" level=info msg="request from user 6702c9a3f1217a1b2123575b successfully published"
96+
time="2024-10-28T14:20:12+08:00" level=info msg="request from user 671f1bdf0b0e2619aaa4dd85 successfully published"
97+
time="2024-10-28T14:31:29+08:00" level=info msg="request from user 6702c9a3f1217a1b2123575b successfully published"
98+
time="2024-10-28T14:31:29+08:00" level=info msg="request from user 671f1bdf0b0e2619aaa4dd85 successfully published"

matching-service/log/matching_service.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ time="2024-10-27T15:29:09+08:00" level=error msg="error handling incoming reques
3636
time="2024-10-27T15:29:10+08:00" level=error msg="error handling incoming request: WRONGTYPE Operation against a key holding the wrong kind of value"
3737
time="2024-10-27T16:08:08+08:00" level=error msg="error handling incoming request: WRONGTYPE Operation against a key holding the wrong kind of value"
3838
time="2024-10-27T16:08:10+08:00" level=error msg="error handling incoming request: WRONGTYPE Operation against a key holding the wrong kind of value"
39+
time="2024-10-28T13:01:38+08:00" level=info msg="Beginning consumption from message queue"
40+
time="2024-10-28T13:01:38+08:00" level=info msg="Begin processing requests"

storage-blob-api/log/matching_service_api.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ time="2024-10-28T14:17:53+08:00" level=info msg="Request handled successfully"
105105
time="2024-10-28T14:17:54+08:00" level=info msg="Request handled successfully"
106106
time="2024-10-28T14:17:55+08:00" level=info msg="Request handled successfully"
107107
time="2024-10-28T14:17:55+08:00" level=info msg="Request handled successfully"
108+
time="2024-10-28T14:20:17+08:00" level=info msg="Request handled successfully"
109+
time="2024-10-28T14:20:18+08:00" level=info msg="Request handled successfully"
110+
time="2024-10-28T14:31:34+08:00" level=info msg="Request handled successfully"
111+
time="2024-10-28T14:31:34+08:00" level=info msg="Request handled successfully"

0 commit comments

Comments
 (0)