1+ on :
2+ push :
3+ workflow_dispatch :
4+ workflow_call :
5+ outputs :
6+ image-tag :
7+ description : " image tag"
8+ value : ${{ jobs.build-and-test.outputs.image-tag }}
9+
10+ name : ci
11+
12+ jobs :
13+ build-and-test :
14+ runs-on : ubuntu-latest
15+ permissions :
16+ id-token : write # need this for OIDC
17+ contents : read
18+ actions : read
19+ security-events : write
20+ environment : ${{ github.ref_name }} # need this to fetch variables and secrets
21+ outputs :
22+ image-tag : ${{ steps.set-image-tag.outputs.IMAGE_TAG }}
23+
24+ steps :
25+ - name : Checkout Code
26+ uses : actions/checkout@v4
27+ with :
28+ fetch-depth : 0
29+
30+ - name : Configure AWS credentials
31+ uses : aws-actions/configure-aws-credentials@v4
32+ with :
33+ role-to-assume : ${{ secrets.ROLE_TO_ASSUME }}
34+ aws-region : ${{ vars.AWS_REGION }}
35+
36+ # cloudformation linting
37+ - name : Cfn Lint
38+ id : cfn-lint
39+ uses : scottbrenner/cfn-lint-action@v2
40+
41+ - name : Run Cfn Lint
42+ id : cfn-lint-run
43+ run : |
44+ shopt -s globstar # enable globbing
45+ cfn-lint --version
46+ cfn-lint -t ./templates/*.yaml
47+
48+ # cloudformation static analysis
49+ - name : Cfn Nag
50+ id : cfn-nag
51+ uses : stelligent/cfn_nag@master
52+ with :
53+ input_path : templates
54+ extra_args : -o sarif
55+ output_path : cfn_nag.sarif
56+
57+ - uses : github/codeql-action/upload-sarif@v3
58+ with :
59+ sarif_file : cfn_nag.sarif
60+
61+ # Build images
62+ - name : Login to Amazon ECR
63+ id : login-ecr
64+ uses : aws-actions/amazon-ecr-login@v2
65+
66+ # - name: Detect Dockerfile changes
67+ # id: detect-dockerfile-changes
68+ # uses: tj-actions/changed-files@v35
69+ # with:
70+ # files: app/**
71+
72+ # Checkout Amplify Repo
73+ - name : Checkout Amplify Repo
74+ run : |
75+ cd $GITHUB_WORKSPACE
76+ git clone https://github.com/ProgramEquity/amplify app
77+ cp $GITHUB_WORKSPACE/Dockerfile $GITHUB_WORKSPACE/app
78+ ls -l $GITHUB_WORKSPACE/app
79+
80+
81+ - name : Build, tag, and push image to AWS ECR
82+ id : build-image
83+ env :
84+ AWS_REGION : ${{ vars.AWS_REGION }}
85+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
86+ ECR_REPOSITORY : ${{ vars.ECR_REPO_NAME }}
87+ IMAGE_TAG : ${{ github.sha }}
88+ run : |
89+ echo "Building image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
90+ cd $GITHUB_WORKSPACE/app
91+ docker build \
92+ -t $ECR_REPOSITORY:latest \
93+ -t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
94+ -t $ECR_REPOSITORY:$IMAGE_TAG \
95+ -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
96+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
97+ docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
98+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
99+ echo "Pushed image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
100+
101+ - name : Set new image tag
102+ id : set-image-tag
103+ run : |
104+ echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
105+ echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
106+
107+ - name : ECR image scan
108+ id : image-scan
109+ uses :
alexjurkiewicz/[email protected] 110+ with :
111+ repository : ${{ vars.ECR_REPO_NAME }}
112+ tag : latest
113+
114+ - name : Check for critical vulnerabilities
115+ run : |
116+ if [ "${{ steps.image-scan.outputs.critical }}" != "0" ]; then
117+ echo "::error::Critical vulnerabilities found: ${{ steps.image-scan.outputs.critical }}"
118+ exit 1
119+ fi
120+
121+ - name : Summary
122+ id : summary
123+ run : |
124+ echo "## ECR Container Vulnerabilities found:" >> $GITHUB_STEP_SUMMARY
125+ echo "${{ steps.image-scan.outputs.critical }} Critical" >> $GITHUB_STEP_SUMMARY
126+ echo "${{ steps.image-scan.outputs.high }} High" >> $GITHUB_STEP_SUMMARY
127+ echo "${{ steps.image-scan.outputs.medium }} Medium" >> $GITHUB_STEP_SUMMARY
128+ echo "${{ steps.image-scan.outputs.low }} Low" >> $GITHUB_STEP_SUMMARY
129+ echo "${{ steps.image-scan.outputs.informational }} Info" >> $GITHUB_STEP_SUMMARY
130+ echo "${{ steps.image-scan.outputs.undefined }} Undefined" >> $GITHUB_STEP_SUMMARY
131+ echo "${{ steps.image-scan.outputs.total }} Total" >> $GITHUB_STEP_SUMMARY
132+ echo "" >> $GITHUB_STEP_SUMMARY # this is a blank line
133+ echo "## ECR Container Image:" >> $GITHUB_STEP_SUMMARY
134+ echo "image-tag: ${{ steps.set-image-tag.outputs.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY
0 commit comments