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

chore: add cicd docker compose #35

Merged
merged 4 commits into from
Oct 9, 2024
Merged
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
74 changes: 74 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Run Tests

on:
push:
branches:
- main
- staging
pull_request:
branches:
- main
- staging

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose

- name: Create Environment Files
env:
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }}
USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }}
run: |
cd ./apps/frontend
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env

cd ../question-service
echo "FIREBASE_CREDENTIAL_PATH=$FIREBASE_CREDENTIAL_PATH" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env

cd ../user-service
echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env
echo "PORT=$USER_SERVICE_PORT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env

- name: Create Database Credential Files
env:
FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
run: |
cd ./apps/question-service
echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH"

- name: Build and Run Services
run: |
cd ./apps
docker-compose up --build -d

- name: Wait for services to be ready
run: sleep 30

- name: Run Tests
env:
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
run: |
curl -sSL -o /dev/null $QUESTION_SERVICE_URL
curl -fsSL -o /dev/null $USER_SERVICE_URL
curl -fsSL -o /dev/null $FRONTEND_URL

# We can add more tests here
2 changes: 1 addition & 1 deletion apps/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Replace with the corresponding url, credentials and endpoint
# URL endpoints of the services
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080/"
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
1 change: 1 addition & 0 deletions apps/question-service/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Path to the firebase credential json
FIREBASE_CREDENTIAL_PATH=cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json

# Secret for creating JWT signature
Expand Down
7 changes: 3 additions & 4 deletions apps/user-service/.env.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Mongo DB connection URL
DB_CLOUD_URI=<CONNECTION_STRING>
DB_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB
PORT=3001

# Will use cloud MongoDB Atlas database
ENV=PROD
# Port for the user-service
PORT=3001

# Secret for creating JWT signature
JWT_SECRET=you-can-replace-this-with-your-own-secret
7 changes: 2 additions & 5 deletions apps/user-service/model/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import "dotenv/config";
import { connect } from "mongoose";

export async function connectToDB() {
let mongoDBUri =
process.env.ENV === "PROD"
? process.env.DB_CLOUD_URI
: process.env.DB_LOCAL_URI;
let mongoDBUri = process.env.DB_CLOUD_URI;

await connect(mongoDBUri);
await connect(mongoDBUri)
}

export async function createUser(username, email, password) {
Expand Down
22 changes: 11 additions & 11 deletions apps/user-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/user-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"dotenv": "^16.4.5",
"express": "^4.21.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.5.4"
"mongoose": "^8.7.0"
}
}
3 changes: 0 additions & 3 deletions services/question-service/.gitignore

This file was deleted.