From 1a565406c9118d6364d3a326db19253e29a7f9cc Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Sun, 20 Oct 2024 20:07:42 +0530 Subject: [PATCH 1/3] BAH-4126 | Add. Workflow to stop EC2 Instances based on schedule --- .github/workflows/stop_ec2_environments.yml | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/stop_ec2_environments.yml diff --git a/.github/workflows/stop_ec2_environments.yml b/.github/workflows/stop_ec2_environments.yml new file mode 100644 index 0000000..1712c37 --- /dev/null +++ b/.github/workflows/stop_ec2_environments.yml @@ -0,0 +1,32 @@ +name: Stop EC2 Instances + +on: + schedule: + # Runs "At 09:00 PM IST on Moday-Friday. Below time is mentioned in UTC time zone" (see https://crontab.guru) + - cron: '30 15 * * 1-5' + workflow_dispatch: + push: + branches: + - BAH-4126 + +jobs: + stop-instances: + runs-on: ubuntu-latest + strategy: + matrix: + instance: ['bahmni-standard-docker'] + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.BAHMNI_AWS_ID }} + aws-secret-access-key: ${{ secrets.BAHMNI_AWS_SECRET }} + aws-region: ap-south-1 + role-to-assume: ${{ secrets.BAHMNI_INFRA_ADMIN_ROLE }} + role-duration-seconds: 1200 # 20 mins + role-session-name: BahmniInfraAdminSession + + - name: Stop Environments + run: | + INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ matrix.instance }}" --query "Reservations[].Instances[].InstanceId" --output text) + aws ec2 stop-instances --instance-ids ${INSTANCE_ID} > /dev/null 2>&1 \ No newline at end of file From 4aaf8e6c70ae4077ce5349b4b222c443fe2af172 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Sun, 20 Oct 2024 20:44:59 +0530 Subject: [PATCH 2/3] BAH-4126 | Add. Workflow to start EC2 instance based environments --- .github/workflows/start_ec2_environments.yml | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/start_ec2_environments.yml diff --git a/.github/workflows/start_ec2_environments.yml b/.github/workflows/start_ec2_environments.yml new file mode 100644 index 0000000..4cf7451 --- /dev/null +++ b/.github/workflows/start_ec2_environments.yml @@ -0,0 +1,32 @@ +name: Start EC2 Instances + +on: + schedule: + # Runs "At 06:00 AM IST on Moday-Friday. Below time is mentioned in UTC time zone" (see https://crontab.guru) + - cron: '30 00 * * 1-5' + workflow_dispatch: + push: + branches: + - BAH-4126 + +jobs: + start-instances: + runs-on: ubuntu-latest + strategy: + matrix: + instance: ['bahmni-standard-docker'] + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.BAHMNI_AWS_ID }} + aws-secret-access-key: ${{ secrets.BAHMNI_AWS_SECRET }} + aws-region: ap-south-1 + role-to-assume: ${{ secrets.BAHMNI_INFRA_ADMIN_ROLE }} + role-duration-seconds: 1200 # 20 mins + role-session-name: BahmniInfraAdminSession + + - name: Start Environments + run: | + INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ matrix.instance }}" --query "Reservations[].Instances[].InstanceId" --output text) + aws ec2 start-instances --instance-ids ${INSTANCE_ID} > /dev/null 2>&1 \ No newline at end of file From ea63783e1dc5a5817c55df7fa8129775d8dd99a0 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Sun, 20 Oct 2024 21:04:30 +0530 Subject: [PATCH 3/3] BAH-4126 | Refactor. Remove trigger based on branch push --- .github/workflows/start_ec2_environments.yml | 3 --- .github/workflows/stop_ec2_environments.yml | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/start_ec2_environments.yml b/.github/workflows/start_ec2_environments.yml index 4cf7451..5f5999e 100644 --- a/.github/workflows/start_ec2_environments.yml +++ b/.github/workflows/start_ec2_environments.yml @@ -5,9 +5,6 @@ on: # Runs "At 06:00 AM IST on Moday-Friday. Below time is mentioned in UTC time zone" (see https://crontab.guru) - cron: '30 00 * * 1-5' workflow_dispatch: - push: - branches: - - BAH-4126 jobs: start-instances: diff --git a/.github/workflows/stop_ec2_environments.yml b/.github/workflows/stop_ec2_environments.yml index 1712c37..ee7de4e 100644 --- a/.github/workflows/stop_ec2_environments.yml +++ b/.github/workflows/stop_ec2_environments.yml @@ -5,9 +5,6 @@ on: # Runs "At 09:00 PM IST on Moday-Friday. Below time is mentioned in UTC time zone" (see https://crontab.guru) - cron: '30 15 * * 1-5' workflow_dispatch: - push: - branches: - - BAH-4126 jobs: stop-instances: @@ -17,7 +14,7 @@ jobs: instance: ['bahmni-standard-docker'] steps: - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.BAHMNI_AWS_ID }} aws-secret-access-key: ${{ secrets.BAHMNI_AWS_SECRET }}