-
Notifications
You must be signed in to change notification settings - Fork 2
105 lines (80 loc) · 3.63 KB
/
base-image-build-pr-main-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
102
103
104
name: Test, lint and build PHP base Image on Shared Core ECR
run-name: Test, lint and build PHP base Image on Shared Core ECR
on:
pull_request:
branches:
- main
jobs:
php-base-image-build:
runs-on: ubuntu-latest
env:
AWS_REGION : ${{ vars.DVSA_AWS_REGION }} #Change to reflect your Region
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID_SHAREDCOREECR }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
steps:
- uses: actions/checkout@v3
- name: Lint check on dockerfile
run: |
jq -c '.[]' build.json | while read -r results; do
build=$(echo "$results" | jq -r '.build')
repoName=$(echo "$results" | jq -r '.repoName')
dockerFile=$(echo "$results" | jq -r '.dockerFile')
if [ "$build" == "true" ]; then
#docker run --rm --privileged -v `pwd`:/root/ projectatomic/dockerfile-lint dockerfile_lint -f build/$repoName/$dockerFile
docker run --rm -i hadolint/hadolint hadolint -t error - < build/$repoName/$dockerFile
else
echo "Not linting - $repoName, build parameter equal to false"
fi
done
#falfast - credential configuration only to detect failure on PR
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
aws-region: ${{ vars.DVSA_AWS_REGION }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
#failfast - credential configuration only to detect failure on PR
- name: Login to Shared Core ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'
#Action can not be used, no good way to loop through action on Github yet
- name: Install snyk cli
run: |
npm install -g snyk
- name: Build the Docker image
run: |
SHA=$(git rev-parse --short HEAD)
# Iterate over JSON objects in build.json
jq -c '.[]' build.json | while read -r results; do
repoName=$(echo "$results" | jq -r '.repoName')
dockerFile=$(echo "$results" | jq -r '.dockerFile')
tag=$(echo "$results" | jq -r '.tag')
build=$(echo "$results" | jq -r '.build')
if [ "$build" == "true" ]; then
echo "Building $repoName ..."
buildTag="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$repoName:$tag-$SHA"
docker build -t "$buildTag" --file "./build/$repoName/$dockerFile" build/.
else
echo "Not building - $repoName, build parameter equal to false"
fi
done
- name: snyk scan api image
run: |
SHA=$(git rev-parse --short HEAD)
# Iterate over JSON objects in build.json
jq -c '.[]' build.json | while read -r results; do
repoName=$(echo "$results" | jq -r '.repoName')
tag=$(echo "$results" | jq -r '.tag')
build=$(echo "$results" | jq -r '.build')
if [ "$build" == "true" ]; then
snyk container test $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$repoName:$tag-$SHA --severity-threshold=critical
else
echo "Not scanning - $repoName, build parameter equal to false"
fi
done
continue-on-error: true # critical vulnerability found fix and remove this tag