1
- name : Build K3s
2
-
3
1
on :
4
2
workflow_call :
5
3
inputs :
6
4
arch :
7
5
type : string
8
- description : ' Architecture to build (ubuntu-latest or ubuntu-24.04- arm)'
9
- default : ' ubuntu-latest '
6
+ description : ' Architecture to build (amd64, arm64, or arm)'
7
+ default : ' amd64 '
10
8
os :
11
9
type : string
12
10
description : ' Target OS (linux or windows)'
15
13
type : boolean
16
14
required : false
17
15
default : false
16
+ cache :
17
+ type : string
18
+ description : ' Cache mode: "read", "write", or empty for no cache'
19
+ required : false
20
+ default : ' '
21
+
22
+ # Note that is workflow requires the following permissions:
23
+ # contents: read
24
+ # If using the cache: write option, you will need:
25
+ # packages: write
26
+ # If using the cache: read option, you will need:
27
+ # packages: read
28
+
18
29
19
- permissions :
20
- contents : read
21
30
22
31
jobs :
23
32
build :
24
- name : Build K3s (${{ inputs.os }} on ${{ inputs.arch }})
25
- runs-on : ${{ inputs.arch }}
33
+ name : Build # DO NOT CHANGE THIS NAME, we rely on it for INSTALL_K3S_PR functionality
34
+ runs-on : ${{ contains( inputs.arch, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
26
35
timeout-minutes : 20
27
36
env :
28
37
BIN_EXT : ${{ inputs.os == 'windows' && '.exe' || '' }}
29
- ARTIFACT_EXT : ${{ inputs.os == 'windows' && '-windows' || (contains(inputs.arch, 'arm') && '-arm64' || '' ) }}
38
+ ARCH_EXT : ${{ inputs.os == 'windows' && '-windows' || format('-{0}', inputs.arch ) }}
30
39
GOOS : ${{ inputs.os }}
31
40
steps :
32
41
- name : Checkout K3s
33
42
uses : actions/checkout@v4
34
-
35
- - name : Build K3s binary
43
+
44
+ - name : Set up QEMU
45
+ if : inputs.arch == 'arm'
46
+ uses : docker/setup-qemu-action@v3
47
+ with :
48
+ platforms : linux/arm/v7
49
+
50
+ - name : Set up Docker Buildx
51
+ uses : docker/setup-buildx-action@v3
52
+
53
+ - name : Determine Git Version Info
54
+ id : git_vars
55
+ run : |
56
+ source ./scripts/git_version.sh
57
+ {
58
+ echo "git_tag=${GIT_TAG}"
59
+ echo "tree_state=${TREE_STATE}"
60
+ echo "commit=${COMMIT}"
61
+ echo "dirty=${DIRTY}"
62
+ } >> "$GITHUB_OUTPUT"
63
+
64
+ - name : Login to GitHub Container Registry
65
+ if : inputs.cache == 'write'
66
+ uses : docker/login-action@v3
67
+ with :
68
+ registry : ghcr.io
69
+ username : ${{ github.repository_owner }}
70
+ password : ${{ secrets.GITHUB_TOKEN }}
71
+
72
+ - name : Build K3s Binary Native
73
+ if : inputs.arch != 'arm'
74
+ env :
75
+ DOCKER_BUILD_SUMMARY : false
76
+ uses : docker/build-push-action@v6
77
+ with :
78
+ context : .
79
+ file : ./Dockerfile.local
80
+ target : result
81
+ # Defined actions like this don't ingest GITHUB_ENV, so use outputs
82
+ # and manual set the build arguments
83
+ build-args : |
84
+ GIT_TAG=${{ steps.git_vars.outputs.git_tag }}
85
+ TREE_STATE=${{ steps.git_vars.outputs.tree_state }}
86
+ COMMIT=${{ steps.git_vars.outputs.commit }}
87
+ DIRTY=${{ steps.git_vars.outputs.dirty }}
88
+ cache-from : ${{ inputs.cache != '' && format('type=registry,ref=ghcr.io/{0}:cache-{1}', github.repository, inputs.arch) || '' }}
89
+ cache-to : ${{ inputs.cache == 'write' && format('type=registry,ref=ghcr.io/{0}:cache-{1},mode=max', github.repository, inputs.arch) || '' }}
90
+ push : false
91
+ provenance : mode=min
92
+ outputs : type=local,dest=.
93
+
94
+ - name : Build K3s Binary Emulated
95
+ if : inputs.arch != 'arm64' && inputs.arch != 'amd64'
96
+ env :
97
+ PLATFORM : ${{ inputs.arch == 'arm' && 'linux/arm/v7' || format('linux/{0}', inputs.arch) }}
98
+ DOCKER_BUILD_SUMMARY : false
99
+ uses : docker/build-push-action@v6
100
+ with :
101
+ context : .
102
+ file : ./Dockerfile.local
103
+ target : result
104
+ build-args : |
105
+ GIT_TAG=${{ steps.git_vars.outputs.git_tag }}
106
+ TREE_STATE=${{ steps.git_vars.outputs.tree_state }}
107
+ COMMIT=${{ steps.git_vars.outputs.commit }}
108
+ DIRTY=${{ steps.git_vars.outputs.dirty }}
109
+ push : false
110
+ provenance : mode=min
111
+ platforms : ${{ env.PLATFORM }}
112
+ outputs : type=local,dest=.
113
+
114
+ - name : Caculate binary checksum
36
115
run : |
37
- DOCKER_BUILDKIT=1 SKIP_IMAGE=1 SKIP_AIRGAP=1 SKIP_VALIDATE=1 GOCOVER=1 GOOS=${{ env.GOOS }} make
38
- sha256sum dist/artifacts/k3s${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.BIN_EXT }}.sha256sum
116
+ if [ ${{ inputs.arch }} == 'amd64' ]; then
117
+ sha256sum dist/artifacts/k3s${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.BIN_EXT }}.sha256sum
118
+ elif [ ${{ inputs.arch }} == "arm" ]; then
119
+ sha256sum dist/artifacts/k3s-armhf | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.ARCH_EXT }}.sha256sum
120
+ else
121
+ sha256sum dist/artifacts/k3s${{ env.ARCH_EXT }}${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.ARCH_EXT }}${{ env.BIN_EXT }}.sha256sum
122
+ fi
39
123
40
124
- name : Build K3s image
41
125
if : inputs.upload-image == true && inputs.os == 'linux'
42
- run : make package-image
126
+ run : ./scripts/ package-image
43
127
44
128
- name : " Save K3s image"
45
129
if : inputs.upload-image == true && inputs.os == 'linux'
48
132
- name : " Upload K3s Artifacts"
49
133
uses : actions/upload-artifact@v4
50
134
with :
51
- name : k3s${{ env.ARTIFACT_EXT }}
135
+ name : k3s${{ env.ARCH_EXT }}
52
136
path : dist/artifacts/k3s*
0 commit comments