Skip to content

Commit

Permalink
Fix more test and merge them
Browse files Browse the repository at this point in the history
also drop uneeded stuff in earthly and improve github workflow

Signed-off-by: Itxaka <itxaka@kairos.io>
  • Loading branch information
Itxaka committed Nov 18, 2024
1 parent 3e5c014 commit a2021ca
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 188 deletions.
46 changes: 31 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ concurrency:
group: ci-tests-${{ github.head_ref || github.ref }}-${{ github.repository }}
cancel-in-progress: true
jobs:
test:
unit-tests:
runs-on: kvm
steps:
- name: Checkout code
Expand All @@ -24,20 +24,16 @@ jobs:
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Build local image
uses: docker/build-push-action@v6
with:
push: false
load: true
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64
tags: auroraboot:latest
- name: Run tests
run: |
sudo go run github.com/onsi/ginkgo/v2/ginkgo -r -p --fail-fast --timeout=2h --skipPackage ./e2e ./...
test-e2e:
sudo go run github.com/onsi/ginkgo/v2/ginkgo -v -r -p --covermode=atomic --coverprofile=coverage.out --timeout=2h --skipPackage ./e2e ./...
- name: Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.out
e2e-tests:
runs-on: kvm
steps:
- name: Checkout code
Expand All @@ -48,10 +44,30 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Build local image
uses: docker/build-push-action@v6
with:
push: false
load: true
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64
tags: auroraboot:latest
- name: Run e2e tests
run: |
sudo go run github.com/onsi/ginkgo/v2/ginkgo -r -p --fail-fast --timeout=2h --label-filter "build-uki || genkey" ./e2e
sudo go run github.com/onsi/ginkgo/v2/ginkgo -v -r -p --covermode=atomic --coverprofile=coverage.out --timeout=2h --label-filter "!bootable" ./e2e
- name: Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.out
test-bootable:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ examples/airgap/build
examples/airgap/data
dist/
build/
coverage.out
coverage.out.*
63 changes: 6 additions & 57 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
VERSION 0.7
ARG --global GO_VERSION=1.23-bookworm

# renovate: datasource=docker depName=golang
ARG GO_VERSION=1.23
ARG --global GO_IMAGE=$GO_VERSION-bookworm

# renovate: datasource=github-releases depName=kairos-io/kairos
ARG IMAGE_VERSION=v3.2.1
Expand All @@ -16,50 +19,20 @@ version:
image:
FROM +version
ARG VERSION=$(cat VERSION)

FROM DOCKERFILE --build-arg VERSION=$VERSION -f Dockerfile .

SAVE IMAGE quay.io/kairos/auroraboot:$VERSION

test-label:
FROM alpine
WORKDIR /test
RUN apk add go docker jq
ENV GOPATH=/go
ENV FIXTURE_CONFIG=/test/tests/fixtures/raw_disk.yaml
ARG LABEL
COPY . .
WITH DOCKER \
--allow-privileged \
--load auroraboot:latest=+image
RUN pwd && ls -liah && go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo && /go/bin/ginkgo -r -p --randomize-all --procs 2 --fail-fast --timeout=2h --label-filter="$LABEL" --flake-attempts 3 ./...
END

