Skip to content

Commit

Permalink
Merge pull request #26 from REAN-Foundation/authorization-01
Browse files Browse the repository at this point in the history
Authorization 01
  • Loading branch information
kiran-rean authored May 6, 2024
2 parents 11c929a + 804da26 commit fbc958f
Show file tree
Hide file tree
Showing 230 changed files with 14,603 additions and 6,593 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
18 changes: 9 additions & 9 deletions .github/workflows/aha-prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:

Github-ECR-Tag-Check:
runs-on: ubuntu-latest

steps:
- name: check tag
uses: mukunku/tag-exists-action@v1.2.0
id: checkTag
with:
with:
tag: ${{ github.event.inputs.Tag_name }}

- name: Get release
if: ${{ steps.checkTag.outputs.exists == 'true' }}
id: result_release
Expand All @@ -38,27 +38,27 @@ jobs:
with:
tag: ${{ github.event.inputs.Tag_name }}
repo: REAN-Foundation/rean-admin-portal

- name: Configure AWS credentials
if: ${{ steps.checkTag.outputs.exists == 'true' }}
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: Get ECR Image Tag
if: ${{ steps.checkTag.outputs.exists == 'true' }}
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 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: |
if [[ ${{ steps.checkTag.outputs.exists }} == 'false' ]]; then exit 1; fi
if [[ -z "${{ steps.imageidvar.outputs.imagetag_value }}" ]]; then exit 1; fi
outputs:
release_name: ${{ steps.result_release.outputs.tag_name }}
release_id: ${{ steps.result_release.outputs.id }}
Expand All @@ -73,7 +73,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get release
id: result_release
uses: cardinalby/git-get-release-action@v1
Expand All @@ -82,7 +82,7 @@ jobs:
with:
tag: ${{ github.event.inputs.Tag_name }}
repo: REAN-Foundation/rean-admin-portal

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/deploy-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Admin Portal Deployment

on:
push:
branches:
- develop-inflection

jobs:
deploy:
runs-on: ubuntu-latest

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

- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli
# - name: Install dependencies
# run: |
# pip install -r requirements.txt

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-south-1

- name: Login to Amazon ECR
run: aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 443751504066.dkr.ecr.ap-south-1.amazonaws.com

- name: Copy env file
run: aws s3 cp s3://reancare-configs/rean-admin-portal/.env ./.env

- name: Build Docker image
run: |
docker build -t 443751504066.dkr.ecr.ap-south-1.amazonaws.com/rean-admin-portal:${{ github.sha }} .
docker push 443751504066.dkr.ecr.ap-south-1.amazonaws.com/rean-admin-portal:${{ github.sha }}
- name: SSH into EC2 instance
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker stop admin-portal || true
docker rm admin-portal || true
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 443751504066.dkr.ecr.ap-south-1.amazonaws.com
docker pull 443751504066.dkr.ecr.ap-south-1.amazonaws.com/rean-admin-portal:${{ github.sha }}
docker run -d -p 3000:3000 --network host --name admin-portal 443751504066.dkr.ecr.ap-south-1.amazonaws.com/rean-admin-portal:${{ github.sha }}
# - name: Get the latest revision of ECS task definition
# id: get-latest-revision
# run: |
# latest_revision=$(aws ecs describe-task-definition --task-definition document-processor --query 'taskDefinition.revision' --output text)
# echo "Latest revision: $latest_revision"
# echo "::set-output name=revision::$latest_revision"

# - name: Download task definition
# run: |
# aws ecs describe-task-definition --task-definition document-processor:${{ steps.get-latest-revision.outputs.revision }} \
# --query taskDefinition > task-definition.json
# cat task-definition.json

# - name: Update container image in task definition
# run: |
# jq '.containerDefinitions[0].image="443751504066.dkr.ecr.ap-south-1.amazonaws.com/document-processor:${{ github.sha }}"' task-definition.json > new-task-definition.json
# jq 'del(.taskDefinitionArn, .revision, .status, .registeredAt, .registeredBy, .requiresAttributes, .compatibilities)' new-task-definition.json > modified-task-definition.json
# mv modified-task-definition.json new-task-definition.json
# cat new-task-definition.json

# - name: Create a new revision of ECS task definition
# id: create-new-revision
# run: |
# new_revision=$(aws ecs register-task-definition --cli-input-json file://new-task-definition.json --query 'taskDefinition.revision' --output text)
# echo "New revision created: $new_revision"
# echo "::set-output name=new-revision::$new_revision"

# - name: Deploy to ECS
# run: |
# aws ecs update-service --cluster reancare-cluster --service document-processor --task-definition document-processor:${{ steps.create-new-revision.outputs.new-revision }} --force-new-deployment
2 changes: 1 addition & 1 deletion .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
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

Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
branches: [main]

jobs:

Publish-Release:
runs-on: ubuntu-latest
steps:
Expand All @@ -25,11 +25,11 @@ jobs:
publish : true
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}

outputs:
release_id: ${{ steps.new_publish.outputs.id }}
release_name: ${{ steps.new_publish.outputs.tag_name }}


Deploy-ECS:
needs: Publish-Release
Expand Down Expand Up @@ -62,6 +62,9 @@ jobs:
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
Expand Down
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch server",
"request": "launch",
"runtimeArgs": ["run-script", "dev"],
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"type": "node",
"console": "integratedTerminal"
},

{
"type": "chrome",
"request": "launch",
"name": "Launch Edge",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}"
}
],
"compounds": [
{
"name": "Both",
"configurations": ["Launch server", "Launch Edge"]
}
]
}
25 changes: 15 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ RUN apk add --no-cache \
python3 \
&& rm -rf /var/cache/apk/*
RUN apk add --update alpine-sdk
RUN apk add chromium \
harfbuzz
# RUN apk add chromium \
# harfbuzz
# RUN apk --no-cache add aws-cli

RUN apk update
RUN apk upgrade

WORKDIR /app
RUN rm -rf ./*
# RUN rm -rf ./*

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

RUN npm install --production
RUN npm install

# # COPY . /app

COPY . /app
# CMD ["npm", "run", "dev", "--", "--host", "--port", "3000"]

#CMD ["node", "index.js"]
# RUN chmod +x /app/entrypoint.sh
# ENTRYPOINT ["/bin/bash", "-c", "/app/entrypoint.sh"]
ENV ORIGIN=http://35.154.171.205

RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/bin/bash", "-c", "/app/entrypoint.sh"]
CMD ["node", "build/index.js"]
10 changes: 5 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/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
aws s3 cp s3://reancare-configs/rean-admin-portal/.env ./.env
aws s3 cp s3://reancare-configs/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
# #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...
Expand Down
Loading

0 comments on commit fbc958f

Please sign in to comment.