-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
required: false | ||
type: string | ||
default: "dev" | ||
|
||
jobs: | ||
deploy_workflow: | ||
name: Deploy static | ||
permissions: | ||
id-token: write | ||
contents: write | ||
environment: ${{ inputs.environment }} | ||
runs-on: ubuntu-latest | ||
env: | ||
APP_NAME: static-${{ inputs.environment }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Determine account number | ||
id: get_account_number | ||
run: | | ||
case "${{ inputs.environment }}" in | ||
"dev") | ||
echo "ACCOUNT_NUMBER=${{ secrets.DEV_ACCOUNT_NUMBER }}" >> $GITHUB_OUTPUT | ||
;; | ||
"staging") | ||
echo "ACCOUNT_NUMBER=${{ secrets.STAGING_ACCOUNT_NUMBER }}" >> $GITHUB_OUTPUT | ||
;; | ||
"prod") | ||
echo "ACCOUNT_NUMBER=${{ secrets.PROD_ACCOUNT_NUMBER }}" >> $GITHUB_OUTPUT | ||
;; | ||
*) | ||
echo "Error: Unknown environment!" | ||
exit 1 | ||
;; | ||
esac | ||
- name: Create taskdef file dynamically using parameters passed | ||
run: | | ||
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/${{ inputs.environment }}-taskdef.yaml \ | ||
".github/taskdefinition_template/taskdef_template.json" | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v3 | ||
with: | ||
aws-region: eu-west-1 | ||
role-to-assume: arn:aws:iam::${{ steps.get_account_number.outputs.ACCOUNT_NUMBER }}:role/${{ env.APP_NAME }}-GithubActionsRole | ||
role-session-name: GithubActionsSession | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- 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: "${{ env.APP_NAME }}-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/taskdefinition_template/${{ env.APP_NAME }}.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: "${{ env.APP_NAME }}" | ||
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: "${{ env.APP_NAME }}-ecs-service" | ||
cluster: "frontend-${{ inputs.environment }}-ecs-cluster" | ||
wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters