Rename pipeline #17
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
name: Deploy Application | |
on: | |
push: | |
branches: [main] | |
paths: | |
- '.github/workflows/deploy.yml' | |
- '.github/workflows/push-container.yml' | |
- 'src/**' | |
- 'container/**' | |
- 'template.yml' | |
workflow_dispatch: | |
env: | |
AWS_REGISTRY_URI: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com | |
AWS_REGION: us-east-1 | |
AWS_ROLE_TO_ASSUME: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/coderunner-pipeline-role | |
REPOSITORY_NAME: coderunner | |
CLOUDFORMATION_ROLE_ARN: arn:aws:iam::254837279431:role/coderunner-cloudformation-role | |
jobs: | |
push-container: | |
uses: ./.github/workflows/push-container.yml | |
secrets: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [push-container] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }} | |
aws-region: ${{ env.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Set REPOSITORY_URI | |
run: | | |
REPOSITORY_URI=$AWS_REGISTRY_URI/$REPOSITORY_NAME | |
echo "REPOSITORY_URI=$REPOSITORY_URI" >> "$GITHUB_ENV" | |
- name: Deploy template.yml | |
run: | | |
sam deploy --stack-name coderunner-dev \ | |
--no-fail-on-empty-changeset \ | |
--image-repositories CodeRunnerFunction=$REPOSITORY_URI \ | |
--capabilities CAPABILITY_IAM \ | |
--role-arn ${CLOUDFORMATION_ROLE_ARN} \ | |
--parameter-overrides \ | |
ImageUri=${{ env.REPOSITORY_URI }}:${{ github.run_id }} | |
delete-outdated-image: | |
runs-on: ubuntu-latest | |
needs: [deploy] | |
steps: | |
- uses: aws-actions/setup-sam@v2 | |
with: | |
use-installer: true | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }} | |
aws-region: ${{ env.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Delete images from ECR Repository | |
run: | | |
IMAGE_ID=$(aws ecr describe-images \ | |
--repository-name $REPOSITORY_NAME \ | |
--query "sort_by(imageDetails, &imagePushedAt) | reverse(@) | [1:].{imageId:imageTags[0]}") | |
for row in $(echo "${IMAGE_ID}" | jq -r '.[] | @base64'); do | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
aws ecr batch-delete-image \ | |
--repository-name $REPOSITORY_NAME \ | |
--image-ids imageTag=$(_jq '.imageId') | |
done |