Skip to content

Commit

Permalink
feat: update docker and env
Browse files Browse the repository at this point in the history
  • Loading branch information
tituschewxj committed Oct 25, 2024
1 parent 2ff03c3 commit f268332
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }}
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
REDIS_URL: ${{ vars.REDIS_URL }}
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
run: |
cd ./apps/frontend
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
Expand All @@ -56,6 +57,7 @@ jobs:
echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
echo "REDIS_URL=$REDIS_URL" >> .env
echo "QUESTION_SERVICE_GRPC_URL=$QUESTION_SERVICE_GRPC_URL" >> .env
- name: Create Database Credential Files
env:
Expand Down
2 changes: 1 addition & 1 deletion apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Once running, you can access:

- The **frontend** at http://localhost:3000
- The **user service** at http://localhost:3001
- The **question service** at http://localhost:8080
- The **question service** at http://localhost:8080 (REST) and http://localhost:50051 (gRPC)
- The **matching service** at http://localhost:8081
- The **redis service** at http://localhost:6379

Expand Down
1 change: 1 addition & 0 deletions apps/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
dockerfile: Dockerfile
ports:
- 8080:8080
- 50051:50051
env_file:
- ./question-service/.env
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const DifficultySelector: React.FC<DifficultySelectorProps> = ({ selectedDifficu
<Tag.CheckableTag
className={`difficulty-tag ${difficultyOption.value}-tag`}
key={difficultyOption.value}
checked={selectedDifficulties.includes(difficultyOption.label)}
onChange={() => handleChange(difficultyOption.label)}
checked={selectedDifficulties.includes(difficultyOption.value)}
onChange={() => handleChange(difficultyOption.value)}
>
{difficultyOption.label}
</Tag.CheckableTag>
Expand Down
41 changes: 14 additions & 27 deletions apps/frontend/src/app/services/use-matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ export type MatchRequestParams = {
}

export type MatchFoundResponse = {
type: "match_found",
matchId: number,
partnerId: number,
partnerName: string,
} | {
type: "match_found",
matchId: string,
type: "match_question_found",
match_id: string,
user: string,
matchedUser: string,
topic: string | string[],
difficulty: string
matched_user: string,
matched_topics: string[],
question_doc_ref_id: string,
question_name: string,
question_difficulty: string,
question_topics: string[],
}

export type MatchTimeoutResponse = {
Expand Down Expand Up @@ -61,7 +59,7 @@ export default function useMatching(): MatchState {
return;
}

if (responseJson.type == "match_found") {
if (responseJson.type == "match_question_found") {
setIsSocket(false);

const info: MatchInfo = parseInfoFromResponse(responseJson);
Expand Down Expand Up @@ -136,20 +134,9 @@ export default function useMatching(): MatchState {
}

function parseInfoFromResponse(responseJson: MatchFoundResponse): MatchInfo {
// test whether old or new
if ("partnerId" in responseJson) {
return {
matchId: responseJson.matchId?.toString() ?? "unknown",
partnerId: responseJson.partnerId?.toString() ?? "unknown",
partnerName: responseJson.partnerName ?? "unknown",
myName: "unknown",
};
} else {
return {
matchId: responseJson.matchId?.toString() ?? "unknown",
partnerId: "unknown",
partnerName: responseJson.matchedUser ?? "unknown",
myName: responseJson.user ?? "unknown",
};
}
return {
matchId: responseJson.match_id?.toString() ?? "unknown",
partnerName: responseJson.matched_user ?? "unknown",
myName: responseJson.user ?? "unknown",
};
}
1 change: 0 additions & 1 deletion apps/frontend/src/contexts/websocketcontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SocketState = {
};
export type MatchInfo = {
matchId: string;
partnerId: string;
myName: string;
partnerName: string;
}
Expand Down
6 changes: 4 additions & 2 deletions apps/matching-service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ PORT=8081
MATCH_TIMEOUT=30
JWT_SECRET=you-can-replace-this-with-your-own-secret

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

# if you are USING docker, use the below url
# If you are USING docker, use the below variables
# REDIS_URL=redis-container:6379
# QUESTION_SERVICE_GRPC_URL=question-service:50051
4 changes: 3 additions & 1 deletion apps/matching-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Client sends matching parameters:
{
"type": "match_request",
"topics": ["Algorithms", "Arrays"],
"difficulties": ["Easy", "Medium"],
"difficulties": ["easy", "medium"],
"username": "1f0myn"
}
```
Expand Down Expand Up @@ -153,3 +153,5 @@ 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
```

**NOTE:** As there is a dependency on the question-service to return the found questions, the matching-service does not work fully unless the question-service is present.
8 changes: 5 additions & 3 deletions apps/matching-service/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package servers
import (
"log"
pb "matching-service/proto"
"os"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -13,12 +14,13 @@ var (
)

func InitGrpcServer() *grpc.ClientConn {
questionServiceAddr := os.Getenv("QUESTION_SERVICE_GRPC_URL")
// Dial the server
conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(questionServiceAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Did not connect: %v", err)
log.Fatalf("Did not connect to %v: %v", questionServiceAddr, err)
} else {
log.Println("Connected to Grpc server at :50051")
log.Println("Connected to Grpc server at %v", questionServiceAddr)
}

// Create a new client for the ExampleService
Expand Down
2 changes: 1 addition & 1 deletion apps/question-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ COPY . .

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

EXPOSE 8080
EXPOSE 8080 50051

CMD ["app"]
2 changes: 1 addition & 1 deletion apps/question-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ docker build -t question-service .
```

```bash
docker run -p 8080:8080 --env-file .env -d question-service
docker run -p 8080:8080 -p 50051:50051 --env-file .env -d question-service
```

The server will be available at http://localhost:8080.
Expand Down

0 comments on commit f268332

Please sign in to comment.