-
Notifications
You must be signed in to change notification settings - Fork 22
187 lines (179 loc) · 6.39 KB
/
components.yaml
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
name: Components
on:
pull_request:
workflow_call:
inputs:
version:
type: string
required: false
description: "The version to use for the build"
default: ""
upload-ctf:
type: boolean
required: false
description: "Whether to upload the final CTF"
default: false
ref:
type: string
description: "The ref to use for the component build, defaults to the ref where the workflow was triggered from"
required: false
default: ""
push:
branches:
- main
permissions:
contents: read
pull-requests: read
env:
REF: ${{ inputs.ref == '' && github.ref || inputs.ref }}
CTF_TYPE: directory
components: '["ocmcli", "helminstaller", "helmdemo", "subchartsdemo", "ecrplugin", "jfrogplugin"]'
IMAGE_PLATFORMS: 'linux/amd64 linux/arm64'
PLATFORMS: 'windows/amd64 darwin/arm64 darwin/amd64 linux/amd64 linux/arm64'
BUILDX_CACHE_PUSH: false
BUILDX_CACHE_REF_BASE: ghcr.io/${{ github.repository }}/buildx-cache
jobs:
define-matrix:
runs-on: ubuntu-latest
outputs:
components: ${{ steps.componentMatrix.outputs.matrix }}
steps:
- id: componentMatrix
name: Set Components to be used for Build
run: |
echo "matrix=$input" >> $GITHUB_OUTPUT
env:
input: ${{ env.components }}
build:
name: "Build"
needs: define-matrix
strategy:
matrix:
component: ${{fromJSON(needs.define-matrix.outputs.components)}}
runs-on: large_runner
steps:
- name: Self Hosted Runner Post Job Cleanup Action
uses: TooMuch4U/[email protected]
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: '${{ github.workspace }}/go.mod'
cache: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get go environment for use with cache
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step
- name: CTF
run: |
cd components/${{ matrix.component }}
PATH=$PATH:$(go env GOPATH)/bin \
CTF_TYPE=${{ env.CTF_TYPE }} \
VERSION=${{ inputs.version }} \
PLATFORMS="${{ env.PLATFORMS }}" \
IMAGE_PLATFORMS="${{ env.IMAGE_PLATFORMS }}" \
BUILDX_CACHE_REF=${{ env.BUILDX_CACHE_REF_BASE }}:${{ matrix.component }} \
BUILDX_CACHE_PUSH=${{ env.BUILDX_CACHE_PUSH }} \
make \
ctf descriptor describe
- name: Upload CTF
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
overwrite: true
retention-days: 1
name: ctf-component-${{ matrix.component }}
path: gen/${{ matrix.component }}/ctf
aggregate:
name: "Aggregate"
runs-on: large_runner
needs: [build, define-matrix]
env:
components: ${{ join(fromJSON(needs.define-matrix.outputs.components), ' ') }}
steps:
- name: Self Hosted Runner Post Job Cleanup Action
uses: TooMuch4U/[email protected]
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Download CTFs
uses: actions/download-artifact@v4
with:
pattern: 'ctf-component-*'
path: gen/downloaded-ctfs
- name: Move CTFs into correct directory for aggregation
run: |
for i in ${{ env.components }}; do
mkdir -p ${{ github.workspace }}/gen/${i}
mv ${{ github.workspace }}/gen/downloaded-ctfs/ctf-component-${i} ${{ github.workspace }}/gen/${i}/ctf
ls -R ${{ github.workspace }}/gen/${i}
done
- name: Extract OCM Binary from CTF to avoid OCM Inception
id: extract-ocm
run: |
ocm_binary=$(bash ./hack/get_bare_resource_from_ctf.sh \
"ocm.software/ocmcli" \
"" \
"ocmcli" \
$(go env GOARCH) \
$(go env GOOS) \
"application/octet-stream" \
${{ github.workspace }}/gen/ocmcli/ctf)
new_loc=${{ github.workspace }}/bin/ocm
mkdir -p $(dirname $new_loc)
ln -s $ocm_binary $new_loc
chmod +x $new_loc
echo "OCM binary linked to $new_loc"
echo "binary=$new_loc" >> $GITHUB_OUTPUT
- name: Create aggregated CTF
run: |
for i in ${{ env.components }}; do
echo "transfering component $i..."
${{ steps.extract-ocm.outputs.binary }} transfer cv \
--type ${{ env.CTF_TYPE }} -V \
${{ github.workspace }}/gen/$i/ctf \
${{ github.workspace }}/gen/ctf
done
- name: Upload aggregated CTF
# only upload the artifact if we are not on a PR
if: inputs.upload-ctf
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
overwrite: true
retention-days: 30
name: ctf-aggregated
path: gen/ctf
- name: Delete old CTFs that lead up to aggregation
uses: geekyeggo/delete-artifact@v5
with:
name: |
ctf-component-*