From b047a4dc92ebe652f1c86d4f016c9a7ff0e23de1 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:41:40 -0700 Subject: [PATCH 01/11] add a k8s install test for pr workflow Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 96 ++++++++++++++++++++++++++++++++++++ .github/workflows/pr.yaml | 35 ++++++++----- 2 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..35f60cf --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,96 @@ +name: Build + +on: + workflow_call: + inputs: + push: + type: boolean + description: "Push package image" + required: false + default: false + target: + type: string + description: "Target to build" + required: false + default: "package" + branch: + type: string + description: "Branch to build" + required: false + default: "main" + envs: + type: string + description: "Environment variables to build" + required: false + default: "" + +env: + IMAGE_REPOSITORY: gcr.io/spectro-dev-public + +permissions: + contents: read + +jobs: + package: + runs-on: ubuntu-latest + steps: + - name: Release space from worker + run: | + echo "Listing top largest packages" + pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr) + head -n 30 <<< "${pkgs}" + echo + df -h + echo + sudo apt-get remove -y '^llvm-.*|^libllvm.*' || true + sudo apt-get remove --auto-remove android-sdk-platform-tools || true + sudo apt-get purge --auto-remove android-sdk-platform-tools || true + sudo rm -rf /usr/local/lib/android + sudo apt-get remove -y '^dotnet-.*|^aspnetcore-.*' || true + sudo rm -rf /usr/share/dotnet + sudo apt-get remove -y '^mono-.*' || true + sudo apt-get remove -y '^ghc-.*' || true + sudo apt-get remove -y '.*jdk.*|.*jre.*' || true + sudo apt-get remove -y 'php.*' || true + sudo apt-get remove -y hhvm || true + sudo apt-get remove -y powershell || true + sudo apt-get remove -y firefox || true + sudo apt-get remove -y monodoc-manual || true + sudo apt-get remove -y msbuild || true + sudo apt-get remove -y microsoft-edge-stable || true + sudo apt-get remove -y '^google-.*' || true + sudo apt-get remove -y azure-cli || true + sudo apt-get remove -y '^mongo.*-.*|^postgresql-.*|^mysql-.*|^mssql-.*' || true + sudo apt-get remove -y '^gfortran-.*' || true + sudo apt-get remove -y '^gcc-*' || true + sudo apt-get remove -y '^g++-*' || true + sudo apt-get remove -y '^cpp-*' || true + sudo apt-get autoremove -y + sudo apt-get clean + echo + echo "Listing top largest packages" + pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr) + head -n 30 <<< "${pkgs}" + echo + sudo rm -rfv build || true + df -h + - uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@master + with: + platforms: all + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@master + - name: Install earthly + uses: Luet-lab/luet-install-action@v1.1 + with: + repository: quay.io/kairos/packages + packages: utils/earthly + - run: earthly --ci +${{ inputs.target }} + if: ${{ !inputs.push }} + - run: earthly --ci --output --push +${{ inputs.target }} + if: ${{ inputs.push }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 72877e9..b260dc3 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,15 +1,28 @@ -# name: Pr +name: Pr -# on: [pull_request] +on: [pull_request] -# concurrency: -# group: ${{ github.pr_workflow }}-${{ github.ref }} -# cancel-in-progress: true +concurrency: + group: pr-${{ github.head_ref || github.ref_name }} + cancel-in-progress: true -# permissions: -# contents: read +permissions: + contents: write + pull-requests: write + issues: read + checks: write -# jobs: -# build: -# uses: ./.github/workflows/release.yaml -# secrets: inherit \ No newline at end of file +jobs: + k8s: + name: k8s install test + uses: ./.github/workflows/build.yaml + strategy: + matrix: + flavor: [k3s, kubeadm, rke2] + with: + target: build-provider-images + branch: ${{ github.head_ref }} + envs: | + TARGET=install-k8s + K8S_DISTRIBUTION=${{ matrix.flavor }} + ARCH=amd64 From 3af5425181a99ea812e3c4e8094dd5357c49bebb Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:43:52 -0700 Subject: [PATCH 02/11] disable cleanup by default Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 35f60cf..9adc25a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,6 +23,11 @@ on: description: "Environment variables to build" required: false default: "" + cleanup: + type: boolean + description: "Cleanup" + required: false + default: false env: IMAGE_REPOSITORY: gcr.io/spectro-dev-public @@ -35,6 +40,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Release space from worker + if: ${{ inputs.cleanup }} run: | echo "Listing top largest packages" pkgs=$(dpkg-query -Wf '${Installed-Size}\t${Package}\t${Status}\n' | awk '$NF == "installed"{print $1 "\t" $2}' | sort -nr) From b82866dcbff7f00b7dbaf1a0e456af4787903c7b Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:44:46 -0700 Subject: [PATCH 03/11] delete release workflow Signed-off-by: Nianyu Shen --- .github/workflows/release.yaml | 48 ---------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index c50d3d6..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# name: Release - -# on: -# push: -# tags: -# - v* - -# permissions: -# contents: write - -# concurrency: -# group: ${{ github.workflow }}-${{ github.ref }} -# cancel-in-progress: true - - -# jobs: -# release-iso-image: -# runs-on: ubuntu-latest -# steps: -# - name: Login to Docker Hub -# uses: docker/login-action@v2 -# with: -# username: ${{ secrets.DOCKERHUB_USERNAME }} -# password: ${{ secrets.DOCKERHUB_TOKEN }} -# - uses: actions/checkout@v3 -# - name: create .netrc file -# env: -# REPO_USER: ${{ secrets.REPO_USER }} -# REPO_TOKEN: ${{ secrets.REPO_TOKEN }} -# shell: bash -# run: | -# echo "machine github.com" > .netrc -# echo " login $REPO_USER" >> .netrc -# echo " password $REPO_TOKEN" >> .netrc -# echo "machine api.github.com" >> .netrc -# echo " login $REPO_USER" >> .netrc -# echo " password $REPO_TOKEN" >> .netrc -# - uses: earthly/actions-setup@v1 -# - run: ./earthly --ci --push -P --output +build-all-images --PE_VERSION=${{ github.ref_name }} -# - run: | -# if [[ "${{ github.ref }}" =~ .*-.*$ ]]; then -# echo "IS_PRERELEASE=true" > $GITHUB_ENV -# fi -# - uses: softprops/action-gh-release@v1 -# with: -# files: build/* -# prerelease: ${{ env.IS_PRERELEASE }} -# generate_release_notes: true \ No newline at end of file From 2b1383596b09eee95b7fb964c3f5514691943b40 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:46:40 -0700 Subject: [PATCH 04/11] set envs in build Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9adc25a..4044e00 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -36,7 +36,7 @@ permissions: contents: read jobs: - package: + build: runs-on: ubuntu-latest steps: - name: Release space from worker @@ -96,6 +96,13 @@ jobs: with: repository: quay.io/kairos/packages packages: utils/earthly + - name: Set environment variables + if: ${{ inputs.envs }} + run: | + for i in "${{ inputs.envs }}" + do + printf "%s\n" $i >> $GITHUB_ENV + done - run: earthly --ci +${{ inputs.target }} if: ${{ !inputs.push }} - run: earthly --ci --output --push +${{ inputs.target }} From d821f0eb7a1421b25de7bbf217060cd2732c290f Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:49:28 -0700 Subject: [PATCH 05/11] set .arg Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4044e00..cc9d044 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -96,13 +96,11 @@ jobs: with: repository: quay.io/kairos/packages packages: utils/earthly - - name: Set environment variables + - name: Set .arg file if: ${{ inputs.envs }} run: | - for i in "${{ inputs.envs }}" - do - printf "%s\n" $i >> $GITHUB_ENV - done + cat ${{ inputs.envs }} > .arg + cat .arg - run: earthly --ci +${{ inputs.target }} if: ${{ !inputs.push }} - run: earthly --ci --output --push +${{ inputs.target }} From a71647ad7fe033c08c66852bbf8996c76b60eee9 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:50:12 -0700 Subject: [PATCH 06/11] fix cat Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index cc9d044..ab227be 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -99,7 +99,7 @@ jobs: - name: Set .arg file if: ${{ inputs.envs }} run: | - cat ${{ inputs.envs }} > .arg + cat "${{ inputs.envs }}" > .arg cat .arg - run: earthly --ci +${{ inputs.target }} if: ${{ !inputs.push }} From b2390760facd070ba429a3bf75525173e39d788d Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:51:16 -0700 Subject: [PATCH 07/11] use echo instead of cat Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ab227be..19c131b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -99,7 +99,7 @@ jobs: - name: Set .arg file if: ${{ inputs.envs }} run: | - cat "${{ inputs.envs }}" > .arg + echo "${{ inputs.envs }}" > .arg cat .arg - run: earthly --ci +${{ inputs.target }} if: ${{ !inputs.push }} From 72e60908dc10c8c56663b9044d4255e926be7029 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:57:36 -0700 Subject: [PATCH 08/11] add cleanup Signed-off-by: Nianyu Shen --- .github/workflows/pr.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b260dc3..45ae9bc 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -20,6 +20,7 @@ jobs: matrix: flavor: [k3s, kubeadm, rke2] with: + cleanup: true target: build-provider-images branch: ${{ github.head_ref }} envs: | From 412e554c6aab161af33ac77de8aaf27bc0b3a279 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 08:58:51 -0700 Subject: [PATCH 09/11] add more cleanup Signed-off-by: Nianyu Shen --- .github/workflows/pr.yaml | 2 +- Earthfile | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 45ae9bc..86ea463 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -24,6 +24,6 @@ jobs: target: build-provider-images branch: ${{ github.head_ref }} envs: | - TARGET=install-k8s + TARGET=install-k8s-test K8S_DISTRIBUTION=${{ matrix.flavor }} ARCH=amd64 diff --git a/Earthfile b/Earthfile index 12cbf3f..d8607af 100644 --- a/Earthfile +++ b/Earthfile @@ -355,6 +355,10 @@ install-k8s: RUN rm -rf /output/var/cache/* SAVE ARTIFACT /output/* +install-k8s-test: + FROM +install-k8s + RUN rm -rf /output + build-uki-iso: FROM --platform=linux/${ARCH} $OSBUILDER_IMAGE ENV ISO_NAME=${ISO_NAME} From 1022b7825e28436babccbbd7732c59792aac9005 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 09:06:35 -0700 Subject: [PATCH 10/11] respect alpine image Signed-off-by: Nianyu Shen --- Earthfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index d8607af..b4d35e6 100644 --- a/Earthfile +++ b/Earthfile @@ -3,7 +3,7 @@ ARG TARGETOS ARG TARGETARCH # Default image repositories used in the builds. -ARG ALPINE_IMG=gcr.io/spectro-images-public/alpine:3.16.2 +ARG ALPINE_IMG=gcr.io/spectro-images-public/alpine:3.17 ARG SPECTRO_PUB_REPO=gcr.io/spectro-images-public ARG SPECTRO_LUET_REPO=gcr.io/spectro-dev-public ARG KAIROS_BASE_IMAGE_URL=gcr.io/spectro-images-public @@ -320,7 +320,7 @@ kairos-agent: SAVE ARTIFACT /usr/bin/kairos-agent /kairos-agent install-k8s: - FROM --platform=linux/${ARCH} alpine:3.19 + FROM --platform=linux/${ARCH} $ALPINE_IMG COPY +luet/luet /usr/bin/luet IF [ "$K8S_DISTRIBUTION" = "kubeadm" ] || [ "$K8S_DISTRIBUTION" = "kubeadm-fips" ] From 29b73d35377ffcd35fc3da7c24bbbadd26e9be87 Mon Sep 17 00:00:00 2001 From: Nianyu Shen Date: Fri, 26 Jul 2024 09:21:59 -0700 Subject: [PATCH 11/11] no cache Signed-off-by: Nianyu Shen --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 19c131b..b97b2b1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -101,7 +101,7 @@ jobs: run: | echo "${{ inputs.envs }}" > .arg cat .arg - - run: earthly --ci +${{ inputs.target }} + - run: earthly --ci --no-cache +${{ inputs.target }} if: ${{ !inputs.push }} - - run: earthly --ci --output --push +${{ inputs.target }} + - run: earthly --ci --output --push --no-cache +${{ inputs.target }} if: ${{ inputs.push }}