Skip to content

Commit 65d1c45

Browse files
Merge branch 'sean/matching-docker' into frontend-websocket
2 parents 7c36043 + 35de547 commit 65d1c45

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

apps/matching-service/.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
PORT=8081
22
MATCH_TIMEOUT=10
33
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

apps/matching-service/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.23
2+
3+
WORKDIR /usr/src/app
4+
5+
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
6+
COPY go.mod go.sum ./
7+
8+
RUN go mod tidy && go mod download && go mod verify
9+
10+
COPY .env /usr/src/app/.env
11+
12+
COPY . .
13+
14+
RUN go build -v -o /usr/local/bin/app ./main.go
15+
16+
EXPOSE 8081
17+
18+
CMD ["app"]

apps/matching-service/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ go mod tidy
2727
- `PORT`: Specifies the port for the WebSocket server. Default is `8081`.
2828
- `JWT_SECRET`: The secret key used to verify JWT tokens.
2929
- `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`
3131

3232
4. Start a local Redis server:
3333

@@ -121,6 +121,24 @@ Make sure to open the HTML file in a web browser while the WebSocket server is r
121121

122122
You can open one instance of the HTML file in multiple tabs to simulate multiple clients connecting to the server. (In the future: ensure that only one connection is allowed per user)
123123

124-
## Docker Support
124+
## Running the Application via Docker
125125

126-
TODO: Add section for Docker setup and usage instructions.
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+
128+
To run the application via Docker, run the following command:
129+
130+
```bash
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
140+
```
141+
142+
```bash
143+
docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app
144+
```

0 commit comments

Comments
 (0)