Skip to content

Commit

Permalink
pipeline implemetation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheetal-ayanworks committed Apr 16, 2024
1 parent 3f7debf commit a5cc9ff
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 60 deletions.
45 changes: 28 additions & 17 deletions .github/workflows/dev-agent-provisioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,35 @@ jobs:
# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

- name: Create or Update Service
run: |
echo "SERVICE_NAME: ${SERVICE_NAME}"
# Describe the service once and store the result
SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ${{ env.AWS_REGION }})
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/user-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/user-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/user-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
# Debug: Print the content of the modified JSON file
cat ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ${{ env.AWS_REGION }} | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ${{ env.AWS_REGION }} --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
30 changes: 24 additions & 6 deletions .github/workflows/dev-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Build and deploy Node.js app to ECSsdc
on:
push:
branches:
- main
paths:
- 'apps/agent-service/**'
workflow_dispatch:
- pipeline-implementation
# paths:
# - 'apps/agent-service/**'
# workflow_dispatch:

env:
ECR_IMAGE_TAG: "AGENT_V_${{ github.run_number }}"
Expand Down Expand Up @@ -69,12 +69,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/agent-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/agent-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/agent-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/agent-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -83,3 +83,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
26 changes: 22 additions & 4 deletions .github/workflows/dev-api-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: dev-services
IMAGE_TAG: "API-GATEWAY_v_${{ github.run_number }}"
IMAGE_TAG: "API-GATEWAY_V_${{ github.run_number }}"
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfiles/Dockerfile.api-gateway .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
Expand All @@ -52,7 +52,7 @@ jobs:
run: |
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV
echo "ECR_REPOSITORY=dev-services" >> $GITHUB_ENV
echo "IMAGE_TAG=API-GATEWAY_v_${{ github.run_number }}" >> $GITHUB_ENV
echo "IMAGE_TAG=API-GATEWAY_V_${{ github.run_number }}" >> $GITHUB_ENV
- name: Print environment variables
run: |
Expand All @@ -69,12 +69,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/api-gateway-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/api-gateway-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/api-gateway-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/api-gateway-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -83,3 +83,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
22 changes: 20 additions & 2 deletions .github/workflows/dev-connection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/connection-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/connection-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/connection-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/connection-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -83,3 +83,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
22 changes: 20 additions & 2 deletions .github/workflows/dev-ecosystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/ecosystem-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/ecosystem-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/ecosystem-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/ecosystem-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -83,3 +83,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
24 changes: 21 additions & 3 deletions .github/workflows/dev-issuance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:


env:
ECR_IMAGE_TAG: "ISSUANCE_v_${{ github.run_number }}"
ECR_IMAGE_TAG: "ISSUANCE_V_${{ github.run_number }}"
ECR_REPOSITORY: "dev-services"
AWS_REGION: "ap-southeast-1"
CLUSTER: "DEV-NGOTAG-CLUSTER"
Expand Down Expand Up @@ -70,12 +70,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/issuance-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/issuance-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/issuance-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/issuance-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -84,3 +84,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
22 changes: 20 additions & 2 deletions .github/workflows/dev-ledger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/ledger-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/ledger-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/ledger-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/ledger-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -84,3 +84,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
22 changes: 20 additions & 2 deletions .github/workflows/dev-notification-webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/notification-webhook-service.json
- name: Update Task Definition
- name: Update Task Definition and service
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/notification-webhook-service.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/notification-webhook-service.json)
SERVICE_NAME="${NAME}-service"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/notification-webhook-service.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
Expand All @@ -83,3 +83,21 @@ jobs:

# Register the task definition using the modified JSON file
aws ecs register-task-definition --family ${FAMILY} --cli-input-json file://${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json --region ${{ env.AWS_REGION }}

SERVICE_INFO=$(aws ecs describe-services --services ${SERVICE_NAME} --cluster ${CLUSTER} --region ap-southeast-1)

# Check if the service exists
if [ -z "$SERVICE_INFO" ]; then
echo "Service does not exist, creating new service..."
# Your logic to create a new service goes here
else
echo "Entered existing service"
# Extract desired count from the stored service info
DESIRED_COUNT=$(echo "$SERVICE_INFO" | jq -r '.services[].desiredCount')
if [ "$DESIRED_COUNT" = "0" ]; then
DESIRED_COUNT="1"
fi
# Update the existing service
REVISION=$(aws ecs describe-task-definition --task-definition ${FAMILY} --region ap-southeast-1 | jq -r '.taskDefinition.revision')
aws ecs update-service --cluster ${CLUSTER} --region ap-southeast-1 --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi
Loading

0 comments on commit a5cc9ff

Please sign in to comment.