Skip to content

Commit

Permalink
Merge branch 'all-1.0-prod' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeeppr1998 committed Apr 26, 2024
2 parents ed92ecb + 076f1db commit e95f54c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 18 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/Dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: DEV DEPLOYMENT

on:
push:
branches: [ ]
branches: [ all-1.0 ]

jobs:
build:
Expand All @@ -17,11 +17,11 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
name: Load .env from GitHub Secret
run: echo "${{ secrets.MY_ENV_VARS }}" > .env

-
name: Build and push
uses: docker/build-push-action@v2
Expand All @@ -30,7 +30,7 @@ jobs:
push: true
tags: ${{ secrets.CONTAINER_REGISTRY }}:${{ secrets.IMAGE_TAG }}
env:
MY_ENV_VARS: ${{ secrets.MY_ENV_VARS }}
MY_ENV_VARS: ${{ secrets.MY_ENV_VARS }}
deploy:
runs-on: ubuntu-latest
timeout-minutes: 15
Expand All @@ -39,24 +39,24 @@ jobs:
-
name: Checkout
uses: actions/checkout@v2
-
-
name: Deploy Stack
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.PORT }}
script: |
docker login
docker container stop ${{ secrets.CONTAINER_NAME }}
docker rm ${{ secrets.CONTAINER_NAME }}
docker rmi ${{ secrets.CONTAINER_REGISTRY }}:${{ secrets.IMAGE_TAG }}
docker pull ${{ secrets.CONTAINER_REGISTRY }}:${{ secrets.IMAGE_TAG }}
docker-compose up -d --force-recreate --no-deps
docker run -d --name ${{ secrets.CONTAINER_NAME }} --network ${{ secrets.NETWORK }} -p ${{ secrets.CONTAINER_PORT }} -t ${{ secrets.CONTAINER_REGISTRY }}:${{ secrets.IMAGE_TAG }}
63 changes: 63 additions & 0 deletions .github/workflows/Prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: PROD DEPLOYMENT

on:
push:
branches: [ all-1.0-prod ]

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
name: Load .env from GitHub Secret
run: echo "${{ secrets.MY_ENV_VARS_PROD }}" > .env

-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.CONTAINER_REGISTRY_PROD }}:${{ secrets.IMAGE_TAG }}
env:
MY_ENV_VARS: ${{ secrets.MY_ENV_VARS_PROD }}
deploy:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [build]
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Deploy Stack
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USERNAME_PROD }}
key: ${{ secrets.SSH_PRIVATE_KEY_PROD }}
port: ${{ secrets.PORT }}
script: |
docker login
docker container stop ${{ secrets.CONTAINER_NAME }}
docker rm ${{ secrets.CONTAINER_NAME }}
docker rmi ${{ secrets.CONTAINER_REGISTRY_PROD }}:${{ secrets.IMAGE_TAG }}
docker pull ${{ secrets.CONTAINER_REGISTRY_PROD }}:${{ secrets.IMAGE_TAG }}
cd /home/azureuser/all-services/all-content-service
docker-compose up -d --force-recreate --no-deps
5 changes: 0 additions & 5 deletions dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ RUN npm install
# Copy the rest of the application code to the container
COPY . .

# Set environment variables
ENV PORT=3008
ENV MONGO_URL=
ENV ALL_LC_API_URL=

# Expose the port on which the application will run
EXPOSE $PORT

Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'
services:
content-service-app:
build:
context: .
ports:
- '3008:3008'
container_name: content-service
restart: always
networks:
- ai-network
environment:
- .env

networks:
ai-network:
driver: bridge
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"mongoose": "^7.3.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"split-graphemes": "^0.5.0",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
32 changes: 30 additions & 2 deletions src/controllers/content.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FastifyReply } from 'fastify';
import { HttpService } from "@nestjs/axios";
import { firstValueFrom, lastValueFrom, map } from "rxjs";
import { ApiBody, ApiExcludeEndpoint, ApiForbiddenResponse, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import * as splitGraphemes from 'split-graphemes';

@ApiTags('content')
@Controller('content')
Expand Down Expand Up @@ -60,10 +61,24 @@ export class contentController {
delete newContent.result.meanWordComplexity;
delete newContent.result.totalWordComplexity;
delete newContent.result.wordComplexityMap;
delete newContent.result.syllableCount;
delete newContent.result.syllableCountMap;

async function getSyllableCount(text) {
return splitGraphemes.splitGraphemes(text.replace(/[\u200B\u200C\u200D\uFEFF\s!@#$%^&*()_+{}\[\]:;<>,.?\/\\|~'"-=]/g, '')).length;
}

let syllableCount = await getSyllableCount(contentSourceDataEle['text']);

let syllableCountMap = {}

for (let wordEle of contentSourceDataEle['text'].split(" ")) {
syllableCountMap[wordEle] = await getSyllableCount(wordEle);
}

newContent.result.wordMeasures = newWordMeasures;

return { ...contentSourceDataEle, ...newContent.result };
return { ...contentSourceDataEle, ...newContent.result, syllableCount: syllableCount, syllableCountMap: syllableCountMap };
} else if (contentSourceDataEle['language'] === "en") {
const url = process.env.ALL_TEXT_EVAL_URL + 'getPhonemes';

Expand Down Expand Up @@ -187,7 +202,20 @@ export class contentController {
try {
const skip = (page - 1) * limit;
const { data } = await this.contentService.pagination(skip, limit, type, collectionId);
return response.status(HttpStatus.OK).send({ status: 'success', data });

let language = data[0].language;

let totalSyllableCount = 0;
if (language === "en") {
data.forEach((contentObject: any) => {
totalSyllableCount += contentObject.contentSourceData[0].phonemes.length;
});
} else {
data.forEach((contentObject: any) => {
totalSyllableCount += contentObject.contentSourceData[0].syllableCount;
});
}
return response.status(HttpStatus.OK).send({ status: 'success', data, totalSyllableCount: totalSyllableCount });
} catch (error) {
return response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
status: "error",
Expand Down

0 comments on commit e95f54c

Please sign in to comment.