-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (58 loc) · 2.19 KB
/
Copy pathdeploy.yml
File metadata and controls
69 lines (58 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Build and Deploy
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: pytest -q
deploy:
if: github.event_name == 'push'
needs: validate
runs-on: ubuntu-latest
environment: dev
permissions:
id-token: write
contents: read
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_REGION }}
- 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_SHA_TAG=dev-${{ github.sha }}
IMAGE_LATEST_TAG=dev-latest
IMAGE_SHA_URI=${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${IMAGE_SHA_TAG}
IMAGE_LATEST_URI=${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${IMAGE_LATEST_TAG}
docker build -t "$IMAGE_SHA_URI" -t "$IMAGE_LATEST_URI" .
docker push "$IMAGE_SHA_URI"
docker push "$IMAGE_LATEST_URI"
- name: Update ECS service
run: |
aws ecs update-service --cluster "${{ vars.ECS_CLUSTER }}" --service "${{ vars.ECS_SERVICE }}" --force-new-deployment