diff --git a/.github/workflows/Dev.yml b/.github/workflows/Dev.yml index 6266410..f8c40b4 100644 --- a/.github/workflows/Dev.yml +++ b/.github/workflows/Dev.yml @@ -2,7 +2,7 @@ name: DEV DEPLOYMENT on: push: - branches: [ ] + branches: [ all-1.0 ] jobs: build: @@ -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 @@ -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 @@ -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 }} diff --git a/.github/workflows/Prod.yml b/.github/workflows/Prod.yml new file mode 100644 index 0000000..b1d7938 --- /dev/null +++ b/.github/workflows/Prod.yml @@ -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 diff --git a/dockerfile b/Dockerfile similarity index 85% rename from dockerfile rename to Dockerfile index 0aa8482..b84a7a7 100644 --- a/dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bfe8cb7 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/package.json b/package.json index dab173c..69321f7 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/controllers/content.controller.ts b/src/controllers/content.controller.ts index 8747fd7..2edd436 100644 --- a/src/controllers/content.controller.ts +++ b/src/controllers/content.controller.ts @@ -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') @@ -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'; @@ -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",