Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build provider in kairos and bring tests #1592

Merged
merged 21 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,86 @@ jobs:
run: |
docker tag quay.io/kairos/core-${{ matrix.flavor }}:latest ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:24h
docker push ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}:24h
build-provider:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
id-token: write # OIDC support
contents: write
actions: read
security-events: write
strategy:
fail-fast: false
matrix:
flavor:
- "opensuse-leap"
- "alpine-opensuse-leap"
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 powershell firefox monodoc-manual msbuild || 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 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
- run: |
git fetch --prune --unshallow
- name: setup-docker
uses: docker-practice/actions-setup-docker@master
- name: Release space from worker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal, but should we move together with the other Release space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, didnt even noticed

run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
- name: Install earthly
uses: Luet-lab/luet-install-action@v1
with:
repository: quay.io/kairos/packages
packages: utils/earthly
- name: Build PR 🔧
if: ${{ github.event_name == 'pull_request' }}
env:
FLAVOR: ${{ matrix.flavor }}
IMAGE: ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}-provider:24h
run: |
earthly +ci --SECURITY_SCANS=false --IMAGE=$IMAGE --FLAVOR=$FLAVOR --PROVIDER_KAIROS=true
sudo mv build/* .
sudo rm -rf build
- uses: actions/upload-artifact@v3
with:
name: kairos-${{ matrix.flavor }}-provider.iso.zip
path: |
*.iso
*.sha256
if-no-files-found: error
- name: Push to testing
run: |
docker push ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}-provider:24h
build-framework:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
needs:
Expand Down Expand Up @@ -723,3 +803,124 @@ jobs:
run: |
export ISO=$PWD/$(ls *.iso)
.github/encryption-tests.sh

provider-tests:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: self-hosted
needs:
- build-provider
strategy:
fail-fast: false
max-parallel: 2
matrix:
label:
- "provider-qrcode-install"
- "provider-upgrade"
- "provider-decentralized-k8s"
- "provider-upgrade-k8s"
flavor:
- "opensuse-leap"
- "alpine-opensuse-leap"
exclude: # looks like only the k8s stuff is tested on both flavors
- label: "provider-qrcode-install"
flavor: "alpine-opensuse-leap"
- label: "provider-upgrade"
flavor: "alpine-opensuse-leap"
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: tests/go.mod
cache-dependency-path: tests/go.sum
- name: Install deps
run: |
# install qemu-system-x86_64 and qemu-img
sudo apt update
sudo apt install -y qemu-system-x86 qemu-utils qemu-kvm acl

# Allow the "runner" user to access /dev/kvm
# Might not be the best solution but adding to the kvm group didn't work
# https://askubuntu.com/a/1081326
sudo setfacl -m u:runner:rwx /dev/kvm
- name: Install earthly
uses: Luet-lab/luet-install-action@v1
with:
repository: quay.io/kairos/packages
packages: utils/earthly
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: kairos-${{ matrix.flavor }}-provider.iso.zip
- name: Run tests
env:
USE_QEMU: true
KVM: true
MEMORY: 4000
CPUS: 2
DRIVE_SIZE: 30000
CONTAINER_IMAGE: ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}-provider:24h
run: |
export ISO=$PWD/$(ls *.iso)
cp tests/go.* .
go run github.com/onsi/ginkgo/v2/ginkgo -v --label-filter "${{ matrix.label }}" --fail-fast -r ./tests/

provider-tests-upgrade-latest:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: self-hosted
strategy:
fail-fast: false
max-parallel: 2
matrix:
label:
- "provider-upgrade-latest-k8s-with-kubernetes"
flavor:
- "opensuse-leap"
- "alpine-opensuse-leap"
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: tests/go.mod
cache-dependency-path: tests/go.sum
- name: Install deps
run: |
# install qemu-system-x86_64 and qemu-img
sudo apt update
sudo apt install -y qemu-system-x86 qemu-utils qemu-kvm acl

# Allow the "runner" user to access /dev/kvm
# Might not be the best solution but adding to the kvm group didn't work
# https://askubuntu.com/a/1081326
sudo setfacl -m u:runner:rwx /dev/kvm
- name: Install earthly
uses: Luet-lab/luet-install-action@v1
with:
repository: quay.io/kairos/packages
packages: utils/earthly
- uses: actions/checkout@v3
- name: Download artifacts
uses: robinraju/[email protected]
with:
latest: true
repository: "kairos-io/provider-kairos"
fileName: "kairos-${{ matrix.flavor }}-*v1.25*.iso"
- name: Run tests
env:
USE_QEMU: true
KVM: true
MEMORY: 4000
CPUS: 2
DRIVE_SIZE: 30000
CONTAINER_IMAGE: ttl.sh/kairos-${{ matrix.flavor }}-${{ github.sha }}-provider:24h
run: |
export ISO=$PWD/$(ls *.iso)
cp tests/go.* .
go run github.com/onsi/ginkgo/v2/ginkgo -v --label-filter "${{ matrix.label }}" --fail-fast -r ./tests/
82 changes: 44 additions & 38 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ ARG FLAVOR=opensuse-leap
ARG BASE_URL=quay.io/kairos
ARG IMAGE=${BASE_URL}/${VARIANT}-${FLAVOR}:latest
ARG ISO_NAME=kairos-${VARIANT}-${FLAVOR}
ARG GITHUB_REPO=kairos-io/kairos
ARG OS_ID=kairos
ARG OS_REPO=quay.io/kairos/${VARIANT}-${FLAVOR}
ARG OS_NAME=${OS_ID}-${VARIANT}-${FLAVOR}
ARG OS_LABEL=latest
# renovate: datasource=docker depName=quay.io/luet/base
ARG LUET_VERSION=0.34.0
ARG OS_ID=kairos
# renovate: datasource=docker depName=aquasec/trivy
ARG TRIVY_VERSION=0.42.0
ARG COSIGN_SKIP=".*quay.io/kairos/.*"
Expand Down Expand Up @@ -37,7 +41,7 @@ ARG IMAGE_REPOSITORY_ORG=quay.io/kairos

all:
ARG SECURITY_SCANS=true
BUILD +image
BUILD +base-image
IF [ "$SECURITY_SCANS" = "true" ]
BUILD +image-sbom
BUILD +trivy-scan
Expand All @@ -50,7 +54,7 @@ all:
# For PR building, only image and iso are needed
ci:
ARG SECURITY_SCANS=true
BUILD +image
BUILD +base-image
IF [ "$SECURITY_SCANS" = "true" ]
BUILD +image-sbom
BUILD +trivy-scan
Expand All @@ -60,7 +64,7 @@ ci:

all-arm:
ARG SECURITY_SCANS=true
BUILD --platform=linux/arm64 +image --MODEL=rpi64
BUILD --platform=linux/arm64 +base-image --MODEL=rpi64
IF [ "$SECURITY_SCANS" = "true" ]
BUILD --platform=linux/arm64 +image-sbom --MODEL=rpi64
BUILD --platform=linux/arm64 +trivy-scan --MODEL=rpi64
Expand All @@ -76,10 +80,10 @@ all-arm:

arm-container-image:
ARG MODEL
BUILD --platform=linux/arm64 +image --MODEL=$MODEL
BUILD --platform=linux/arm64 +base-image --MODEL=$MODEL

all-arm-generic:
BUILD --platform=linux/arm64 +image --MODEL=generic
BUILD --platform=linux/arm64 +base-image --MODEL=generic
BUILD --platform=linux/arm64 +iso --MODEL=generic

go-deps-test:
Expand Down Expand Up @@ -205,6 +209,7 @@ framework-luet:
# COPY luet into the final framework
# TODO: Understand why?
COPY +luet/luet /framework/usr/bin/luet
COPY framework-profile.yaml /framework/etc/luet/luet.yaml
# more cleanup
RUN rm -rf /framework/var/luet
RUN rm -rf /framework/var/cache
Expand Down Expand Up @@ -261,6 +266,7 @@ base-image:
ARG MODEL
ARG FLAVOR
ARG VARIANT
ARG KAIROS_VERSION
ARG BUILD_INITRD="true"
IF [ "$BASE_IMAGE" = "" ]
# Source the flavor-provided docker file
Expand All @@ -269,21 +275,23 @@ base-image:
FROM $BASE_IMAGE
END

ARG KAIROS_VERSION
# Includes overlay/files
COPY (+framework/framework --FLAVOR=$FLAVOR --VERSION=$OS_VERSION --MODEL=$MODEL) /
# Avoid to accidentally push keys generated by package managers
RUN rm -rf /etc/ssh/ssh_host_*

# Set proper os-release file with all the info
IF [ "$KAIROS_VERSION" = "" ]
COPY +version/VERSION ./
ARG VERSION=$(cat VERSION)
RUN echo "version ${VERSION}"
ARG OS_VERSION=${VERSION}
RUN rm VERSION
ELSE
ELSE
ARG OS_VERSION=${KAIROS_VERSION}
END

# Includes overlay/files
COPY (+framework/framework --FLAVOR=$FLAVOR --VERSION=$OS_VERSION --MODEL=$MODEL) /
# Avoid to accidentally push keys generated by package managers
RUN rm -rf /etc/ssh/ssh_host_*
DO +OSRELEASE --HOME_URL=https://github.com/kairos-io/kairos --BUG_REPORT_URL=https://github.com/kairos-io/kairos/issues --GITHUB_REPO=kairos-io/kairos --VARIANT=${VARIANT} --FLAVOR=${FLAVOR} --OS_ID=${OS_ID} --OS_LABEL=${OS_LABEL} --OS_NAME=${OS_NAME} --OS_REPO=${OS_REPO} --OS_VERSION=${OS_VERSION}

# Enable services
IF [ -f /sbin/openrc ]
Expand Down Expand Up @@ -338,6 +346,27 @@ base-image:

# END

# Build with provider-kairos
# TODO: Allow installing from luet packages
ARG PROVIDER_KAIROS
ARG PROVIDER_KAIROS_BRANCH=main
IF [[ "$PROVIDER_KAIROS" != "" ]]
DO github.com/kairos-io/provider-kairos:main+PROVIDER_INSTALL --FLAVOR=$FLAVOR
# Redo os-release with override settings to point to provider-kairos stuff
# in earthly 0.7 we will be able to just override VARIANT here and just run the OSRELEASE once
mauromorales marked this conversation as resolved.
Show resolved Hide resolved
# but currently on 0.6 you cant override args properly as it picks the first arg it founds
# https://docs.earthly.dev/docs/earthfile#arg
# Overrides GITHUB_REPO, VARIANT, OS_REPO and OS_NAME to add the kairos name in there
# which points to the provider-kairos repo
DO +OSRELEASE --HOME_URL=https://github.com/kairos-io/kairos \
--BUG_REPORT_URL=https://github.com/kairos-io/kairos/issues \
--GITHUB_REPO=kairos-io/provider-kairos --VARIANT=kairos \
--OS_REPO=quay.io/kairos/kairos-${FLAVOR} \
--FLAVOR=${FLAVOR} --OS_ID=${OS_ID} --OS_LABEL=${OS_LABEL} \
--OS_NAME=${OS_ID}-kairos-${FLAVOR} \
--OS_VERSION=${OS_VERSION}
END

IF [[ "$FLAVOR" =~ ^ubuntu* ]]
# compress firmware
RUN find /usr/lib/firmware -type f -execdir zstd --rm -9 {} \+
Expand Down Expand Up @@ -382,39 +411,16 @@ base-image:
END
END


RUN rm -rf /tmp/*

image:
ARG BUILD_INITRD="true"
FROM +base-image --BUILD_INITRD=$BUILD_INITRD
ARG FLAVOR
ARG VARIANT
ARG MODEL
ARG KAIROS_VERSION
IF [ "$KAIROS_VERSION" = "" ]
COPY +version/VERSION ./
ARG VERSION=$(cat VERSION)
RUN echo "version ${VERSION}"
ARG OS_VERSION=${VERSION}
RUN rm VERSION
ELSE
ARG OS_VERSION=${KAIROS_VERSION}
END
ARG OS_ID
# should we add the model to the resulting iso?
ARG OS_NAME=${OS_ID}-${VARIANT}-${FLAVOR}
ARG OS_REPO=quay.io/kairos/${VARIANT}-${FLAVOR}
ARG OS_LABEL=latest
DO +OSRELEASE --HOME_URL=https://github.com/kairos-io/kairos --BUG_REPORT_URL=https://github.com/kairos-io/kairos/issues --GITHUB_REPO=kairos-io/kairos --VARIANT=${VARIANT} --FLAVOR=${FLAVOR} --OS_ID=${OS_ID} --OS_LABEL=${OS_LABEL} --OS_NAME=${OS_NAME} --OS_REPO=${OS_REPO} --OS_VERSION=${OS_VERSION}
SAVE IMAGE $IMAGE

image-rootfs:
FROM +image
FROM +base-image
SAVE ARTIFACT --keep-own /. rootfs

uki-artifacts:
FROM +image --BUILD_INITRD=false
FROM +base-image --BUILD_INITRD=false
RUN /usr/bin/immucore version
RUN ln -s /usr/bin/immucore /init
RUN find . \( -path ./sys -prune -o -path ./run -prune -o -path ./dev -prune -o -path ./tmp -prune -o -path ./proc -prune \) -o -print | cpio -R root:root -H newc -o | gzip -2 > /tmp/initramfs.cpio.gz
Expand Down Expand Up @@ -989,7 +995,7 @@ temp-image:

ARG TTL_IMAGE = "ttl.sh/${NAME}:${EXPIRATION}"

FROM +image
FROM +base-image
SAVE IMAGE --push $TTL_IMAGE

generate-schema:
Expand Down
Loading