generated from eclipse-velocitas/vehicle-app-python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (186 loc) · 7.36 KB
/
build-docker-image.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# This file is maintained by velocitas CLI, do not modify manually. Change settings in .velocitas.json
# Copyright (c) 2022 Robert Bosch GmbH and Microsoft Corporation
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
name: Build Docker Image for single arch
on:
workflow_call:
inputs:
platform:
required: true
type: string
deployment-matrix-str:
required: true
type: string
multiarch:
required: false
type: boolean
default: false
outputs:
imageid:
value: ${{ jobs.build-image.outputs.imageid }}
imagedigest:
value: ${{ jobs.build-image.outputs.digest }}
jobs:
build-image:
name: "Building image (${{ matrix.component.name }})"
runs-on: ubuntu-latest
container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.1
strategy:
matrix:
component: ${{ fromJson(inputs.deployment-matrix-str) }}
outputs:
imageid: ${{ steps.image_build.outputs.imageid }}
imagedigest: ${{ steps.image_build.outputs.imagedigest }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: "recursive"
- name: Clone Release Documentation Action repository
uses: actions/checkout@v3
with:
repository: eclipse-velocitas/release-documentation-action
path: "./.github/actions"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- id: github-repository-name-case-adjusted
name: Prepare repository name in lower case for docker upload. This supports repository names in mixed case
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository }}
- uses: de-vri-es/setup-git-credentials@v2
with:
credentials: https://user:${{ secrets.GITHUB_TOKEN }}@github.com/
- name: Init velocitas project
run: |
velocitas init
- name: Setup git config
shell: bash
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Automation"
- name: Set Arguments for next step
id: set_args
run: |
if [ ${{ inputs.multiarch }} == true ]; then
echo "Build Multiarch"
echo "platforms=linux/amd64, linux/arm64" >> $GITHUB_OUTPUT
echo "type=oci,dest=./${{ matrix.component.name }}.tar" >> $GITHUB_OUTPUT
else
echo "Build ${{inputs.platform}}"
echo "platforms=linux/${{ inputs.platform }}" >> $GITHUB_OUTPUT
echo "type=docker,dest=./${{ matrix.component.name }}.tar" >> $GITHUB_OUTPUT
fi
shell: bash
- name: "${{ matrix.component.name }} -- Build image"
id: image_build
uses: docker/build-push-action@v4
with:
provenance: false
pull: true
push: false
outputs: |
type=${{ steps.set_args.outputs.type }}
file: ./app/Dockerfile
context: .
platforms: ${{ steps.set_args.outputs.platforms }}
secrets: |
"github_token=user:${{ secrets.GITHUB_TOKEN }}"
tags: ${{ github.sha }}
labels: |
org.opencontainers.image.source=https://github.com/${{steps.github-repository-name-case-adjusted.outputs.lowercase}}
- name: "Install skopeo"
run: |
sudo apt-get update
sudo apt-get -y install skopeo
- name: "${{ matrix.component.name }} -- Inspect tar image with skopeo"
run: |
skopeo inspect --raw oci-archive:${{ matrix.component.name }}.tar | jq
skopeo inspect oci-archive:${{ matrix.component.name }}.tar
skopeo copy oci-archive:${{ matrix.component.name }}.tar docker-archive:${{ matrix.component.name }}-arch.tar
- name: "${{ matrix.component.name }} -- Scan docker image for vulnerabilities"
uses: aquasecurity/[email protected]
with:
input: ${{ matrix.component.name }}-arch.tar
exit-code: "0"
ignore-unfixed: true
severity: "CRITICAL,HIGH"
format: "template"
template: "@.github/scripts/junit.tpl"
output: "junit.xml"
- name: "${{ matrix.component.name }} -- Show scan results"
if: ${{ always() }}
run: cat ./junit.xml
- name: "${{ matrix.component.name }} -- Package vulnerability scan files"
uses: ./.github/actions/package
with:
name: "VulnerabilityScan-${{ matrix.component.name }}"
type: "VulnerabilityScan"
schema: "JUnit"
sourcePath: ./junit.xml
packagePath: results/Documentation/renderer
- name: "${{ matrix.component.name }} -- Upload trivy report as artifacts"
if: ${{ always() && steps.image_build.outcome == 'success' }}
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
results/Documentation/renderer/*
- name: "${{ matrix.component.name }} -- Publish Trivy Scan Results"
uses: mikepenz/action-junit-report@v3
if: ${{ always() && steps.image_build.outcome == 'success' }}
with:
check_name: Trivy Scan Results (${{ matrix.component.name }})
report_paths: ./junit.xml
summary: true
update_check: true
annotate_only: true
- name: "${{ matrix.component.name }} -- Upload image to artifacts"
if: ${{ steps.image_build.outcome == 'success' }}
uses: actions/upload-artifact@v3
env:
VAPP_IMAGE: ${{ matrix.component.name }}-${{ inputs.platform }}
with:
name: ${{ env.VAPP_IMAGE }}
path: ./${{ matrix.component.name }}.tar
if-no-files-found: error
- name: "${{ matrix.component.name }} -- Upload AppManifest.json to artifacts"
if: ${{ steps.image_build.outcome == 'success' }}
uses: actions/upload-artifact@v3
with:
name: AppManifest
path: ./app/AppManifest.json
if-no-files-found: error
- name: Generate podspec.yaml
run: |
velocitas exec runtime-k3d generate-podspec
- name: "${{ matrix.component.name }} -- Upload generated podspec.yaml"
if: ${{ steps.image_build.outcome == 'success' }}
uses: actions/upload-artifact@v3
with:
name: Podspec
path: ./podspec.yaml
if-no-files-found: error
- name: Generate helm chart
run: |
velocitas exec runtime-k3d generate-helm
- name: "${{ matrix.component.name }} -- Upload generated helm chart"
if: ${{ steps.image_build.outcome == 'success' }}
uses: actions/upload-artifact@v3
with:
name: HelmChart
path: ./helm
if-no-files-found: error