-
Notifications
You must be signed in to change notification settings - Fork 93
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 kots with apko+melange in presubmit #3959
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
presubmit-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's get on |
||
with: | ||
go-version: '1.20.x' | ||
- uses: chainguard-dev/actions/melange-build@main | ||
with: | ||
config: melange.yaml | ||
archs: x86_64 | ||
sign-with-temporary-key: true | ||
- uses: chainguard-images/actions/apko-publish@main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that this action pushes the image with a digest instead of a tag. Our tests currently leverages a |
||
with: | ||
config: apko.yaml | ||
archs: x86_64 | ||
tag: ttl.sh/kots | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably make integration easier if we match the chainguard image name to our current image name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, we will usually push the image with a namespace to avoid conflicts on ttl.sh. For example |
||
vcs-url: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,7 @@ kotsdata/ | |
sbom/ | ||
cosign.key | ||
pkg/tests/pull/cases/*/results | ||
|
||
melange.rsa | ||
melange.rsa.pub | ||
packages/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
contents: | ||
repositories: | ||
- https://packages.wolfi.dev/os | ||
- ./packages/ | ||
keyring: | ||
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub | ||
- ./melange.rsa.pub | ||
packages: | ||
- kots-head # This is expected to be built locally by `melange`. | ||
|
||
# All currently supported kubectl versions. | ||
# TODO: this requires manual intervention whenever there are new kubectl releases. | ||
- kubectl-1.24 | ||
- kubectl-1.25 | ||
- kubectl-1.26 | ||
- kubectl-1.27 | ||
|
||
- bash | ||
- busybox | ||
- curl | ||
- git | ||
- helm | ||
- kustomize | ||
- py3-dateutil | ||
- py3-magic | ||
- s3cmd | ||
- wolfi-baselayout | ||
|
||
accounts: | ||
groups: | ||
- groupname: kotsadm | ||
gid: 1001 | ||
users: | ||
- username: kotsadm | ||
uid: 1001 | ||
gid: 1001 | ||
run-as: kotsadm | ||
|
||
environment: | ||
VERSION: v1.98.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this refers to the KOTS version? I feel like this should be a variable assuming the file format supports them, else we need to |
||
KOTS_KUBECTL_BIN_DIR: /usr/local/bin | ||
KOTS_HELM_BIN_DIR: /usr/local/bin | ||
KOTS_KUSTOMIZE_BIN_DIR: /usr/local/bin | ||
|
||
entrypoint: | ||
command: /kotsadm | ||
|
||
cmd: api | ||
|
||
archs: | ||
- x86_64 | ||
- aarch64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we started supporting KOTS on arm64? If not, should we remove this? I don't feel like we're doing a lot of local dev on KOTS. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Building KOTS with apko + melange | ||
|
||
## What? | ||
|
||
This doc describes a non-production-ready process for building a minimal `kots` image using `melange` and `apko`: | ||
|
||
- [`melange`](https://github.com/chainguard-dev/melange) is a tool for reproducibly building APK packages from source | ||
- [`apko`](https://github.com/chainguard-dev/apko) is a tool for reproducibly building container images from APK packages | ||
|
||
## Why? | ||
|
||
Building with `melange` and `apko` produces smaller, more reproducible images, which can be easier to operate and easier to keep free of vulnerabilities. | ||
|
||
## How? | ||
|
||
First, build the package from source, using `melange`. | ||
|
||
To start, if there isn't already a signing key for the package, we need to generate one: | ||
|
||
```sh | ||
melange keygen | ||
``` | ||
|
||
We only need to build for x86_64, which is faster than building for arm64 since it doesn't require qemu. | ||
|
||
```sh | ||
melange build melange.yaml --arch=x86_64 | ||
``` | ||
|
||
> 💡 Only building for your local platform makes builds faster, since it doesn't have to emulate with qemu. | ||
> If you're on an arm64 machine (e.g., Apple Silicon), use `--arch=aarch64` here and below. | ||
|
||
Then, build the image from the newly built `kots` package, and the other packages needed by the image, using `apko`: | ||
|
||
```sh | ||
apko publish apko.yaml ttl.sh/kots --arch=x86_64 | ||
``` | ||
|
||
This will print the image to stdout, so you can run it: | ||
|
||
```sh | ||
docker run $(apko publish ...) | ||
``` | ||
|
||
### Presubmit GitHub Actions | ||
|
||
The above steps are automated in [GitHub Actions](./.github/workflows/presubmit-image.yaml) as a presubmit check for PRs. | ||
|
||
The image this workflow produces is only meant for validation, and not meant for production use cases at this time. | ||
|
||
## Further Reading | ||
|
||
- https://edu.chainguard.dev/open-source/melange/overview/ | ||
- https://edu.chainguard.dev/open-source/apko/overview/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package: | ||
name: kots-head | ||
version: 0.0.1 | ||
epoch: 0 | ||
description: Kubernetes Off-The-Shelf (KOTS) Software | ||
copyright: | ||
- license: Apache-2.0 | ||
|
||
environment: | ||
contents: | ||
repositories: | ||
- https://packages.wolfi.dev/os | ||
keyring: | ||
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub | ||
packages: | ||
- ca-certificates-bundle | ||
- busybox | ||
- git | ||
- go | ||
- nodejs | ||
- yarn | ||
|
||
pipeline: | ||
- runs: | | ||
set -x | ||
export DESTDIR="${{targets.destdir}}" | ||
mkdir -p "${DESTDIR}" | ||
|
||
# Scripts etc. | ||
mv deploy/assets/backup.sh "${DESTDIR}/backup.sh" | ||
mv deploy/assets/restore-db.sh "${DESTDIR}/restore-db.sh" | ||
mv deploy/assets/restore-s3.sh "${DESTDIR}/restore-s3.sh" | ||
mv deploy/assets/restore.sh "${DESTDIR}/restore.sh" | ||
mv deploy/assets/migrate-s3.sh "${DESTDIR}/migrate-s3.sh" | ||
mv deploy/assets/fs-minio-check.sh "${DESTDIR}/fs-minio-check.sh" | ||
mv deploy/assets/fs-minio-reset.sh "${DESTDIR}/fs-minio-reset.sh" | ||
mv deploy/assets/fs-minio-keys-sha.sh "${DESTDIR}/fs-minio-keys-sha.sh" | ||
mv deploy/assets/s3-bucket-create.sh "${DESTDIR}/s3-bucket-create.sh" | ||
mv deploy/assets/s3-bucket-head.sh "${DESTDIR}/s3-bucket-head.sh" | ||
mv deploy/assets/kots-upgrade.sh "${DESTDIR}/kots-upgrade.sh" | ||
mv deploy/assets/postgres "${DESTDIR}/postgres" | ||
|
||
# kotsadm and kots binaries | ||
export VERSION=${{package.version}} | ||
export GIT_TAG=${{package.version}} | ||
|
||
# Set environment variables from repository | ||
source .image.env | ||
|
||
KOTS_KUSTOMIZE_BIN_DIR=/usr/local/bin | ||
|
||
# TODO: fix pact build error on arm https://github.com/pact-foundation/pact-js-core/issues/264 | ||
export PACT_SKIP_BINARY_INSTALL=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should no longer be necessary as we should be on the latest version of pact-js which bundles the multi-arch Rust core. I'll submit a PR for kotsadm today to address that. |
||
|
||
# Configure Yarn | ||
yarn install --pure-lockfile --network-concurrency 1 | ||
|
||
make -C web deps lint build-kotsadm | ||
make vet kots build | ||
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move the static analysis steps into jobs outside of the package build, and just do the build here? That will allow us to parallelize those items and save some CI time. |
||
|
||
mv bin/kotsadm "${DESTDIR}/kotsadm" | ||
mv bin/kots "${DESTDIR}/kots" | ||
|
||
# TODO: this requires manual intervention whenever helm bumps its major version | ||
ln -s /usr/bin/helm ${{targets.destdir}}/usr/local/bin/helm | ||
ln -s /usr/bin/helm ${{targets.destdir}}/usr/local/bin/helm3 | ||
|
||
# TODO: this requires manual intervention whenever kustomize bumps its major version | ||
ln -s /usr/bin/kustomize ${{targets.destdir}}/usr/local/bin/kustomize | ||
ln -s /usr/bin/kustomize ${{targets.destdir}}/usr/local/bin/kustomize5 | ||
|
||
ln -s /usr/bin/kubectl ${{targets.destdir}}/usr/local/bin/kubectl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pin to a specific ubuntu major version (preferably 22.04)?