mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-08-05 07:29:22 +00:00
Build k3s overhaul (#12200)
* Add full ci support without Dapper * Seperate git and other version tags, improves caching on binary builds * Use new local targets for build-k3s.yaml workflow * Allow optional ghcr build caching * Build binary using GHA native commands * Use internal setup-go action for e2e.yaml * Add emulation builds to k3s-build.yaml (for arm32 and future riscv64) * Be consistent in k3s artifact names * Fix package/dockerfile warnings * Fix install script for PR installs Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
114
.github/workflows/build-k3s.yaml
vendored
114
.github/workflows/build-k3s.yaml
vendored
@@ -1,12 +1,10 @@
|
||||
name: Build K3s
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
arch:
|
||||
type: string
|
||||
description: 'Architecture to build (ubuntu-latest or ubuntu-24.04-arm)'
|
||||
default: 'ubuntu-latest'
|
||||
description: 'Architecture to build (amd64, arm64, or arm)'
|
||||
default: 'amd64'
|
||||
os:
|
||||
type: string
|
||||
description: 'Target OS (linux or windows)'
|
||||
@@ -15,31 +13,117 @@ on:
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
cache:
|
||||
type: string
|
||||
description: 'Cache mode: "read", "write", or empty for no cache'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
# Note that is workflow requires the following permissions:
|
||||
# contents: read
|
||||
# If using the cache: write option, you will need:
|
||||
# packages: write
|
||||
# If using the cache: read option, you will need:
|
||||
# packages: read
|
||||
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build K3s (${{ inputs.os }} on ${{ inputs.arch }})
|
||||
runs-on: ${{ inputs.arch }}
|
||||
name: Build # DO NOT CHANGE THIS NAME, we rely on it for INSTALL_K3S_PR functionality
|
||||
runs-on: ${{ contains(inputs.arch, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
|
||||
timeout-minutes: 20
|
||||
env:
|
||||
BIN_EXT: ${{ inputs.os == 'windows' && '.exe' || '' }}
|
||||
ARTIFACT_EXT: ${{ inputs.os == 'windows' && '-windows' || (contains(inputs.arch, 'arm') && '-arm64' || '') }}
|
||||
ARCH_EXT: ${{ inputs.os == 'windows' && '-windows' || format('-{0}', inputs.arch) }}
|
||||
GOOS: ${{ inputs.os }}
|
||||
steps:
|
||||
- name: Checkout K3s
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build K3s binary
|
||||
|
||||
- name: Set up QEMU
|
||||
if: inputs.arch == 'arm'
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: linux/arm/v7
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Determine Git Version Info
|
||||
id: git_vars
|
||||
run: |
|
||||
DOCKER_BUILDKIT=1 SKIP_IMAGE=1 SKIP_AIRGAP=1 SKIP_VALIDATE=1 GOCOVER=1 GOOS=${{ env.GOOS }} make
|
||||
sha256sum dist/artifacts/k3s${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.BIN_EXT }}.sha256sum
|
||||
source ./scripts/git_version.sh
|
||||
{
|
||||
echo "git_tag=${GIT_TAG}"
|
||||
echo "tree_state=${TREE_STATE}"
|
||||
echo "commit=${COMMIT}"
|
||||
echo "dirty=${DIRTY}"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: inputs.cache == 'write'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build K3s Binary Native
|
||||
if: inputs.arch != 'arm'
|
||||
env:
|
||||
DOCKER_BUILD_SUMMARY: false
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.local
|
||||
target: result
|
||||
# Defined actions like this don't ingest GITHUB_ENV, so use outputs
|
||||
# and manual set the build arguments
|
||||
build-args: |
|
||||
GIT_TAG=${{ steps.git_vars.outputs.git_tag }}
|
||||
TREE_STATE=${{ steps.git_vars.outputs.tree_state }}
|
||||
COMMIT=${{ steps.git_vars.outputs.commit }}
|
||||
DIRTY=${{ steps.git_vars.outputs.dirty }}
|
||||
cache-from: ${{ inputs.cache != '' && format('type=registry,ref=ghcr.io/{0}:cache-{1}', github.repository, inputs.arch) || '' }}
|
||||
cache-to: ${{ inputs.cache == 'write' && format('type=registry,ref=ghcr.io/{0}:cache-{1},mode=max', github.repository, inputs.arch) || '' }}
|
||||
push: false
|
||||
provenance: mode=min
|
||||
outputs: type=local,dest=.
|
||||
|
||||
- name: Build K3s Binary Emulated
|
||||
if: inputs.arch != 'arm64' && inputs.arch != 'amd64'
|
||||
env:
|
||||
PLATFORM: ${{ inputs.arch == 'arm' && 'linux/arm/v7' || format('linux/{0}', inputs.arch) }}
|
||||
DOCKER_BUILD_SUMMARY: false
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.local
|
||||
target: result
|
||||
build-args: |
|
||||
GIT_TAG=${{ steps.git_vars.outputs.git_tag }}
|
||||
TREE_STATE=${{ steps.git_vars.outputs.tree_state }}
|
||||
COMMIT=${{ steps.git_vars.outputs.commit }}
|
||||
DIRTY=${{ steps.git_vars.outputs.dirty }}
|
||||
push: false
|
||||
provenance: mode=min
|
||||
platforms: ${{ env.PLATFORM }}
|
||||
outputs: type=local,dest=.
|
||||
|
||||
- name: Caculate binary checksum
|
||||
run: |
|
||||
if [ ${{ inputs.arch }} == 'amd64' ]; then
|
||||
sha256sum dist/artifacts/k3s${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.BIN_EXT }}.sha256sum
|
||||
elif [ ${{ inputs.arch }} == "arm" ]; then
|
||||
sha256sum dist/artifacts/k3s-armhf | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.ARCH_EXT }}.sha256sum
|
||||
else
|
||||
sha256sum dist/artifacts/k3s${{ env.ARCH_EXT }}${{ env.BIN_EXT }} | sed 's|dist/artifacts/||' > dist/artifacts/k3s${{ env.ARCH_EXT }}${{ env.BIN_EXT }}.sha256sum
|
||||
fi
|
||||
|
||||
- name: Build K3s image
|
||||
if: inputs.upload-image == true && inputs.os == 'linux'
|
||||
run: make package-image
|
||||
run: ./scripts/package-image
|
||||
|
||||
- name: "Save K3s image"
|
||||
if: inputs.upload-image == true && inputs.os == 'linux'
|
||||
@@ -48,5 +132,5 @@ jobs:
|
||||
- name: "Upload K3s Artifacts"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: k3s${{ env.ARTIFACT_EXT }}
|
||||
name: k3s${{ env.ARCH_EXT }}
|
||||
path: dist/artifacts/k3s*
|
||||
28
.github/workflows/e2e.yaml
vendored
28
.github/workflows/e2e.yaml
vendored
@@ -29,14 +29,22 @@ permissions:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write # permissions cannot be conditional, so we need to set this for all jobs
|
||||
uses: ./.github/workflows/build-k3s.yaml
|
||||
with:
|
||||
upload-image: true
|
||||
cache: ${{ github.ref == 'refs/heads/master' && 'write' || 'read' }}
|
||||
build-arm64:
|
||||
uses: ./.github/workflows/build-k3s.yaml
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
with:
|
||||
arch: ubuntu-24.04-arm
|
||||
arch: arm64
|
||||
upload-image: true
|
||||
cache: ${{ github.ref == 'refs/heads/master' && 'write' || 'read' }}
|
||||
e2e:
|
||||
name: "E2E Tests"
|
||||
needs: build
|
||||
@@ -71,10 +79,7 @@ jobs:
|
||||
- name: "Vagrant Plugin(s)"
|
||||
run: vagrant plugin install vagrant-k3s vagrant-reload vagrant-scp
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
cache: false
|
||||
uses: ./.github/actions/setup-go
|
||||
- name: Install Kubectl
|
||||
run: |
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
@@ -82,7 +87,7 @@ jobs:
|
||||
- name: "Download k3s binary"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: k3s
|
||||
name: k3s-amd64
|
||||
path: ./dist/artifacts
|
||||
|
||||
- name: Run ${{ matrix.etest }} Test
|
||||
@@ -177,17 +182,10 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: "Download K3s image (amd64)"
|
||||
if: ${{ matrix.arch == 'amd64' }}
|
||||
- name: "Download K3s image"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: k3s
|
||||
path: ./dist/artifacts
|
||||
- name: "Download K3s image (arm64)"
|
||||
if: ${{ matrix.arch == 'arm64' }}
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: k3s-arm64
|
||||
name: k3s-${{ matrix.arch }}
|
||||
path: ./dist/artifacts
|
||||
- name: Load and set K3s image
|
||||
run: |
|
||||
|
||||
2
.github/workflows/install.yaml
vendored
2
.github/workflows/install.yaml
vendored
@@ -54,7 +54,7 @@ jobs:
|
||||
- name: "Download k3s binary"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: k3s
|
||||
name: k3s-amd64
|
||||
path: tests/install/${{ matrix.vm }}
|
||||
- name: "Vagrant Up"
|
||||
run: vagrant up --no-tty --no-provision
|
||||
|
||||
6
.github/workflows/integration.yaml
vendored
6
.github/workflows/integration.yaml
vendored
@@ -29,9 +29,13 @@ env:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
uses: ./.github/workflows/build-k3s.yaml
|
||||
with:
|
||||
os: linux
|
||||
cache: read
|
||||
build-windows:
|
||||
uses: ./.github/workflows/build-k3s.yaml
|
||||
with:
|
||||
@@ -56,7 +60,7 @@ jobs:
|
||||
- name: "Download k3s binary"
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: k3s
|
||||
name: k3s-amd64
|
||||
path: ./dist/artifacts
|
||||
- name: Run Integration Tests
|
||||
run: |
|
||||
|
||||
3
.github/workflows/trivy.yaml
vendored
3
.github/workflows/trivy.yaml
vendored
@@ -36,8 +36,7 @@ jobs:
|
||||
|
||||
- name: Build K3s Image
|
||||
run: |
|
||||
make local
|
||||
make package-image
|
||||
make local-image
|
||||
make tag-image-latest
|
||||
|
||||
- name: Download Rancher's VEX Hub report
|
||||
|
||||
Reference in New Issue
Block a user