Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,39 @@ jobs:
- name: Run tests
run: pytest -q

build-and-push:
deploy:
if: github.event_name == 'push'
needs: validate
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
packages: write
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_REGION }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/simple-ecs-python-app:latest
- name: Ensure ECR repository exists
run: |
aws ecr describe-repositories --repository-names ${{ vars.ECR_REPOSITORY }} >/dev/null 2>&1 || \
aws ecr create-repository --repository-name ${{ vars.ECR_REPOSITORY }}

- name: Log in to Amazon ECR
run: |
aws ecr get-login-password --region ${{ vars.AWS_REGION }} | \
docker login --username AWS --password-stdin ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com

- name: Build and push Docker image to ECR
run: |
IMAGE_URI=${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
docker build -t "$IMAGE_URI" .
docker push "$IMAGE_URI"

- name: Update ECS service
run: |
aws ecs update-service --cluster "${{ vars.ECS_CLUSTER }}" --service "${{ vars.ECS_SERVICE }}" --force-new-deployment
Loading