Skip to content

Commit

Permalink
chore(ci): build and tag all image architectures (#1160)
Browse files Browse the repository at this point in the history
* chore(ci): build multi-arch images

* build multi-arch images

* f

* f

* f
  • Loading branch information
emosbaugh authored Sep 17, 2024
1 parent 8ab69ee commit 52278b7
Show file tree
Hide file tree
Showing 26 changed files with 314 additions and 278 deletions.
1 change: 1 addition & 0 deletions .github/workflows/image-deps-updater.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
INPUT_VELERO_AWS_PLUGIN_VERSION: ${{ github.event.inputs.velero_aws_plugin_version }}
INPUT_KUBECTL_VERSION: ${{ github.event.inputs.kubectl_version }}
INPUT_SEAWEEDFS_VERSION: ${{ github.event.inputs.seaweedfs_version }}
ARCHS: "amd64,arm64"
run: |
chmod +x ./output/bin/buildtools
./output/bin/buildtools update images ${{ matrix.addon }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-addons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
INPUT_OPENEBS_CHART_VERSION: ${{ github.event.inputs.openebs_chart_version }}
INPUT_VELERO_CHART_VERSION: ${{ github.event.inputs.velero_chart_version }}
INPUT_SEAWEEDFS_CHART_VERSION: ${{ github.event.inputs.seaweedfs_chart_version }}
ARCHS: "amd64,arm64"
run: |
chmod 755 ./output/bin/buildtools
./output/bin/buildtools update addon ${{ matrix.addon }}
Expand Down
84 changes: 62 additions & 22 deletions cmd/buildtools/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,37 @@ type addonComponentOptions struct {
latestK8sVersion *semver.Version
}

func (c *addonComponent) resolveImageRepoAndTag(ctx context.Context, image string) (string, string, error) {
func (c *addonComponent) buildImage(ctx context.Context, image string, archs string) (string, error) {
if c.useUpstreamImage || c.getCustomImageName != nil {
return "", nil
}
builtImage, err := c.buildApkoImage(ctx, image, archs)
if err != nil {
return "", fmt.Errorf("build apko image: %w", err)
}
return builtImage, nil
}

func (c *addonComponent) resolveImageRepoAndTag(ctx context.Context, image string, arch string) (repo string, tag string, err error) {
if c.useUpstreamImage {
return c.resolveUpstreamImageRepoAndTag(ctx, image)
repo, tag, err = c.resolveUpstreamImageRepoAndTag(ctx, image, arch)
if err != nil {
err = fmt.Errorf("resolve upstream image repo and tag: %w", err)
}
return
}
if c.getCustomImageName != nil {
return c.resolveCustomImageRepoAndTag(ctx, c.getUpstreamVersion(image))
repo, tag, err = c.resolveCustomImageRepoAndTag(ctx, image, arch)
if err != nil {
err = fmt.Errorf("resolve custom image repo and tag: %w", err)
}
return
}
return c.resolveApkoImageRepoAndTag(ctx, c.getUpstreamVersion(image))
repo, tag, err = c.resolveApkoImageRepoAndTag(ctx, image, arch)
if err != nil {
err = fmt.Errorf("resolve apko image repo and tag: %w", err)
}
return
}

func (c *addonComponent) getUpstreamVersion(image string) string {
Expand All @@ -46,17 +69,19 @@ func (c *addonComponent) getUpstreamVersion(image string) string {
return TagFromImage(image)
}

func (c *addonComponent) resolveUpstreamImageRepoAndTag(ctx context.Context, image string) (string, string, error) {
digest, err := GetImageDigest(ctx, image)
func (c *addonComponent) resolveUpstreamImageRepoAndTag(ctx context.Context, image string, arch string) (string, string, error) {
digest, err := GetImageDigest(ctx, image, arch)
if err != nil {
return "", "", fmt.Errorf("failed to get image %s digest: %w", image, err)
}
tag := fmt.Sprintf("%s@%s", TagFromImage(image), digest)
tag := fmt.Sprintf("%s-%s@%s", TagFromImage(image), arch, digest)
repo := fmt.Sprintf("proxy.replicated.com/anonymous/%s", FamiliarImageName(RemoveTagFromImage(image)))
return repo, tag, nil
}

func (c *addonComponent) resolveCustomImageRepoAndTag(ctx context.Context, upstreamVersion string) (string, string, error) {
func (c *addonComponent) resolveCustomImageRepoAndTag(ctx context.Context, image string, arch string) (string, string, error) {
upstreamVersion := c.getUpstreamVersion(image)

k0sVersion, err := getK0sVersion()
if err != nil {
return "", "", fmt.Errorf("get k0s version: %w", err)
Expand All @@ -74,38 +99,53 @@ func (c *addonComponent) resolveCustomImageRepoAndTag(ctx context.Context, upstr
if err != nil {
return "", "", fmt.Errorf("failed to get image name for %s: %w", c.name, err)
}
digest, err := GetImageDigest(ctx, customImage)
digest, err := GetImageDigest(ctx, customImage, arch)
if err != nil {
return "", "", fmt.Errorf("failed to get image %s digest: %w", customImage, err)
}
tag := fmt.Sprintf("%s@%s", TagFromImage(customImage), digest)
tag := fmt.Sprintf("%s-%s@%s", TagFromImage(customImage), arch, digest)
repo := fmt.Sprintf("proxy.replicated.com/anonymous/%s", FamiliarImageName(RemoveTagFromImage(customImage)))
return repo, tag, nil
}

func (c *addonComponent) resolveApkoImageRepoAndTag(ctx context.Context, upstreamVersion string) (string, string, error) {
func (c *addonComponent) resolveApkoImageRepoAndTag(ctx context.Context, image string, arch string) (string, string, error) {
builtImage, err := GetImageNameFromBuildFile("build/image")
if err != nil {
return "", "", fmt.Errorf("failed to get digest from build file: %w", err)
}

digest, err := GetImageDigest(ctx, builtImage, arch)
if err != nil {
return "", "", fmt.Errorf("failed to get image %s digest: %w", builtImage, err)
}
tag := fmt.Sprintf("%s-%s@%s", TagFromImage(builtImage), arch, digest)
repo := fmt.Sprintf("proxy.replicated.com/anonymous/%s", FamiliarImageName(RemoveTagFromImage(builtImage)))
return repo, tag, nil
}

func (c *addonComponent) buildApkoImage(ctx context.Context, image string, archs string) (string, error) {
upstreamVersion := c.getUpstreamVersion(image)

packageName, packageVersion, err := c.getPackageNameAndVersion(ctx, upstreamVersion)
if err != nil {
return "", "", fmt.Errorf("failed to get package name and version constraint for %s: %w", c.name, err)
return "", fmt.Errorf("get package name and version constraint for %s: %w", c.name, err)
}

logrus.Infof("building and publishing %s", c.name)

if err := ApkoBuildAndPublish(c.name, packageName, packageVersion); err != nil {
return "", "", fmt.Errorf("failed to apko build and publish for %s: %w", c.name, err)
if err := ApkoLogin(); err != nil {
return "", fmt.Errorf("apko login: %w", err)
}

builtImage, err := GetImageNameFromBuildFile("build/image")
if err != nil {
return "", "", fmt.Errorf("failed to get digest from build file: %w", err)
if err := ApkoBuildAndPublish(c.name, packageName, packageVersion, archs); err != nil {
return "", fmt.Errorf("apko build and publish for %s: %w", c.name, err)
}

parts := strings.SplitN(builtImage, ":", 2)
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid image name: %s", builtImage)
builtImage, err := GetImageNameFromBuildFile("build/image")
if err != nil {
return "", fmt.Errorf("get image name from build file: %w", err)
}

return fmt.Sprintf("proxy.replicated.com/anonymous/%s", FamiliarImageName(parts[0])), parts[1], nil
return builtImage, nil
}

func (c *addonComponent) getPackageNameAndVersion(ctx context.Context, upstreamVersion string) (string, string, error) {
Expand Down
18 changes: 4 additions & 14 deletions cmd/buildtools/adminconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"runtime"
"strings"

"github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole"
Expand Down Expand Up @@ -70,20 +69,11 @@ var updateAdminConsoleAddonCommand = &cli.Command{
return fmt.Errorf("failed to get images from admin console chart: %w", err)
}

for _, image := range images {
component, ok := adminconsoleImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(c.Context, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := adminconsole.Metadata.Images[component.name]
newimage.Repo = repo
newimage.Tag[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(c.Context, adminconsoleImageComponents, adminconsole.Metadata.Images, images)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving addon manifest")
if err := newmeta.Save("adminconsole"); err != nil {
Expand Down
22 changes: 4 additions & 18 deletions cmd/buildtools/embeddedclusteroperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"

"github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator"
Expand Down Expand Up @@ -123,24 +122,11 @@ func updateOperatorAddonImages(ctx context.Context, chartURL string, chartVersio
// chart.
images = append(images, "docker.io/library/busybox:latest")

if err := ApkoLogin(); err != nil {
return fmt.Errorf("failed to apko login: %w", err)
}

for _, image := range images {
component, ok := operatorImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(ctx, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := embeddedclusteroperator.Metadata.Images[component.name]
newimage.Repo = repo
newimage.Tag[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(ctx, operatorImageComponents, embeddedclusteroperator.Metadata.Images, images)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving addon manifest")
if err := newmeta.Save("embeddedclusteroperator"); err != nil {
Expand Down
24 changes: 5 additions & 19 deletions cmd/buildtools/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"runtime"

"github.com/Masterminds/semver/v3"
k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
Expand Down Expand Up @@ -78,29 +77,16 @@ var updateK0sImagesCommand = &cli.Command{
logrus.Infof("updating k0s images")

newmeta := release.K0sMetadata{
Images: make(map[string]release.K0sImage),
Images: make(map[string]release.AddonImage),
}

k0sImages := config.ListK0sImages(k0sv1beta1.DefaultClusterConfig())

if err := ApkoLogin(); err != nil {
return fmt.Errorf("failed to apko login: %w", err)
}

for _, image := range k0sImages {
component, ok := k0sImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(c.Context, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := config.Metadata.Images[component.name]
newimage.Image = repo
newimage.Version[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(c.Context, k0sImageComponents, config.Metadata.Images, k0sImages)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving k0s metadata")
if err := newmeta.Save(); err != nil {
Expand Down
22 changes: 4 additions & 18 deletions cmd/buildtools/openebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"runtime"
"strings"

"github.com/replicatedhq/embedded-cluster/pkg/addons/openebs"
Expand Down Expand Up @@ -129,24 +128,11 @@ func updateOpenEBSAddonImages(ctx context.Context, chartURL string, chartVersion
// make sure we include the linux-utils image.
images = append(images, fmt.Sprintf("docker.io/openebs/linux-utils:%s", linuxUtilsVersion))

if err := ApkoLogin(); err != nil {
return fmt.Errorf("failed to apko login: %w", err)
}

for _, image := range images {
component, ok := openebsImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(ctx, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := openebs.Metadata.Images[component.name]
newimage.Repo = repo
newimage.Tag[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(ctx, openebsImageComponents, openebs.Metadata.Images, images)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving addon manifest")
if err := newmeta.Save("openebs"); err != nil {
Expand Down
18 changes: 4 additions & 14 deletions cmd/buildtools/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"runtime"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -70,20 +69,11 @@ var updateRegistryAddonCommand = &cli.Command{
return fmt.Errorf("failed to get images from chart: %w", err)
}

for _, image := range images {
component, ok := registryImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(c.Context, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := registry.Metadata.Images[component.name]
newimage.Repo = repo
newimage.Tag[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(c.Context, registryImageComponents, registry.Metadata.Images, images)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving addon manifest")
if err := newmeta.Save("registry"); err != nil {
Expand Down
22 changes: 4 additions & 18 deletions cmd/buildtools/seaweedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"runtime"
"strings"

"github.com/replicatedhq/embedded-cluster/pkg/addons/seaweedfs"
Expand Down Expand Up @@ -114,24 +113,11 @@ func updateSeaweedFSAddonImages(ctx context.Context, chartURL string, chartVersi
return fmt.Errorf("failed to get images from seaweedfs chart: %w", err)
}

if err := ApkoLogin(); err != nil {
return fmt.Errorf("failed to apko login: %w", err)
}

for _, image := range images {
component, ok := seaweedfsImageComponents[RemoveTagFromImage(image)]
if !ok {
return fmt.Errorf("no component found for image %s", image)
}
repo, tag, err := component.resolveImageRepoAndTag(ctx, image)
if err != nil {
return fmt.Errorf("failed to resolve image and tag for %s: %w", image, err)
}
newimage := seaweedfs.Metadata.Images[component.name]
newimage.Repo = repo
newimage.Tag[runtime.GOARCH] = tag
newmeta.Images[component.name] = newimage
metaImages, err := UpdateImages(ctx, seaweedfsImageComponents, seaweedfs.Metadata.Images, images)
if err != nil {
return fmt.Errorf("failed to update images: %w", err)
}
newmeta.Images = metaImages

logrus.Infof("saving addon manifest")
if err := newmeta.Save("seaweedfs"); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/buildtools/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ var updateAddonCommand = &cli.Command{
},
},
Subcommands: []*cli.Command{
updateAdminConsoleAddonCommand,
updateOpenEBSAddonCommand,
updateSeaweedFSAddonCommand,
updateOperatorAddonCommand,
updateRegistryAddonCommand,
updateVeleroAddonCommand,
updateOperatorAddonCommand,
updateAdminConsoleAddonCommand,
updateSeaweedFSAddonCommand,
},
}

Expand All @@ -38,8 +38,8 @@ var updateImagesCommand = &cli.Command{
Subcommands: []*cli.Command{
updateK0sImagesCommand,
updateOpenEBSImagesCommand,
updateVeleroImagesCommand,
updateOperatorImagesCommand,
updateSeaweedFSImagesCommand,
updateVeleroImagesCommand,
},
}
Loading

0 comments on commit 52278b7

Please sign in to comment.