Skip to content

Commit

Permalink
Modfied workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rf-opssupport committed Jan 8, 2024
1 parent ef49a2e commit 8995bca
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 57 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/aha-prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
with:
tag: ${{ github.event.inputs.Tag_name }}
repo: REAN-Foundation/reancare-service
repo: REAN-Foundation/rean-admin-portal

- name: Configure AWS credentials
if: ${{ steps.checkTag.outputs.exists == 'true' }}
Expand All @@ -52,7 +52,7 @@ jobs:
id: imageidvar
run: |
image_tag+=${{ steps.result_release.outputs.tag_name }} && image_tag+=_ && image_tag+=${{ steps.result_release.outputs.id }}
echo "imagetag_value=$(aws ecr-public describe-image-tags --repository-name reancare --region us-east-1 --query "imageTagDetails[?imageTag=='$image_tag'].imageTag" --output text)" >> $GITHUB_OUTPUT
echo "imagetag_value=$(aws ecr-public describe-image-tags --repository-name rean-admin-portal --region us-east-1 --query "imageTagDetails[?imageTag=='$image_tag'].imageTag" --output text)" >> $GITHUB_OUTPUT
- name: ECR Image and Github Tag Check
run: |
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
with:
tag: ${{ github.event.inputs.Tag_name }}
repo: REAN-Foundation/reancare-service
repo: REAN-Foundation/rean-admin-portal

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
with:
task-definition: task-definition.json
container-name: default
image: public.ecr.aws/i9y2d4u3/reancare:${{ needs.Github-ECR-Tag-Check.outputs.release_name }}_${{ needs.Github-ECR-Tag-Check.outputs.release_id }}
image: public.ecr.aws/i9y2d4u3/rean-admin-portal:${{ needs.Github-ECR-Tag-Check.outputs.release_name }}_${{ needs.Github-ECR-Tag-Check.outputs.release_id }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
Expand Down
35 changes: 16 additions & 19 deletions .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# file with configuration. For more information, see:
# https://github.com/actions/labeler


name: Dev-CI-CD

## Controls when the workflow will run
# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the develop branch
push:
Expand All @@ -18,12 +17,10 @@ jobs:
Deploy-ECS:
environment: dev
runs-on: ubuntu-latest
# group: Default Larger Runners
# labels: ubuntu-latest-4-cores

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -36,46 +33,46 @@ jobs:
id: vars
shell: bash
run: |
echo "branch=$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "repo_name=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')" >> $GITHUB_OUTPUT
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=repo_name::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')"
- name: Another step
- name: Print Branch Details
run: |
echo "Branch: ${{ steps.vars.outputs.branch }}"
echo "Sha: ${{ steps.vars.outputs.sha_short }}"
echo "Repo: ${{ steps.vars.outputs.repo_name }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Cache Docker layers
uses: actions/cache@v3
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Copy env file
run: aws s3 cp s3://${{ secrets.ENV_FILE_BUCKET_PATH }}/.env ./.env

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/reancare-service-dev-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
tags: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
env:
# 7 GiB by default on GitHub, setting this to 16 GiB
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Expand All @@ -91,7 +88,7 @@ jobs:
with:
task-definition: task-definition.json
container-name: default
image: ${{ steps.login-ecr.outputs.registry }}/reancare-service-dev-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
image: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
Expand All @@ -103,7 +100,7 @@ jobs:
id: taskdefintionvar
shell: bash
run: |
echo "task_definition_arn=$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')" >> $GITHUB_OUTPUT
echo "::set-output name=task_definition_arn::$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')"
- name: Task Defintion ARN
run: |
Expand All @@ -114,5 +111,5 @@ jobs:
with:
url: 'https://reanfoundation.duplocloud.net/subscriptions/${{ secrets.DUPLO_ID }}/UpdateEcsService'
method: 'POST'
data: '{"TaskDefinition":${{ steps.taskdefintionvar.outputs.task_definition_arn }},"Name": "${{ secrets.SERVICE_NAME }}","Replicas":1, "HealthCheckGracePeriodSeconds": 1200}'
data: '{"TaskDefinition":${{ steps.taskdefintionvar.outputs.task_definition_arn }},"Name": "${{ secrets.SERVICE_NAME }}","Replicas":1, "DnsPrfx": "", "HealthCheckGracePeriodSeconds": 1200}'
bearerToken: ${{ secrets.DUPLOCLOUD_TOKEN }}
55 changes: 23 additions & 32 deletions .github/workflows/pr-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This workflow will trigger pull requests and apply a label based on the
# paths that are modified in the pull request.
#

# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration. For more information, see:
# https://github.com/actions/labeler
Expand All @@ -13,63 +12,55 @@ on:
# Triggers the workflow on push or pull request events but only for the develop branch
pull_request:
branches: [develop]

jobs:
CodeScan-ESLint:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Lint Code Base
uses: docker://ghcr.io/github/super-linter:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: /
TYPESCRIPT_ES_CONFIG_FILE: .eslintrc.json
VALIDATE_TYPESCRIPT_ES: true
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: develop

Build-Docker-Image:
environment: dev
runs-on: ubuntu-latest
# group: Default Larger Runners
# labels: ubuntu-latest-4-cores

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v2

- name: Declare some variables
id: vars
shell: bash
run: |
# echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")"
# echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
# echo "::set-output name=repo_name::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')"
echo "branch=$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "repo_name=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')" >> $GITHUB_OUTPUT
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed "s/\\//-/g")"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=repo_name::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')"
- name: Another step
run: |
echo "Branch: ${{ steps.vars.outputs.branch }}"
echo "Sha: ${{ steps.vars.outputs.sha_short }}"
echo "Repo: ${{ steps.vars.outputs.repo_name }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v3
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Copy env file
run: aws s3 cp s3://${{ secrets.ENV_FILE_BUCKET_PATH }}/.env ./.env

