Skip to content

Commit

Permalink
MS6 DevOps: Cloud Deployment using K8s (#115)
Browse files Browse the repository at this point in the history
* Push image up aws cloud

* Attempt to bring up question service

* Update Dockerfile for k8

* Setup local k8 deployment

* Revert "Setup local k8 deployment"

This reverts commit 95c6775.

* Reapply "Setup local k8 deployment"

This reverts commit a7fef30.

* Update config

* Remove non essential yml

* Deployed to GKE

* Initialise CI workflow (#117)

* Initialise ci (#118)

* Initialise CI workflow

* Add CI for both repos

* Fix ci (#119)

* Initialise CI workflow

* Fix CI pipeline

* Add ci (#120)

* Initialise CI workflow

* Amend CI workflow

* Fix linting and add backend CI workflow

* Reconfigure for local dev

* Update deployment options

---------

Co-authored-by: Jajabonks <84561814+Jajared@users.noreply.github.com>
  • Loading branch information
evanyan13 and Jajared authored Nov 11, 2024
1 parent fbee878 commit 6529c57
Show file tree
Hide file tree
Showing 84 changed files with 906 additions and 577 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/backend-ci-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Backend CI Workflow

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies for Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Installing dependencies for $service"
cd $service
npm install
cd ..
done
# Build Check for Each Service
- name: Build Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Building $service"
cd $service
npm run build
cd ..
done
# Lint Check for Each Service
- name: Lint Each Service
run: |
cd backend
for service in auth-service question-service user-service matching-service gateway-service collaboration-service; do
echo "Linting $service"
cd $service
npm run lint
cd ..
done
38 changes: 38 additions & 0 deletions .github/workflows/frontend-ci-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Frontend CI Workflow

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies
run: |
cd frontend
npm install
# Build Check
- name: Build Project
run: |
cd frontend
npm run build
# Lint Check
- name: Lint Code
run: |
cd frontend
npm run lint
40 changes: 3 additions & 37 deletions backend/auth-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
#################
## DEVELOPMENT ##
#################
FROM node:18-alpine AS development
FROM node:18

# Set the working directory in the container
WORKDIR /app

# Copy the package.json and package-lock.json files
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Built the app to /dist folder
RUN npm run build
EXPOSE 3003

# Expose the port the app runs on
EXPOSE 4000

################
## PRODUCTION ##
################
FROM node:18-alpine AS production

# Set node environment to production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

# Set the working directory in the container
WORKDIR /app

# Copy only the necessary files from the previous build stage
COPY --from=development /peerprep/app/dist ./dist
COPY package*.json ./

# Install production dependencies only
RUN npm ci --only=production

# Expose the port the app runs on
EXPOSE 4000

# Run the main file
CMD ["node", "dist/main"]
CMD ["node", "dist/main.js"]
17 changes: 0 additions & 17 deletions backend/auth-service/src/app.controller.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion backend/auth-service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ClientsModule } from '@nestjs/microservices';
import { HttpModule } from '@nestjs/axios';
import {
AccessTokenStrategy,
Expand Down
7 changes: 5 additions & 2 deletions backend/auth-service/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class AppService {
}

public async resetPassword(dto: ResetPasswordDto): Promise<boolean> {
const { userId, email } = await this.validatePasswordResetToken(dto.token);
const { userId } = await this.validatePasswordResetToken(dto.token);

const hashedPassword = await bcrypt.hash(dto.password, SALT_ROUNDS);

Expand Down Expand Up @@ -218,6 +218,7 @@ export class AppService {
}
return { userId, email };
} catch (err) {
console.error(err);
throw new RpcException({
statusCode: HttpStatus.UNAUTHORIZED,
message: 'Unauthorized: Invalid or expired password reset token',
Expand Down Expand Up @@ -246,7 +247,7 @@ export class AppService {
text: `Click here to reset your password: ${resetUrl}`,
};

transporter.sendMail(mailOptions, (error, info) => {
transporter.sendMail(mailOptions, (error) => {
if (error) {
throw new RpcException(`Error sending reset email: ${error.message}`);
}
Expand All @@ -260,6 +261,7 @@ export class AppService {
});
return decoded;
} catch (error) {
console.error(error);
throw new RpcException('Invalid access token');
}
}
Expand All @@ -271,6 +273,7 @@ export class AppService {
});
return decoded;
} catch (error) {
console.error(error);
throw new RpcException('Invalid Refresh Token');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export enum AccountProvider {
LOCAL = 'local',
GOOGLE = 'google',
GITHUB = 'github',
}
}
2 changes: 1 addition & 1 deletion backend/auth-service/src/dto/reset-password-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsEmail, IsNotEmpty } from 'class-validator';

export class ResetPasswordRequestDto {
@IsEmail()
Expand Down
2 changes: 1 addition & 1 deletion backend/auth-service/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { MicroserviceOptions } from '@nestjs/microservices';
import { ValidationPipe } from '@nestjs/common';
import { config } from 'src/configs';
import * as dotenv from 'dotenv';
Expand Down
48 changes: 5 additions & 43 deletions backend/code-execution-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#################
## DEVELOPMENT ##
#################
FROM ubuntu:20.04 AS development
# Use a single stage for both development and production
FROM ubuntu:20.04

# Set environment variables to prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -30,47 +28,11 @@ RUN npm install
# Copy the rest of the application code
COPY . .

# Build the app to the /dist folder
# Build the app
RUN npm run build

# Expose the port the app runs on
EXPOSE 4000

# Run the application in development mode
CMD ["npm", "run", "start:dev"]


################
## PRODUCTION ##
################
FROM ubuntu:20.04 AS production

# Set environment variables to prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

# Install only runtime dependencies (Node.js, Python, and Java)
RUN apt-get update && \
apt-get install -y \
python3 openjdk-11-jdk curl gnupg && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set the working directory in the container
WORKDIR /app

# Copy the build artifacts from the development stage
COPY --from=development /app/dist ./dist
COPY package*.json ./

# Install production dependencies only
RUN npm ci --only=production

# Expose the port the app runs on
EXPOSE 4000

# Run the main application
CMD ["node", "dist/main"]
# Set the command to run the application
CMD ["node", "dist/main.js"]
47 changes: 0 additions & 47 deletions backend/code-execution-service/Dockerfile(copybackup)

This file was deleted.

Loading

0 comments on commit 6529c57

Please sign in to comment.