Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sean/matching docker #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/matching-service/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
PORT=8081
MATCH_TIMEOUT=10
JWT_SECRET=you-can-replace-this-with-your-own-secret
REDIS_URL=localhost:6379

# if you are NOT USING docker, use the below url
REDIS_URL=localhost:6379

# if you are USING docker, use the below url
# REDIS_URL=redis-container:6379
18 changes: 18 additions & 0 deletions apps/matching-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.23

WORKDIR /usr/src/app

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

RUN go mod tidy && go mod download && go mod verify

COPY .env /usr/src/app/.env

COPY . .

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

EXPOSE 8081

CMD ["app"]
24 changes: 21 additions & 3 deletions apps/matching-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ go mod tidy
- `PORT`: Specifies the port for the WebSocket server. Default is `8081`.
- `JWT_SECRET`: The secret key used to verify JWT tokens.
- `MATCH_TIMEOUT`: The time in seconds to wait for a match before timing out.
- `REDIS_URL`: The URL for the Redis server. Default is `localhost:6379`.
- `REDIS_URL`: The URL for the Redis server. Default is `localhost:6379`. If you are using docker, use `redis-container:6379`

4. Start a local redis server:

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

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)

## Docker Support
## Running the Application via Docker

TODO: Add section for Docker setup and usage instructions.
Before running the following commands, ensure that the URL for the Redis server in `.env` file has been changed to `redis-container:6379`

To run the application via Docker, run the following command:

```bash
docker build -f Dockerfile -t match-go-app .
```

```bash
docker network create redis-go-network
```

```bash
docker run -d --name redis-container --network redis-go-network redis
```

```bash
docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app
```