build-iso:
FROM +image
ARG BASE_IMAGE
WORKDIR /build
COPY e2e/assets/keys /keys
# Extend the default cmdline to write everything to serial first :D
RUN /usr/bin/auroraboot build-uki --output-dir /build -k /keys --output-type iso -x "console==ttyS0" $BASE_IMAGE
RUN /usr/bin/auroraboot build-uki --output-dir /build -k /keys --output-type iso -x "console=ttyS0" $BASE_IMAGE
SAVE ARTIFACT /build/*.iso kairos.iso AS LOCAL build/kairos.iso

test:
FROM alpine
WORKDIR /test
RUN apk add go docker jq
ENV GOPATH=/go
ENV FIXTURE_CONFIG=/test/tests/fixtures/raw_disk.yaml
COPY . .
WITH DOCKER \
--allow-privileged \
--load auroraboot:latest=+image
RUN pwd && ls -liah && go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo && /go/bin/ginkgo -r -p --randomize-all --procs 2 --fail-fast --timeout=2h --flake-attempts 3 ./...
END

go-deps:
ARG GO_VERSION
FROM golang:$GO_VERSION
FROM golang:$GO_IMAGE
WORKDIR /build
COPY go.mod go.sum . # This will make the go mod download able to be cached as long as it hasnt change
RUN go mod download
Expand All @@ -82,27 +55,3 @@ test-bootable:
ARG CREATE_VM=true
RUN date
RUN go run github.com/onsi/ginkgo/v2/ginkgo run --label-filter "bootable" -v --fail-fast -r ./e2e

last-commit-packages:
FROM quay.io/skopeo/stable
RUN dnf install -y jq
WORKDIR build
ENV jqQuery='.Tags | map(select(. | contains("-repository.yaml"))) | sort_by(. | sub("v";"") | sub("-repository.yaml";"") | sub("-git.*";"") | .[0:12] | tonumber) | .[-1]'
RUN skopeo list-tags docker://quay.io/kairos/packages | jq -rc "${jqQuery}" > REPO_AMD64
RUN skopeo list-tags docker://quay.io/kairos/packages-arm64 | jq -rc "${jqQuery}" > REPO_ARM64
SAVE ARTIFACT REPO_AMD64 REPO_AMD64
SAVE ARTIFACT REPO_ARM64 REPO_ARM64

bump-repositories:
FROM mikefarah/yq
WORKDIR build
COPY +last-commit-packages/REPO_AMD64 REPO_AMD64
COPY +last-commit-packages/REPO_ARM64 REPO_ARM64
ARG REPO_AMD64=$(cat REPO_AMD64)
ARG REPO_ARM64=$(cat REPO_ARM64)
COPY image-assets/luet-amd64.yaml luet-amd64.yaml
COPY image-assets/luet-arm64.yaml luet-arm64.yaml
RUN yq eval ".repositories[0] |= . * { \"reference\": \"${REPO_AMD64}\" }" -i luet-amd64.yaml
RUN yq eval ".repositories[0] |= . * { \"reference\": \"${REPO_ARM64}\" }" -i luet-arm64.yaml
SAVE ARTIFACT luet-arm64.yaml AS LOCAL image-assets/luet-arm64.yaml
SAVE ARTIFACT luet-amd64.yaml AS LOCAL image-assets/luet-amd64.yaml
40 changes: 25 additions & 15 deletions e2e/arm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,36 @@ var _ = Describe("ARM image generation", Label("arm"), func() {
err = WriteConfig("test", tempDir)
Expect(err).ToNot(HaveOccurred())

aurora = NewAuroraboot("auroraboot", fmt.Sprintf("%s/config.yaml", tempDir))
aurora = NewAuroraboot("auroraboot")
// Map the config.yaml file to the container and the temp dir to the state dir
aurora.ManualDirs = map[string]string{
fmt.Sprintf("%s/config.yaml", tempDir): "/config.yaml",
tempDir: "/tmp/auroraboot",
}
})

AfterEach(func() {
os.RemoveAll(tempDir)
aurora.Cleanup()
})

It("generate a disk.img file", func() {
image := "quay.io/kairos/core-opensuse-leap-arm-rpi:latest"
_, err := PullImage(image)
Expect(err).ToNot(HaveOccurred())

out, err := aurora.Run(fmt.Sprintf(`--set container_image=docker://%s \
--set "disable_http_server=true" \
--set "disable_netboot=true" \
--cloud-config /config.yaml \
--set "disk.arm.model=rpi4" \
--set "state_dir=/tmp/auroraboot"`, image), tempDir)
out, err := aurora.Run("--debug",
"--set", "disable_http_server=true",
"--set", "disable_netboot=true",
"--set", "container_image=docker://"+image,
"--set", "state_dir=/tmp/auroraboot",
"--set", "disk.arm.model=rpi4",
"--cloud-config", "/config.yaml",
)
Expect(out).To(ContainSubstring("done"), out)
Expect(out).To(ContainSubstring("build-arm-image"), out)
Expect(err).ToNot(HaveOccurred())
_, err = os.Stat(filepath.Join(tempDir, "build/disk.img"))
_, err = os.Stat(filepath.Join(tempDir, "disk.img"))
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -53,17 +61,19 @@ var _ = Describe("ARM image generation", Label("arm"), func() {
_, err := PullImage(image)
Expect(err).ToNot(HaveOccurred())

out, err := aurora.Run(fmt.Sprintf(`--set container_image=docker://%s \
--set "disable_http_server=true" \
--set "disable_netboot=true" \
--cloud-config /config.yaml \
--set "disk.arm.prepare_only=true" \
--set "state_dir=/tmp/auroraboot"`, image), tempDir)
out, err := aurora.Run("--debug",
"--set", "disable_http_server=true",
"--set", "disable_netboot=true",
"--set", "container_image=docker://"+image,
"--set", "state_dir=/tmp/auroraboot",
"--set", "disk.arm.prepare_only=true",
"--cloud-config", "/config.yaml",
)
Expect(out).To(ContainSubstring("done"), out)
Expect(out).ToNot(ContainSubstring("build-arm-image"), out)
Expect(out).To(ContainSubstring("prepare_arm"), out)
Expect(err).ToNot(HaveOccurred())
_, err = os.Stat(filepath.Join(tempDir, "build/efi.img"))
_, err = os.Stat(filepath.Join(tempDir, "efi.img"))
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
Loading

0 comments on commit a2021ca

Please sign in to comment.