generated from abirismyname/actions-hackpod-template
-
Notifications
You must be signed in to change notification settings - Fork 3
101 lines (83 loc) · 4.01 KB
/
ci.yml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
on:
workflow_dispatch:
workflow_call:
outputs:
image-tag:
description: "image tag"
value: ${{ jobs.build-and-test.outputs.image-tag }}
name: ci
jobs:
build-and-test:
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.set-image-tag.outputs.IMAGE_TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Echo
run: echo "CI..."
# TODO:
# Configure dynamic credentials to AWS, check out the action: aws-actions/configure-aws-credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: ${{vars.AWS_REGION}}
# Lint the CloudFormation template (templates/), check out the action: scottbrenner/cfn-lint-action
# Perform static analysis against the CloudFormation template, check out the action: stelligent/cfn_nag@master
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Checkout Amplify Repo (we do this so that you can start to build the Amplify app from this repo)
- name: Checkout Amplify Repo
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/ProgramEquity/amplify app
cp $GITHUB_WORKSPACE/Dockerfile $GITHUB_WORKSPACE/app
ls -l $GITHUB_WORKSPACE/app
# Build the Amplify app and create a docker image, relevant actions: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to AWS ECR
id: build-image
env:
AWS_REGION: ${{ vars.AWS_REGION }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.ECR_REPO_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
echo "Building image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
cd $GITHUB_WORKSPACE/app
docker build \
-t $ECR_REPOSITORY:latest \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
-t $ECR_REPOSITORY:$IMAGE_TAG \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "Pushed image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Set new image tag
id: set-image-tag
run: |
[[ -z $IMAGE_TAG ]] && echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT && echo "IMAGE_TAG=latest" >> $GITHUB_ENV || echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT && echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: ECR image scan
id: image-scan
uses: alexjurkiewicz/[email protected]
with:
repository: ${{ vars.ECR_REPO_NAME }}
tag: latest
- name: Summary
id: summary
run: |
echo "## ECR Container Vulnerabilities found:" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.critical }} Critical" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.high }} High" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.medium }} Medium" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.low }} Low" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.informational }} Info" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.undefined }} Undefined" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.image-scan.outputs.total }} Total" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY # this is a blank line
echo "## ECR Container Image:" >> $GITHUB_STEP_SUMMARY
echo "image-tag: ${{ steps.set-image-tag.outputs.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY
# Scan the docker image in ECR, check out the action: alexjurkiewicz/ecr-scan-image for inspiration
# Create build summary output