Skip to content

Commit 2271546

Browse files
committed
Merge branch 'master' into api-gateway
2 parents f78600f + b6c7174 commit 2271546

File tree

77 files changed

+2503
-4144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2503
-4144
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Selectively Build and Push to Artifact Registry
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
7+
env:
8+
PROJECT_ID: cs3219-400714
9+
REGION: asia-southeast1
10+
GAR_LOCATION: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/
11+
12+
jobs:
13+
build-push-artifact:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
build_status: ${{ steps.set_output.outputs.build_status }}
17+
steps:
18+
- name: "Checkout"
19+
uses: "actions/checkout@v3"
20+
21+
- name: Detect Changes in Microservices
22+
id: changes
23+
uses: dorny/paths-filter@v2
24+
with:
25+
filters: |
26+
frontend:
27+
- 'frontend/**'
28+
user_service:
29+
- 'user_service/**'
30+
question_service:
31+
- 'question_service/**'
32+
matching_service:
33+
- 'matching_service/**'
34+
collab_service:
35+
- 'collab_service/**'
36+
37+
- name: 'Create env file'
38+
run: |
39+
echo "${{ secrets.ENV_FILE }}" > .env
40+
41+
- name: "Set up google auth"
42+
id: auth
43+
uses: "google-github-actions/auth@v1"
44+
with:
45+
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
46+
47+
- name: "Set up Cloud SDK"
48+
uses: "google-github-actions/setup-gcloud@v1"
49+
50+
- name: "Use gcloud CLI"
51+
run: "gcloud info"
52+
53+
- name: "Docker auth"
54+
run: |-
55+
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
56+
57+
- name: Determine Build Status
58+
id: set_output
59+
run: echo "::set-output name=build_status::false"
60+
61+
- name: 1. Build and Push frontend
62+
if: steps.changes.outputs.frontend == 'true'
63+
run: |
64+
docker-compose build frontend
65+
docker-compose push frontend
66+
echo "::set-output name=build_status::true"
67+
68+
- name: 2. Build and Push question-service
69+
if: steps.changes.outputs.question_service == 'true'
70+
run: |
71+
docker-compose build question-service
72+
docker-compose push question-service
73+
echo "::set-output name=build_status::true"
74+
75+
- name: 3. Build and Push user-service
76+
if: steps.changes.outputs.user_service == 'true'
77+
run: |
78+
docker-compose build user-service
79+
docker-compose push user-service
80+
echo "::set-output name=build_status::true"
81+
82+
- name: 4. Build and Push matching-service
83+
if: steps.changes.outputs.matching_service == 'true'
84+
run: |
85+
docker-compose build matching-service
86+
docker-compose push matching-service
87+
echo "::set-output name=build_status::true"
88+
89+
- name: 5. Build and Push collab-service
90+
if: steps.changes.outputs.collab_service == 'true'
91+
run: |
92+
docker-compose build collab-service
93+
docker-compose push collab-service
94+
echo "::set-output name=build_status::true"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build and Push to Artifact Registry
2+
3+
on:
4+
workflow_dispatch
5+
6+
env:
7+
PROJECT_ID: cs3219-400714
8+
REGION: asia-southeast1
9+
GAR_LOCATION: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/
10+
11+
jobs:
12+
build-push-artifact:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: "Checkout"
16+
uses: "actions/checkout@v3"
17+
18+
- name: 'Create env file'
19+
run: |
20+
echo "${{ secrets.ENV_FILE }}" > .env
21+
22+
- id: "auth"
23+
uses: "google-github-actions/auth@v1"
24+
with:
25+
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
26+
27+
- name: "Set up Cloud SDK"
28+
uses: "google-github-actions/setup-gcloud@v1"
29+
30+
- name: "Use gcloud CLI"
31+
run: "gcloud info"
32+
33+
- name: "Docker auth"
34+
run: |-
35+
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
36+
37+
- name: Build image
38+
run: docker-compose build
39+
40+
- name: Push image
41+
run: docker-compose push

.github/workflows/deployment.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deployment Workflow
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: ["Selectively Build and Push to Artifact Registry", "Build and Push to Artifact Registry"]
7+
types:
8+
- completed
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
if: >
14+
github.event_name == 'workflow_dispatch' ||
15+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.build_status == 'true')
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: "Set up google auth"
21+
id: auth
22+
uses: "google-github-actions/auth@v1"
23+
with:
24+
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
25+
26+
- name: "Use gcloud CLI"
27+
run: "gcloud info"
28+
29+
- name: "SSH to VM"
30+
id: 'compute-ssh'
31+
uses: 'google-github-actions/ssh-compute@v0'
32+
with:
33+
instance_name: 'peerprep-prod'
34+
zone: 'asia-southeast1-b'
35+
ssh_private_key: '${{ secrets.SSH_KEY }}'
36+
command: 'echo "${{ secrets.ENV_FILE }}" | sudo tee /usr/src/peerprep/.env > /dev/null && sudo chmod 777 /usr/src/peerprep/scripts/init.sh && sudo /usr/src/peerprep/scripts/init.sh'
37+
38+
- id: 'test'
39+
run: |-
40+
echo '${{ steps.compute-ssh.outputs.stdout }}'
41+
echo '${{ steps.compute-ssh.outputs.stderr }}'

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
/coverage
1010

