Skip to content

Commit

Permalink
Update workflow to be included in same repository
Browse files Browse the repository at this point in the history
  • Loading branch information
sshrihar committed Mar 18, 2024
1 parent a385d1e commit ca6ecd7
Showing 1 changed file with 67 additions and 12 deletions.
79 changes: 67 additions & 12 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Static Deployment
on:
push:
branches:
- DEVOPS-2599-static-staging-app-infra
- dev
- staging
- main
Expand All @@ -23,23 +24,77 @@ jobs:
if [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "::set-output name=ENVIRONMENT::dev"
echo "::set-output name=ACCOUNT_NUMBER::058264511034"
elif [ "${{ github.ref }}" == "refs/heads/DEVOPS-2599-static-staging-app-infra" ]; then
echo "::set-output name=ENVIRONMENT::dev"
echo "::set-output name=ACCOUNT_NUMBER::058264511034"
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
echo "::set-output name=ENVIRONMENT::staging"
echo "::set-output name=ACCOUNT_NUMBER::070528468658"
elif [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "::set-output name=ENVIRONMENT::prod"
echo "::set-output name=ACCOUNT_NUMBER::042947190491"
fi
deploy:
uses: 0xPolygon/pipelines/.github/workflows/ecs_deploy_docker_taskdef.yaml@main
deploy_workflow:
name: Deploy static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}
needs: set-env-variable
with:
app_name: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}
taskdef_file_vars: .github/taskdef/${{ needs.set-env-variable.outputs.ENVIRONMENT }}-taskdef.yaml
account_number: "${{ needs.set-env-variable.outputs.ACCOUNT_NUMBER }}"
aws_region: eu-west-1
environment: ${{ needs.set-env-variable.outputs.ENVIRONMENT }}
docker_file: .github/Dockerfile
cluster_name: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}-ecs-cluster
secrets: inherit
permissions:
id-token: write
contents: write
environment: eu-west-1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create taskdef file dynamically using parameters passed
run: |
ls -lrt
export PIPENV_PIPFILE=.github/taskdefinition_template/Pipfile
python -m pip install --upgrade pip && \
pip install pipenv && \
pipenv install && \
pipenv run python ".github/taskdefinition_template/taskdef_creator.py" \
.github/taskdef/${{ needs.set-env-variable.outputs.ENVIRONMENT }}-taskdef.yaml \
".github/taskdefinition_template/taskdef_template.json"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::${{ needs.set-env-variable.outputs.ACCOUNT_NUMBER }}:role/static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}-GithubActionsRole
role-session-name: GithubActionsSession

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
ECR_REPOSITORY: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}-ecr
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Extract directory path
run: |
echo "TASKDEF_FILE=".github/taskdef/static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}.json" >> $GITHUB_ENV
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: "${{ env.TASKDEF_FILE }}"
container-name: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}-ecs-service
cluster: static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}-ecs-cluster
wait-for-service-stability: true

0 comments on commit ca6ecd7

Please sign in to comment.