Skip to content

Commit 216ab93

Browse files
[backport] CI refactor to v2.1.x branch (#2146)
* Fix stackable sources for build-iso (#2061) * Fix stackable sources for build-iso * Move syncFunc as a parameter of DumpSource Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 22baf14) * Fix error return Signed-off-by: David Cassany <[email protected]> (cherry picked from commit f9934d7) * Change default root password Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 46a88e1) * Allow key pair of ssh connection in tests Signed-off-by: David Cassany <[email protected]> (cherry picked from commit a5f526d) * Set legacy password for upgrade test Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 6f0b28e) * Allow insecure registries (#2131) * Allow skipping TLS verification on registries Signed-off-by: David Cassany <[email protected]> * Improve error logging Signed-off-by: David Cassany <[email protected]> * Fix flag default value Signed-off-by: David Cassany <[email protected]> * Fix image extractor mock and use default TLS verification for tests Signed-off-by: David Cassany <[email protected]> --------- Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 22996ef) * Fix permissions * Set token to explicit content read permissions (cherry picked from commit 3d657c9) * Move permissions at top level (cherry picked from commit 8b8ae12) * Fix workflows, permissions at top level (cherry picked from commit d3da1cf) * Leftover from d3da1cf (cherry picked from commit 3206436) * Fix nested permissions definition Top level permissions can't be increased for specific jobs, hence setting the permission on each specific job on workflows that require more fine grain approach. In addition it removes the pull-request permission as this is mostly required for PR decorators, read/write labels, etc. (cherry picked from commit 1a0903a) * Refactor ci (#2137) * Refactor CI to use a local registry * Cache image and fetch image tarballs * Composite fetch images * Push to insecure registry with podman * Simplify workflow runs * Improve cache cleanup * Improve ip detection Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 644cdc7) * Fix cache cleaning for PRs and main pushes (#2144) * Fix cache cleaning for PRs and main pushes * Update .github/workflows/cache-cleanup.yaml Co-authored-by: Francesco Giudici <[email protected]> Signed-off-by: David Cassany Viladomat <[email protected]> (cherry picked from commit f54f683) * Remove unused steps in workflow Signed-off-by: David Cassany <[email protected]> (cherry picked from commit 51a85a7) (cherry picked from commit 9f8d14fea58c2e458f8840d274422352f0b0b1c2) * Do not fetch upstream go dependencies Signed-off-by: David Cassany <[email protected]> * Update cmd/cloud-init.go Missing err Co-authored-by: Francesco Giudici <[email protected]> Signed-off-by: David Cassany Viladomat <[email protected]> --------- Signed-off-by: David Cassany <[email protected]> Signed-off-by: David Cassany Viladomat <[email protected]> Co-authored-by: Francesco Giudici <[email protected]>
1 parent e536b50 commit 216ab93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+718
-408
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Pull images
2+
descriptions: Fetches and loads images from the cache
3+
4+
inputs:
5+
version:
6+
description: key of the cache and tag of the images
7+
required: true
8+
type: string
9+
flavor:
10+
description: flavor of the OS image
11+
required: false
12+
type: string
13+
toolkit:
14+
description: fetch toolkit image
15+
required: false
16+
default: 'true'
17+
type: 'boolean'
18+
os:
19+
description: fetch OS image
20+
required: false
21+
default: 'true'
22+
type: 'boolean'
23+
24+
runs:
25+
using: composite
26+
steps:
27+
- if: ${{ inputs.toolkit == 'true' }}
28+
name: Fetch toolkit image
29+
id: cache-toolkit
30+
uses: actions/cache/restore@v4
31+
env:
32+
cache-name: toolkit-build-x86_64-${{ github.event_name }}
33+
with:
34+
path: /tmp/toolkit.tar
35+
key: ${{ env.cache-name }}-${{ inputs.version }}
36+
fail-on-cache-miss: true
37+
- if: ${{ inputs.toolkit == 'true' }}
38+
name: Load toolkit image
39+
id: load-toolkit
40+
shell: bash
41+
run: |
42+
docker load -i /tmp/toolkit.tar
43+
- if: ${{ inputs.os == 'true' }}
44+
name: Fetch OS image
45+
id: cache-os
46+
uses: actions/cache/restore@v4
47+
env:
48+
cache-name: os-build-x86_64-${{ inputs.flavor }}-${{ github.event_name }}
49+
with:
50+
path: /tmp/os.tar
51+
key: ${{ env.cache-name }}-${{ inputs.version }}
52+
fail-on-cache-miss: true
53+
- if: ${{ inputs.os == 'true' }}
54+
name: Load OS image
55+
id: load-os
56+
shell: bash
57+
run: |
58+
docker load -i /tmp/os.tar

.github/actions/version/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Version hash
2+
descriptions: Computes the version hash from the current context
3+
4+
outputs:
5+
version:
6+
description: computed hash from current context
7+
value: ${{ steps.version.outputs.version }}
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Define version
13+
id: version
14+
shell: bash
15+
env:
16+
hash: ${{ hashFiles('Dockerfile', '**/go.sum', '**/pkg/**', '**/examples/**', '**/cmd/**', '**/vendor/**', '**/Makefile', '**/main.go') }}
17+
run: |
18+
version="${{ env.hash }}"
19+
version=${version::16}
20+
echo "version=${version}" >> $GITHUB_OUTPUT

.github/workflows/build.yaml

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
name: Build
22
on:
3+
pull_request:
34
push:
4-
tags:
5-
- v**
6-
pull_request_target:
7-
types:
8-
- opened
9-
- synchronize
10-
- reopened
11-
paths:
12-
- tests/**
13-
- make/**
14-
- Makefile
15-
- .github/**
16-
- pkg/**
17-
- cmd/**
18-
- go.mod
19-
- go.sum
20-
- examples/**
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
10+
cancel-in-progress: true
2111

2212
jobs:
2313
detect:
14+
permissions:
15+
contents: read
2416
runs-on: ubuntu-latest
2517
outputs:
2618
flavor: ${{ steps.set-matrix.outputs.flavor }}
@@ -42,29 +34,49 @@ jobs:
4234
fi
4335
4436
build-toolkit:
37+
permissions:
38+
contents: read
4539
needs:
4640
- detect
47-
permissions:
48-
packages: write
4941
runs-on: ubuntu-latest
5042
env:
5143
PLATFORM: ${{ needs.detect.outputs.platform }}
52-
TOOLKIT_REPO: ghcr.io/${{github.repository}}/elemental-cli
44+
outputs:
45+
version: ${{ steps.version.outputs.version }}
5346
steps:
5447
- uses: actions/checkout@v4
5548
with:
5649
ref: "${{ github.event.pull_request.head.sha }}"
5750
- run: |
5851
git fetch --prune --unshallow
59-
- name: Log in to ghcr.io
60-
uses: docker/login-action@v3
52+
- name: Define version
53+
id: version
54+
uses: ./.github/actions/version
55+
- name: Check cache for Toolkit image
56+
id: cache-toolkit
57+
uses: actions/cache/restore@v4
58+
env:
59+
cache-name: toolkit-build-x86_64-${{ github.event_name }}
60+
lookup-only: true
6161
with:
62-
registry: ghcr.io
63-
username: ${{ github.actor }}
64-
password: ${{ secrets.GITHUB_TOKEN }}
65-
- name: Build toolkit
62+
path: /tmp/toolkit.tar
63+
key: ${{ env.cache-name }}-${{ steps.version.outputs.version }}
64+
- if: ${{ steps.cache-toolkit.outputs.cache-hit != 'true' }}
65+
name: Build toolkit
66+
env:
67+
VERSION: ${{ steps.version.outputs.version }}
6668
run: |
67-
make DOCKER_ARGS=--push build
69+
make build-save
70+
mv build/elemental-toolkit*.tar /tmp/toolkit.tar
71+
- if: ${{ steps.cache-toolkit.outputs.cache-hit != 'true' }}
72+
name: Save toolkit image in cache
73+
id: save-toolkit
74+
uses: actions/cache/save@v4
75+
env:
76+
cache-name: toolkit-build-x86_64-${{ github.event_name }}
77+
with:
78+
path: /tmp/toolkit.tar
79+
key: ${{ env.cache-name }}-${{ steps.version.outputs.version }}
6880

6981
build-matrix:
7082
needs:
@@ -77,3 +89,4 @@ jobs:
7789
uses: ./.github/workflows/build_and_test_x86.yaml
7890
with:
7991
flavor: ${{ matrix.flavor }}
92+
version: ${{ needs.build-toolkit.outputs.version }}

.github/workflows/build_and_test_arm.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ on:
1111
type: string
1212

1313
concurrency:
14-
group: ci-${{ inputs.flavor }}-aarch64-${{ github.head_ref || github.ref }}-${{ github.repository }}
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}-${{ inputs.flavor }}-aarch64
1515
cancel-in-progress: true
1616

17-
jobs:
17+
permissions:
18+
contents: read
1819

20+
jobs:
1921
build-iso:
2022
needs: detect
2123
runs-on: [self-hosted, arm64]
@@ -120,9 +122,6 @@ jobs:
120122
uses: actions/setup-go@v5
121123
with:
122124
go-version-file: go.mod
123-
- name: Install deps
124-
run: |
125-
make test-deps
126125
- run: |
127126
git fetch --prune --unshallow
128127
- name: Cached Disk
@@ -174,9 +173,6 @@ jobs:
174173
uses: actions/setup-go@v5
175174
with:
176175
go-version-file: go.mod
177-
- name: Install deps
178-
run: |
179-
make test-deps
180176
- run: |
181177
git fetch --prune --unshallow
182178
- name: Cached ISO

0 commit comments

Comments
 (0)