Skip to content

Update env variables setup for fixing warnings #6

Update env variables setup for fixing warnings

Update env variables setup for fixing warnings #6

Workflow file for this run

name: Static Deployment
on:
push:
branches:
- DEVOPS-2599-static-staging-app-infra
- dev
- staging
- main
paths:
- "network/**"
- ".github/workflows/deployment.yml"
- ".github/taskdefinition_template/*"
workflow_dispatch:
jobs:
set-env-variable:
runs-on: ubuntu-latest
outputs:
ENVIRONMENT: ${{ steps.set-env-var.outputs.ENVIRONMENT }}
ACCOUNT_NUMBER: ${{ steps.set-env-var.outputs.ACCOUNT_NUMBER }}
steps:
- name: Set Environment Variable
id: set-env-var
run: |
if [ "${{ github.ref }}" == "refs/heads/dev" ]; then
echo "ENVIRONMENT=dev" >> $GITHUB_OUTPUT
echo "ACCOUNT_NUMBER=058264511034" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/DEVOPS-2599-static-staging-app-infra" ]; then
echo "ENVIRONMENT=dev" >> $GITHUB_OUTPUT
echo "ACCOUNT_NUMBER=058264511034" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
echo "ENVIRONMENT=staging" >> $GITHUB_OUTPUT
echo "ACCOUNT_NUMBER=070528468658" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "ENVIRONMENT=prod" >> $GITHUB_OUTPUT
echo "ACCOUNT_NUMBER=042947190491" >> $GITHUB_OUTPUT
fi
deploy_workflow:
name: Deploy static-${{ needs.set-env-variable.outputs.ENVIRONMENT }}
needs: set-env-variable
permissions:
id-token: write
contents: write
environment: ${{ needs.set-env-variable.outputs.ENVIRONMENT }}
env:
DEPLOY_ENV: ${{ needs.set-env-variable.outputs.ENVIRONMENT }}
ACCOUNT_NUMBER: ${{ needs.set-env-variable.outputs.ACCOUNT_NUMBER }}
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/$DEPLOY_ENV-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::$ACCOUNT_NUMBER:role/static-$DEPLOY_ENV-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-$DEPLOY_ENV-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-$DEPLOY_ENV.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-$DEPLOY_ENV"
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-$DEPLOY_ENV-ecs-service"
cluster: "static-$DEPLOY_ENV-ecs-cluster"
wait-for-service-stability: true