Skip to content

Commit 35de547

Browse files
Add dockerfile for matching service
1 parent 81d7cf4 commit 35de547

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
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: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
# Stage 1: Build Go Application
2-
3-
FROM golang:1.23 AS builder
1+
FROM golang:1.23
42

53
WORKDIR /usr/src/app
64

5+
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
76
COPY go.mod go.sum ./
87

98
RUN go mod tidy && go mod download && go mod verify
109

11-
# Copy the .env file to the final image
1210
COPY .env /usr/src/app/.env
1311

1412
COPY . .
1513

1614
RUN go build -v -o /usr/local/bin/app ./main.go
1715

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
2517

26-
# Start both Redis and the Go application
27-
CMD ["sh", "-c", "redis-server & app; wait"]
18+
CMD ["app"]

apps/matching-service/README.md

Lines changed: 13 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

@@ -123,12 +123,22 @@ You can open one instance of the HTML file in multiple tabs to simulate multiple
123123

124124
## Running the Application via Docker
125125

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+
126128
To run the application via Docker, run the following command:
127129

128130
```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
130140
```
131141

132142
```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
134144
```

0 commit comments

Comments
 (0)