1111
# production
12-
/build
12+
*/build
13+
*/dist
1314

1415
# misc
1516
.DS_Store

README.md

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,13 @@
1-
# Frontend
1+
# Running this project
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
3+
Simply run `docker-compose up --build` or `docker compose up --build`
44

5-
## Available Scripts
65

7-
In the project directory, you can run:
6+
# For devs
87

9-
### `npm start`
8+
TBA
109

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
10+
To manually push to our service registry, please set up gcloud authentication with our project title
11+
Then build the images as you would normally with `docker-compose build`
12+
Then push the builds to the registry with `docker-compose push`
1313

14-
The page will reload when you make changes.\
15-
You may also see any lint errors in the console.
16-
17-
### `npm test`
18-
19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `npm run build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `npm run eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
35-
36-
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37-
38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39-
40-
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41-
42-
43-
# Backend
44-
45-
## Question Service
46-
47-
The question service depends on a MongoDB instance to serve as the database.
48-
To start the question service on localhost, run `docker-compose -f .\docker_compose_dev.yml up` at the root of this project.
49-
50-
The server should be accessible via the endpoint
51-
`localhost:8080/api/questions/`
52-
53-
See the comments `question_service/questionController.js` for the list of endpoints

collab_service/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18
1+
FROM node:18-alpine
22
WORKDIR /usr/src/app
33
COPY package*.json ./
44
RUN npm install

docker-compose.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
version: '3'
2+
services:
3+
4+
frontend:
5+
container_name: frontend
6+
build:
7+
context: ./frontend
8+
dockerfile: Dockerfile.prod
9+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/frontend:latest
10+
environment:
11+
- REACT_APP_ENV_TYPE=prod
12+
ports:
13+
- "80:80"
14+
15+
question-service:
16+
container_name: question-service
17+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/question-service:latest
18+
build:
19+
context: ./question_service
20+
dockerfile: Dockerfile.prod
21+
environment:
22+
- MONGODB_URI=mongodb://mongo:27017/question_service
23+
- PORT=8080
24+
ports:
25+
- "8080:8080"
26+
depends_on:
27+
- mongo
28+
volumes:
29+
- questions_test_cases:/app/question_test_cases
30+
31+
collab-service:
32+
container_name: collab-service
33+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/collab-service:latest
34+
environment:
35+
PORT: 8083
36+
build:
37+
context: ./collab_service
38+
dockerfile: Dockerfile #no need for prod file since the server is so basic
39+
ports:
40+
- "8083:8083"
41+
42+
user-service:
43+
container_name: user-service
44+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/user-service:latest
45+
build:
46+
context: ./user_service
47+
dockerfile: Dockerfile.prod
48+
environment:
49+
PORT: 8081
50+
SECRET_KEY: ${SECRET_KEY}
51+
ports:
52+
- "8081:8081"
53+
depends_on:
54+
- postgres
55+
volumes:
56+
- profile_pictures:/usr/src/app/public/profile_pictures
57+
58+
matching-service:
59+
container_name: matching-service
60+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/matching-service:latest
61+
build:
62+
context: ./matching_service
63+
dockerfile: Dockerfile.prod
64+
environment:
65+
- PORT=8082
66+
ports:
67+
- "8082:8082"
68+
69+
mongo:
70+
container_name: mongo
71+
image: mongo:6.0
72+
ports:
73+
- "27017:27017"
74+
volumes:
75+
- mongo-dev-data:/data/db
76+
77+
postgres:
78+
container_name: postgres
79+
image: postgres:latest
80+
environment:
81+
POSTGRES_USER: ${POSTGRES_USER}
82+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
83+
POSTGRES_DB: ${POSTGRES_DB}
84+
PG_PORT: ${PG_PORT}
85+
ports:
86+
- "${PG_PORT}:5432"
87+
volumes:
88+
- postgres_data:/var/lib/postgresql/data/
89+
90+
91+
rabbitmq:
92+
image: rabbitmq:3-management
93+
container_name: rabbitmq
94+
environment:
95+
- RABBITMQ_DEFAULT_USER=guest
96+
- RABBITMQ_DEFAULT_PASS=guest
97+
ports:
98+
- "5672:5672"
99+
- "15672:15672"
100+
healthcheck:
101+
test: rabbitmq-diagnostics -q ping
102+
interval: 30s
103+
timeout: 30s
104+
retries: 5
105+
start_period: 30s
106+
107+
volumes:
108+
postgres_data:
109+
mongo-dev-data:
110+
questions_test_cases:
111+
profile_pictures:

0 commit comments

Comments
 (0)