Skip to content

Commit 098224f

Browse files
authored
Merge pull request #35 from CS3219-AY2425S1/titus/add-cicd-docker-compose
chore: add cicd docker compose
2 parents 65f0d57 + bba2f31 commit 098224f

File tree

8 files changed

+93
-25
lines changed

8 files changed

+93
-25
lines changed

.github/workflows/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- staging
8+
pull_request:
9+
branches:
10+
- main
11+
- staging
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Docker Compose
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y docker-compose
25+
26+
- name: Create Environment Files
27+
env:
28+
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
29+
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
30+
JWT_SECRET: ${{ secrets.JWT_SECRET }}
31+
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
32+
DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }}
33+
USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }}
34+
run: |
35+
cd ./apps/frontend
36+
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
37+
echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env
38+
39+
cd ../question-service
40+
echo "FIREBASE_CREDENTIAL_PATH=$FIREBASE_CREDENTIAL_PATH" >> .env
41+
echo "JWT_SECRET=$JWT_SECRET" >> .env
42+
43+
cd ../user-service
44+
echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env
45+
echo "PORT=$USER_SERVICE_PORT" >> .env
46+
echo "JWT_SECRET=$JWT_SECRET" >> .env
47+
48+
- name: Create Database Credential Files
49+
env:
50+
FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
51+
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
52+
run: |
53+
cd ./apps/question-service
54+
echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH"
55+
56+
- name: Build and Run Services
57+
run: |
58+
cd ./apps
59+
docker-compose up --build -d
60+
61+
- name: Wait for services to be ready
62+
run: sleep 30
63+
64+
- name: Run Tests
65+
env:
66+
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
67+
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
68+
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
69+
run: |
70+
curl -sSL -o /dev/null $QUESTION_SERVICE_URL
71+
curl -fsSL -o /dev/null $USER_SERVICE_URL
72+
curl -fsSL -o /dev/null $FRONTEND_URL
73+
74+
# We can add more tests here

apps/frontend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Replace with the corresponding url, credentials and endpoint
1+
# URL endpoints of the services
22
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080/"
33
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"

apps/question-service/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Path to the firebase credential json
12
FIREBASE_CREDENTIAL_PATH=cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json
23

34
# Secret for creating JWT signature

apps/user-service/.env.sample

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
# Mongo DB connection URL
12
DB_CLOUD_URI=<CONNECTION_STRING>
2-
DB_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB
3-
PORT=3001
43

5-
# Will use cloud MongoDB Atlas database
6-
ENV=PROD
4+
# Port for the user-service
5+
PORT=3001
76

87
# Secret for creating JWT signature
98
JWT_SECRET=you-can-replace-this-with-your-own-secret

apps/user-service/model/repository.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ import "dotenv/config";
33
import { connect } from "mongoose";
44

55
export async function connectToDB() {
6-
let mongoDBUri =
7-
process.env.ENV === "PROD"
8-
? process.env.DB_CLOUD_URI
9-
: process.env.DB_LOCAL_URI;
6+
let mongoDBUri = process.env.DB_CLOUD_URI;
107

11-
await connect(mongoDBUri);
8+
await connect(mongoDBUri)
129
}
1310

1411
export async function createUser(username, email, password) {

apps/user-service/package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/user-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"dotenv": "^16.4.5",
2222
"express": "^4.21.0",
2323
"jsonwebtoken": "^9.0.2",
24-
"mongoose": "^8.5.4"
24+
"mongoose": "^8.7.0"
2525
}
2626
}

services/question-service/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)