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

Feat: Add Communication Service for users in room #66

Merged
merged 14 commits into from
Nov 12, 2023
Merged
34 changes: 34 additions & 0 deletions .github/workflows/communication_service_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Communication Service Pulumi Preview
on:
pull_request:
branches: ["staging", "master"]
paths: ["backend/communication-service/**"]
env:
WORKING_DIRECTORY_INFRA: ./backend/communication-service/infra
STACK_NAME: ${{ github.ref == 'refs/heads/master' && 'cs3219/communication-service-infra/prod' || 'cs3219/communication-service-infra/staging'}}
jobs:
preview:
name: Preview
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY_INFRA }}
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
node-version: 16.15.0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: npm install
- uses: pulumi/actions@v3
with:
work-dir: ${{ env.WORKING_DIRECTORY_INFRA }}
command: preview
stack-name: ${{ env.STACK_NAME}}
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/communication_service_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Communication Service Pulumi Update
on:
push:
branches: ["master"]
paths: ["backend/communication-service/**"]
env:
WORKING_DIRECTORY_INFRA: ./backend/communication-service/infra
STACK_NAME: ${{ github.ref == 'refs/heads/master' && 'cs3219/communication-service-infra/prod' || 'cs3219/communication-service-infra/staging'}}
jobs:
update:
name: Update
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY_INFRA }}
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
node-version: 16.15.0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: npm install
- uses: pulumi/actions@v3
with:
work-dir: ${{ env.WORKING_DIRECTORY_INFRA }}
command: up
stack-name: ${{ env.STACK_NAME }}
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
1. In the `/backend/collaboration-service/app` directory, copy the `.env.example` file and rename it to `.env.development`
- For any missing env vars, check with the team to retrieve the secrets from the vault

### 1.7. Communication service (`/backend/communication-service`)

1. In the `/backend/communication-service/app` directory, copy the `.env.example` file and rename it to `.env.development`
- For any missing env vars, check with the team to retrieve the secrets from the vault

## 2. Instructions to run services locally

### Pre-requisites
Expand All @@ -54,6 +59,7 @@
- Questions service: http://localhost:8003
- Matching service: http://localhost:8004
- Collaboration service: http://localhost:8005
- Communication service: http://localhost:8006

### Known issues

Expand Down
1 change: 1 addition & 0 deletions backend/api-gateway/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ USERS_SERVICE_URL=http://user-service
QUESTIONS_SERVICE_URL=http://question-service
MATCHING_SERVICE_URL=http://matching-service
COLLABORATION_SERVICE_URL=http://collaboration-service
COMMUNICATION_SERVICE_URL=http://communication-service

# Meant for authorization of server to server communication
API_GATEWAY_AUTH_SECRET=
9 changes: 9 additions & 0 deletions backend/api-gateway/app/routes/api.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ apiRouter.use(
...proxyOptions,
})
);

apiRouter.use(
"/communication",
authMiddleware,
createProxyMiddleware({
target: process.env.COMMUNICATION_SERVICE_URL,
...proxyOptions,
})
);
4 changes: 4 additions & 0 deletions backend/api-gateway/app/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const envSchema = z.object({
.string()
.url()
.default("http://collaboration-service"),
COMMUNICATION_SERVICE_URL: z
.string()
.url()
.default("http://communication-service"),
});

type EnvSchemaType = z.infer<typeof envSchema>;
16 changes: 16 additions & 0 deletions backend/communication-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Communication Service

## Instructions to run

- Please refer to the [README.md](../README.md) in the root of the project for instructions to run the communication service.

## New environment variables

If you need to add new environment variables, please add them to the following locations:

1. `/backend/communication-service/app/.env.example` file and commit it. For others to run the service locally.

1. If the value is a secret, leave it blank and store it with the team's vault (e.g. an API key, secret key, access token, ARN, etc.)
2. If the value is not a secret, you can leave in the value in the `.env.example` file (e.g. http://localhost:8000, staging, 32, etc.)

2. `/backend/communication-service/infra/index.ts` under the `Deploy an ECS Service on Fargate to host the application container` comment under the `env` object. For Pulumi to inject the appropriate environment variables during deployment.
7 changes: 7 additions & 0 deletions backend/communication-service/app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NODE_ENV=development
PORT=80
FRONTEND_ORIGIN=http://localhost:8000
API_GATEWAY_URL=http://api-gateway

# Meant for authorization of server to server communication
API_GATEWAY_AUTH_SECRET=
131 changes: 131 additions & 0 deletions backend/communication-service/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.development
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
16 changes: 16 additions & 0 deletions backend/communication-service/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Use NodeJS server for the app
FROM node:18-alpine AS builder
WORKDIR /app
# Install dependencies first, as they change less often than code.
COPY package.json package-lock.json* ./
RUN npm install
COPY . .
RUN npm run build

FROM node:18-alpine as server
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev
COPY --from=builder ./app/dist ./dist
EXPOSE 80
CMD ["npm", "run", "start"]
13 changes: 13 additions & 0 deletions backend/communication-service/app/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use NodeJS server for the app
FROM node:18-alpine

WORKDIR /app

# Install dependencies first, as they change less often than code.
COPY package.json package-lock.json* ./
RUN npm install
COPY . .

EXPOSE 80

CMD ["npm", "run", "dev"]
Loading
Loading