Skip to content

Commit

Permalink
Create release 0.3.0 (#191)
Browse files Browse the repository at this point in the history
Add HTTPS support

---------

Co-authored-by: Lee Chun Wei <[email protected]>
  • Loading branch information
yhtMinceraft1010X and chunweii authored Oct 26, 2023
1 parent cf81e15 commit 54a5d31
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
2 changes: 1 addition & 1 deletion deployment/gke-prod-manifests/frontend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
13 changes: 13 additions & 0 deletions deployment/gke-prod-manifests/frontend-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
networking.gke.io/managed-certificates: gke-managed-cert
kubernetes.io/ingress.class: "gce"
spec:
defaultBackend:
service:
name: frontend-service
port:
number: 3000
1 change: 0 additions & 1 deletion deployment/gke-prod-manifests/frontend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ spec:
targetPort: 3000
selector:
io.kompose.service: frontend
type: LoadBalancer
status:
loadBalancer: {}
16 changes: 13 additions & 3 deletions deployment/gke-prod-manifests/gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,30 @@ spec:
secretKeyRef:
name: firebase-service-account
key: firebase-service-account
- name: PORT
- name: HTTP_PROXY_PORT
value: "4000"
- name: WS_MATCH_PROXY_PORT
value: "4002"
- name: WS_COLLABORATION_PROXY_PORT
value: "4003"
- name: FRONTEND_ADDRESS
value: "http://www.codeparty.org:3000"
value: "https://www.codeparty.org"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/gateway:latest
name: gateway
ports:
- containerPort: 4000
hostPort: 4000
protocol: TCP
- containerPort: 4002
hostPort: 4002
protocol: TCP
- containerPort: 4003
hostPort: 4003
protocol: TCP
resources:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
13 changes: 13 additions & 0 deletions deployment/gke-prod-manifests/gateway-http-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gateway-http-ingress
annotations:
networking.gke.io/managed-certificates: gke-managed-cert
kubernetes.io/ingress.class: "gce"
spec:
defaultBackend:
service:
name: frontend-service
port:
number: 4000
7 changes: 6 additions & 1 deletion deployment/gke-prod-manifests/gateway-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ spec:
- name: "4000"
port: 4000
targetPort: 4000
- name: "4002"
port: 4002
targetPort: 4002
- name: "4003"
port: 4003
targetPort: 4003
selector:
io.kompose.service: gateway
type: LoadBalancer
status:
loadBalancer: {}
13 changes: 13 additions & 0 deletions deployment/gke-prod-manifests/gateway-wscollaboration-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gateway-wscollaboration-ingress
annotations:
networking.gke.io/managed-certificates: gke-managed-cert
kubernetes.io/ingress.class: "gce"
spec:
defaultBackend:
service:
name: gateway-service
port:
number: 4003
13 changes: 13 additions & 0 deletions deployment/gke-prod-manifests/gateway-wsmatch-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gateway-wsmatch-ingress
annotations:
networking.gke.io/managed-certificates: gke-managed-cert
kubernetes.io/ingress.class: "gce"
spec:
defaultBackend:
service:
name: gateway-service
port:
number: 4002
11 changes: 11 additions & 0 deletions deployment/gke-prod-manifests/gke-managed-cert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: gke-managed-cert
spec:
domains:
- codeparty.org
- www.codeparty.org
- api.codeparty.org
- wsmatch.codeparty.org
- wscollab.codeparty.org
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
2 changes: 1 addition & 1 deletion deployment/gke-prod-manifests/user-service-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ spec:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
cpu: "100m"
restartPolicy: Always
status: {}
4 changes: 3 additions & 1 deletion deployment/prod-dockerfiles/Dockerfile.frontend-prod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ RUN yarn prisma generate
ARG NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG_ARG
ENV NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG=$NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG_ARG

ENV NEXT_PUBLIC_GATEWAY_ADDRESS="http://api.codeparty.org:4000/"
ENV NEXT_PUBLIC_HTTP_PROXY_GATEWAY_ADDRESS="https://api.codeparty.org/"
ENV NEXT_PUBLIC_WS_MATCH_PROXY_GATEWAY_ADDRESS="https://wsmatch.codeparty.org"
ENV NEXT_PUBLIC_WS_COLLABORATION_PROXY_GATEWAY_ADDRESS="https://wscollab.codeparty.org"

RUN yarn build

Expand Down
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ services:
- ./services/gateway:/app/services/gateway
ports:
- "4000:4000"
- "4002:4002"
- "4003:4003"
environment:
PORT: 4000
HTTP_PROXY_PORT: 4000
WS_MATCH_PROXY_PORT: 4002
WS_COLLABORATION_PROXY_PORT: 4003
FIREBASE_SERVICE_ACCOUNT: ${FIREBASE_SERVICE_ACCOUNT}
FRONTEND_ADDRESS: "http://localhost:3000"

Expand All @@ -95,5 +99,7 @@ services:
ports:
- "3000:3000"
environment:
NEXT_PUBLIC_GATEWAY_ADDRESS: "http://localhost:4000/"
NEXT_PUBLIC_HTTP_PROXY_GATEWAY_ADDRESS: "http://localhost:4000/"
NEXT_PUBLIC_WS_MATCH_PROXY_GATEWAY_ADDRESS: "http://localhost:4002/"
NEXT_PUBLIC_WS_COLLABORATION_PROXY_GATEWAY_ADDRESS: "http://localhost:4003/"
NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG: ${NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG}
6 changes: 2 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"@radix-ui/react-tabs": "^1.0.4",
"@tanstack/react-query": "^5.0.0",
"@tanstack/react-table": "^8.10.4",
"@types/node": "20.6.0",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"@uiball/loaders": "^1.3.0",
"autoprefixer": "10.4.15",
"class-variance-authority": "^0.7.0",
Expand Down Expand Up @@ -62,7 +59,8 @@
"devDependencies": {
"@types/diff-match-patch": "^1.0.34",
"@types/lodash": "^4.14.199",
"@types/react": "^18.2.30",
"@types/node": "^20.8.8",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@types/socket.io-client": "^3.0.0",
"eslint": "^8.51.0",
Expand Down
7 changes: 3 additions & 4 deletions frontend/providers/MatchmakingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import React, {
import { io, Socket } from "socket.io-client";
import { Match } from "@prisma/client";
import { AuthContext } from "@/contexts/AuthContext";
import {matchSocketAddress} from "@/gateway-address/gateway-address";
import {wsMatchProxyGatewayAddress} from "@/gateway-address/gateway-address";

const SERVER_URL = matchSocketAddress;
const SERVER_URL = wsMatchProxyGatewayAddress;

interface MatchmakingContextValue {
socket: Socket | null;
Expand Down Expand Up @@ -57,8 +57,7 @@ export const MatchmakingProvider: React.FC<MatchmakingProviderProps> = ({
query: { username: generateRandomNumber() },
extraHeaders: {
"User-Id-Token": token
},
path: "/match/socket.io"
}
});
setSocket(newSocket);
newSocket.connect();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/firebase-client/useDeleteOwnAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useDeleteOwnAccount = () => {
method: "DELETE",
headers: {
"User-Id-Token": idToken,
"User-Id": currentUser.uid
},
});
// This will delete the user from the Firebase Authentication database
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/gateway-address/gateway-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* - Leave NEXT_PUBLIC_GATEWAY_ADDRESS empty for dev environments
* - For prod, pass in a separate address to NEXT_PUBLIC_GATEWAY_ADDRESS
*/
const gatewayAddress = process.env.NEXT_PUBLIC_GATEWAY_ADDRESS || "http://localhost:4000/"
const httpProxyGatewayAddress = process.env.NEXT_PUBLIC_HTTP_PROXY_GATEWAY_ADDRESS || "http://localhost:4000/";
export const wsMatchProxyGatewayAddress = process.env.NEXT_PUBLIC_WS_MATCH_PROXY_GATEWAY_ADDRESS || "http://localhost:4002";
export const wsCollaborationProxyGatewayAddress = process.env.NEXT_PUBLIC_WS_COLLABORATION_PROXY_GATEWAY_ADDRESS
|| "http://localhost:4003";

export const userApiPathAddress = gatewayAddress + "api/user-service/";
export const questionApiPathAddress = gatewayAddress + "api/question-service/";

export const collaborationSocketAddress = gatewayAddress + "collaboration/socket.io";
export const matchSocketAddress = gatewayAddress + "match/socket.io";
export const userApiPathAddress = httpProxyGatewayAddress + "api/user-service/";
export const questionApiPathAddress = httpProxyGatewayAddress + "api/question-service/";
5 changes: 2 additions & 3 deletions frontend/src/hooks/useCollaboration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "../../../utils/shared-ot";
import { TextOp } from "ot-text-unicode";
import { Room, connect } from "twilio-video";
import {collaborationSocketAddress} from "@/gateway-address/gateway-address";
import {wsCollaborationProxyGatewayAddress} from "@/gateway-address/gateway-address";
import {AuthContext} from "@/contexts/AuthContext";

type UseCollaborationProps = {
Expand Down Expand Up @@ -47,11 +47,10 @@ const useCollaboration = ({ roomId, userId, disableVideo }: UseCollaborationProp
if (currentUser) {
currentUser.getIdToken(true).then(
(token) => {
const socketConnection = io(collaborationSocketAddress, {
const socketConnection = io(wsCollaborationProxyGatewayAddress, {
extraHeaders: {
"User-Id-Token": token
},
path: "/collaboration/socket.io"
});
setSocket(socketConnection);

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/api/userHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EditableUser } from "@/types/UserTypes";

export const updateUserByUid = async (user: EditableUser, currentUser: any) => {
try {
const url = `${userApiPathAddress}${currentUser.uid}}`;
const url = `${userApiPathAddress}${currentUser.uid}`;
const idToken = await currentUser.getIdToken(true);

console.log("user", user);
Expand All @@ -14,6 +14,7 @@ export const updateUserByUid = async (user: EditableUser, currentUser: any) => {
headers: {
"Content-Type": "application/json",
"User-Id-Token": idToken,
"User-Id": currentUser.uid
},
body: JSON.stringify(user),
});
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/pages/interviews/find-match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ export default function FindMatch() {
};

useEffect(() => {
let timeout: ReturnType<typeof setTimeout> | null = null;
if (match) {
router.push("/interviews/match-found");
} else {
setTimeout(() => {
timeout = setTimeout(() => {
cancelLooking();
router.push("/interviews/match-not-found");
}, 30000);
}
return () => {
if (timeout)
clearTimeout(timeout);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [match, router]);

Expand Down
2 changes: 1 addition & 1 deletion services/gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The below code shows a sample route that is being proxied from the frontend to t
}
```

This code is part of the `proxied_routes` list in `src/proxied_routes/proxied_routes.ts` file.
This code is part of the `http_proxied_routes` list in `src/proxied_routes/proxied_routes.ts` file.

Explanation:
* `url` - The initial path. Assuming that the gateway address is `YYY://localhost:4000`, the frontend would call `YYY://localhost:4000/users`
Expand Down
Loading

0 comments on commit 54a5d31

Please sign in to comment.