File tree Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Original file line number Diff line number Diff line change 1
1
PORT = 8081
2
2
MATCH_TIMEOUT = 10
3
3
JWT_SECRET = you-can-replace-this-with-your-own-secret
4
- REDIS_URL = localhost:6379
4
+
5
+ # if you are NOT USING docker, use the below url
6
+ REDIS_URL = localhost:6379
7
+
8
+ # if you are USING docker, use the below url
9
+ # REDIS_URL=redis-container:6379
Original file line number Diff line number Diff line change 1
- # Stage 1: Build Go Application
2
-
3
- FROM golang:1.23 AS builder
1
+ FROM golang:1.23
4
2
5
3
WORKDIR /usr/src/app
6
4
5
+ # pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
7
6
COPY go.mod go.sum ./
8
7
9
8
RUN go mod tidy && go mod download && go mod verify
10
9
11
- # Copy the .env file to the final image
12
10
COPY .env /usr/src/app/.env
13
11
14
12
COPY . .
15
13
16
14
RUN go build -v -o /usr/local/bin/app ./main.go
17
15
18
- # Stage 2: Setup Redis and combine with Go
19
- FROM redis:latest
20
-
21
- # Copy the built Go binary from the builder stage
22
- COPY --from=builder /usr/local/bin/app /usr/local/bin/app
23
-
24
- EXPOSE 8081 6379
16
+ EXPOSE 8081
25
17
26
- # Start both Redis and the Go application
27
- CMD ["sh" , "-c" , "redis-server & app; wait" ]
18
+ CMD ["app" ]
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ go mod tidy
27
27
- ` PORT ` : Specifies the port for the WebSocket server. Default is ` 8081 ` .
28
28
- ` JWT_SECRET ` : The secret key used to verify JWT tokens.
29
29
- ` MATCH_TIMEOUT ` : The time in seconds to wait for a match before timing out.
30
- - ` REDIS_URL ` : The URL for the Redis server. Default is ` localhost:6379 ` .
30
+ - ` REDIS_URL ` : The URL for the Redis server. Default is ` localhost:6379 ` . If you are using docker, use ` redis-container:6379 `
31
31
32
32
4 . Start a local redis server:
33
33
@@ -123,12 +123,22 @@ You can open one instance of the HTML file in multiple tabs to simulate multiple
123
123
124
124
## Running the Application via Docker
125
125
126
+ Before running the following commands, ensure that the URL for the Redis server in ` .env ` file has been changed to ` redis-container:6379 `
127
+
126
128
To run the application via Docker, run the following command:
127
129
128
130
``` bash
129
- docker build -t matching-service .
131
+ docker build -f Dockerfile -t match-go-app .
132
+ ```
133
+
134
+ ``` bash
135
+ docker network create redis-go-network
136
+ ```
137
+
138
+ ``` bash
139
+ docker run -d --name redis-container --network redis-go-network redis
130
140
```
131
141
132
142
``` bash
133
- docker run -d -p 8081:8081 -p 6379:6379 --name matching-service-container matching-service
143
+ docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app
134
144
```
You can’t perform that action at this time.
0 commit comments