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 09bb6f0 commit 50d3bef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dev-agent-provisioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:
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
cat ${GITHUB_WORKSPACE}/${NAME}-v_${{ github.run_number }}.json
# 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
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 }}
Expand Down
42 changes: 37 additions & 5 deletions .github/workflows/dev-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ on:
push:
branches:
- pipeline-implementation
paths:
- 'apps/user/**'
workflow_dispatch:


env:
ECR_IMAGE_TAG: "USER_v_${{ github.run_number }}"
ECR_REPOSITORY: "dev-services"
Expand Down Expand Up @@ -69,4 +66,39 @@ jobs:
run: |
sed -i "s#\"executionRoleArn\": \"arn:aws:iam::.*:role/ecsTaskExecutionRole\"#\"executionRoleArn\": \"arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ecsTaskExecutionRole\"#" taskdef/user-service.json
- name: Update Task Definition
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 }}

- 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')
aws ecs update-service --cluster ${CLUSTER} --region ${{ env.AWS_REGION }} --service ${SERVICE_NAME} --task-definition ${FAMILY}:${REVISION} --desired-count ${DESIRED_COUNT}
fi

0 comments on commit 50d3bef

Please sign in to comment.