-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (74 loc) · 2.36 KB
/
deploy.yml
File metadata and controls
79 lines (74 loc) · 2.36 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
70
71
72
73
74
75
76
77
78
79
name: Deploy
on:
push:
branches: ["main"]
permissions:
id-token: write
contents: read
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: ssdlc-demo
IMAGE_TAG: ${{ github.sha }}
jobs:
build-scan-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Build Docker image
run: |
docker build -t $ECR_REPOSITORY:$IMAGE_TAG .
- name: Trivy scan
uses: aquasecurity/trivy-action@0.24.0
with:
image-ref: ${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
- name: Tag image with ECR registry
id: ecr
run: |
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
echo "account_id=$ACCOUNT_ID" >> $GITHUB_OUTPUT
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$IMAGE_TAG
- name: Push to ECR
run: |
docker push ${{ steps.ecr.outputs.account_id }}.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$IMAGE_TAG
terraform-apply:
needs: build-scan-push
runs-on: ubuntu-latest
defaults:
run:
working-directory: infra
steps:
- 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: ${{ env.AWS_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.5
- name: Terraform Init
run: terraform init -input=false
- name: Terraform Validate
run: terraform validate
- name: Checkov IaC scan
uses: bridgecrewio/checkov-action@v12
with:
directory: infra
quiet: true
framework: terraform
download_external_modules: true
- name: Terraform Plan
run: terraform plan -input=false -out=tfplan
# - name: Terraform Apply
# if: github.ref == 'refs/heads/main'
# run: terraform apply -input=false -auto-approve tfplan