-
Notifications
You must be signed in to change notification settings - Fork 7
102 lines (89 loc) · 3 KB
/
build-branch.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
name: build container image when branches are pushed
on:
push:
branches: ["*"]
jobs:
build:
strategy:
matrix:
runs-on:
- "ubuntu-latest"
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 10
if: github.event.pusher.name != 'dreamkast-cloudnativedays'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs
tags: |
type=sha,prefix=,format=long
type=ref,event=branch
- name: Prepare-tag
id: tags
run: |
arch=""
# https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context
case "${{ runner.arch }}" in
"X64" ) arch="amd64" ;;
"ARM64" ) arch="arm64" ;;
esac
echo "tag=${{ github.sha }}-${arch}" >> $GITHUB_OUTPUT
- name: Build
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ steps.tags.outputs.tag }}
provenance: false
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
merge-images:
runs-on: "ubuntu-latest"
timeout-minutes: 10
needs: ["build"]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Create a New Image
run: |
image_tag_sha="${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ github.sha }}"
docker buildx imagetools create \
--tag ${image_tag_sha} \
${image_tag_sha}-amd64
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ github.sha }}'
format: 'table'
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'