-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild-nightly-images.yaml
More file actions
225 lines (202 loc) · 7.92 KB
/
Copy pathbuild-nightly-images.yaml
File metadata and controls
225 lines (202 loc) · 7.92 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
name: Build Nightly Images (Reusable)
on:
workflow_call:
inputs:
matrix-config:
description: 'JSON string containing the matrix configuration'
required: true
type: string
branch:
description: 'Branch to build from'
required: true
type: string
tag:
description: 'the tag to be used for the built image'
required: false
type: string
tested_repo:
description: |
The repository being tested (e.g., "konveyor/analyzer-lsp").
Used to determine which repo should use the PR/branch ref vs base ref.
If not provided, all repos use the branch ref.
required: false
type: string
outputs:
dependent-jobs:
description: 'Dependent jobs to build next'
value: ${{ jobs.build-images.outputs.dependent-jobs }}
jobs:
build-images:
name: Build Images ${{ matrix.image.image }}-${{ matrix.os.arch }}
runs-on: ${{ matrix.os.runner }}
env:
GONOSUMCHECK: "*"
GOFLAGS: "-mod=mod"
GOPROXY: direct
strategy:
fail-fast: false
matrix:
image: ${{ fromJSON(inputs.matrix-config).image }}
os: ${{ fromJSON(inputs.matrix-config).os }}
steps:
- name: Determine checkout ref
id: determine_ref
shell: bash
env:
TESTED_REPO: ${{ inputs.tested_repo }}
IMAGE_REPO: ${{ matrix.image.repo }}
OVERRIDE_REF: ${{ matrix.image.ref }}
BRANCH: ${{ inputs.branch }}
BASE_REF: ${{ github.base_ref }}
GH_REF: ${{ github.ref_name }}
run: |
if [ -n "$OVERRIDE_REF" ]; then
echo "ref=$OVERRIDE_REF" >> $GITHUB_OUTPUT
elif [ -z "$TESTED_REPO" ] || [ "$IMAGE_REPO" == "$TESTED_REPO" ]; then
echo "ref=$BRANCH" >> $GITHUB_OUTPUT
else
echo "ref=${BASE_REF:-$GH_REF}" >> $GITHUB_OUTPUT
fi
- name: Checkout repo
id: checkout
uses: actions/checkout@v5
with:
repository: ${{ matrix.image.repo }}
ref: ${{ steps.determine_ref.outputs.ref }}
- name: Get Go version from go.mod
id: go_version
shell: bash
run: |
GO_MOD_DIR="${{ matrix.image.go_mod_directory || '.' }}"
if [ -f "${GO_MOD_DIR}/go.mod" ]; then
GO_VERSION=$(grep '^go ' "${GO_MOD_DIR}/go.mod" | awk '{print $2}')
fi
echo "go_version=${GO_VERSION:-1.25}" >> $GITHUB_OUTPUT
- name: Setup golang
uses: actions/setup-go@v6
with:
go-version: "${{ steps.go_version.outputs.go_version }}"
- name: Apply go mod replaces
id: go_mod_replaces
shell: bash
if: matrix.image.go_mod_replaces != '' && matrix.image.go_mod_replaces[0] != null
env:
GO_MOD_REPLACES_JSON: ${{ toJSON(matrix.image.go_mod_replaces) }}
run: |
GO_MOD_DIR="${{ matrix.image.go_mod_directory || '.' }}"
cd "$GO_MOD_DIR"
echo "Applying go mod replaces in directory: $(pwd)"
REPLACE_ARGS=()
while IFS= read -r replace; do
echo " -replace $replace"
REPLACE_ARGS+=("-replace" "$replace")
done < <(echo "$GO_MOD_REPLACES_JSON" | jq -r '.[]')
go mod edit "${REPLACE_ARGS[@]}"
- name: Update go mod to the branch
id: go_mod
shell: bash
if: matrix.image.go_mod_update != '' && matrix.image.go_mod_update[0] != null
env:
GO_MOD_UPDATE_JSON: ${{ toJSON(matrix.image.go_mod_update) }}
run: |
# Change to the specified directory if provided, otherwise use current directory
GO_MOD_DIR="${{ matrix.image.go_mod_directory || '.' }}"
cd "$GO_MOD_DIR"
echo "Running go mod commands in directory: $(pwd)"
while IFS= read -r mod_update; do
echo "updating go mod $mod_update"
go get "$mod_update"
done < <(echo "$GO_MOD_UPDATE_JSON" | jq -r '.[]')
# Run go mod tidy to clean up
go mod tidy
- name: Get Tag
id: get_tag
shell: bash
env:
INPUT_TAG: ${{ inputs.tag }}
run: |
if [ -n "$INPUT_TAG" ]; then
INPUT_TAG+="_${{ matrix.os.arch }}"
echo "tag=$INPUT_TAG" >> $GITHUB_OUTPUT
else
date=$(date +'%Y.%m.%d')
date+="_${{ matrix.os.arch }}"
echo "tag=${{ inputs.branch }}_$date" >> $GITHUB_OUTPUT
fi
- name: build image
id: build-image
uses: konveyor/ci/build-image@main
with:
repo: ${{ matrix.image.repo }}
ref: ${{ (inputs.tested_repo == '' || matrix.image.repo == inputs.tested_repo) && inputs.branch || github.base_ref || github.ref_name }}
image_name: ${{ matrix.image.image }}
image_tag: ${{ steps.get_tag.outputs.tag }}
dockerfile_path: ${{ matrix.image.dockerfile_path }}
build_context: ${{ matrix.image.context_path }}
build_args: ${{ matrix.image.args }}
checked_out: true
base_image: ${{ matrix.image.base_image }}
base_image_arg: ${{ matrix.image.base_image_arg }}
build-manifest-lists:
needs: build-images
name: Build Manifest List And Save
runs-on: ubuntu-latest
strategy:
matrix:
image: ${{ fromJSON(inputs.matrix-config).image }}
steps:
- name: Get Tag
id: get_tag
shell: bash
env:
INPUT_TAG: ${{ inputs.tag }}
run: |
if [ -n "$INPUT_TAG" ]; then
NEW_TAG="$INPUT_TAG"
else
date=$(date +'%Y.%m.%d')
NEW_TAG="${{ inputs.branch }}_$date"
fi
echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
IMAGE_NAME="${{ matrix.image.image }}"
NEW_TAG+="_{amd64,arm64}"
FILE_NAME="${IMAGE_NAME//\//_}--${NEW_TAG//\//_}"
echo "download_pattern=$FILE_NAME" >> $GITHUB_OUTPUT
- name: Download provider image artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ steps.get_tag.outputs.download_pattern }}
path: /tmp/images
merge-multiple: true
- name: Build manifest list and save
shell: bash
id: build_image
run: |
podman manifest create ${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }}
for image in $(find /tmp/images -type f -name "*.tar"); do
echo "loading image: ${image}"
podman load -i "${image}"
podman images
echo "adding image: ${image}"
podman manifest add ${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }} docker-archive:"${image}"
done
echo "Loaded images:"
podman images
IMAGE_NAME="${{ matrix.image.image }}"
IMAGE_TAG="${{ steps.get_tag.outputs.tag }}"
FILE_NAME="${IMAGE_NAME//\//_}--${IMAGE_TAG//\//_}"
echo "Saving image to tar file..."
TAR_FILE="$PWD/image_artifact/${FILE_NAME}.tar"
mkdir -p image_artifact/
echo "Running podman manifest push --all ${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }} oci-archive://"${TAR_FILE}":${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }}"
podman manifest push --all ${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }} oci-archive://"${TAR_FILE}":${{ matrix.image.image }}:${{ steps.get_tag.outputs.tag }}
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "tar_file=${TAR_FILE}" >> $GITHUB_OUTPUT
echo "file_name=${FILE_NAME}" >> $GITHUB_OUTPUT
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build_image.outputs.file_name }}
path: ${{ steps.build_image.outputs.tar_file }}
retention-days: 1