- name: Build
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: public.ecr.aws/i9y2d4u3/reancare:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }}
tags: public.ecr.aws/i9y2d4u3/rean-admin-portal:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

Expand All @@ -88,7 +88,7 @@ jobs:
with:
task-definition: task-definition.json
container-name: default
image: public.ecr.aws/i9y2d4u3/reancare:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }}
image: public.ecr.aws/i9y2d4u3/rean-admin-portal:${{ needs.Publish-Release.outputs.release_name }}_${{ needs.Publish-Release.outputs.release_id }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:18.12.0-alpine3.16 AS builder

WORKDIR /app
COPY . .

RUN npm install -g typescript
RUN npm install
RUN npm run build

#######################################

FROM node:18.12.0-alpine3.16

RUN apk add bash
RUN apk add --no-cache \
python3 \
&& rm -rf /var/cache/apk/*
RUN apk add --update alpine-sdk
RUN apk add chromium \
harfbuzz

RUN apk update
RUN apk upgrade

WORKDIR /app
RUN rm -rf ./*

COPY --from=builder ./app/package*.json ./
COPY --from=builder ./app/build .

RUN npm install --production

COPY . /app

#CMD ["node", "index.js"]

RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/bin/bash", "-c", "/app/entrypoint.sh"]
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

#prod
aws s3 cp s3://$S3_CONFIG_BUCKET/$S3_CONFIG_PATH/rean-admin-portal/.env ./.env
aws s3 cp s3://$S3_CONFIG_BUCKET/$S3_CONFIG_PATH/rean-admin-portal/constants.ts /app/src/lib

#aha-prod
aws s3 cp s3://$S3_CONFIG_BUCKET/$S3_CONFIG_PATH/rean-admin-portal/.env ./.env
aws s3 cp s3://$S3_CONFIG_BUCKET/$S3_CONFIG_PATH/rean-admin-portal/constants.ts /app/src/lib

cd /app/build
# Add any other scripts here...
# Start the service
# npm run start
node index.js

0 comments on commit 8995bca

Please sign in to comment.