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 56b74ad commit 1152e82
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions .github/workflows/dev-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
push:
branches:
- pipeline-implementation

paths:
- 'apps/user/**'
workflow_dispatch:

env:
ECR_IMAGE_TAG: "USER_v_${{ github.run_number }}"
Expand Down Expand Up @@ -69,38 +71,37 @@ jobs:
- name: Update Task Definition
run: |
FAMILY=$(sed -n 's/.*"family": "\(.*\)",/\1/p' taskdef/agent-provisioning.json)
NAME=$(sed -n 's/.*"name": "\(.*\)",/\1/p' taskdef/agent-provisioning.json)
SERVICE_NAME="${NAME}-service"
echo "SERVICE_NAME: ${SERVICE_NAME}"
# Replace placeholders in the JSON file
sed -e "s;%BUILD_NUMBER%;${{ github.run_number }};g" -e "s;%REPOSITORY_URI%;${REPOSITORY_URI};g" taskdef/agent-provisioning.json > ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
# Debug: Print the content of the modified JSON file
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 }}
- 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 }})
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 }})
# 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')
# 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

0 comments on commit 1152e82

Please sign in to comment.