Skip to content

Commit

Permalink
test: Add e2e for arm64 import
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jan 5, 2023
1 parent 696cf03 commit 9413ca7
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 111 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
- name: Install asdf
uses: asdf-vm/actions/setup@v1

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64

- name: Run e2e tests
run: make e2e-test

Expand Down
6 changes: 5 additions & 1 deletion make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ E2E_FLAKE_ATTEMPTS ?= 1
e2e-test: ## Runs e2e tests
e2e-test: install-tool.golang install-tool.ginkgo skopeo.build
$(info $(M) running e2e tests$(if $(E2E_LABEL), labelled "$(E2E_LABEL)")$(if $(E2E_FOCUS), matching "$(E2E_FOCUS)"))
$(MAKE) build-snapshot
$(MAKE) BUILD_ALL=true build-snapshot
ifdef CI
$(MAKE) SKIP_UPX=false GOOS=linux GOARCH=amd64 UPX_TARGET=dist/mindthegap_linux_arm64/mindthegap upx
$(MAKE) SKIP_UPX=false GOOS=linux GOARCH=arm64 UPX_TARGET=dist/mindthegap_linux_amd64_v1/mindthegap upx
endif
ginkgo run \
--r \
--race \
Expand Down
2 changes: 1 addition & 1 deletion make/goreleaser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build-snapshot: dockerauth install-tool.goreleaser ; $(info $(M) building snapsh
--snapshot \
--rm-dist \
--parallelism=$(GORELEASER_PARALLELISM) \
--single-target \
$(if $(BUILD_ALL),,--single-target) \
--skip-post-hooks

.PHONY: release
Expand Down
32 changes: 22 additions & 10 deletions test/e2e/imagebundle/helpers/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ func NewDockerClient() (*Docker, error) {
}

func (d *Docker) PullImage(ctx context.Context, image string) error {
_, _, err := d.cl.ImageInspectWithRaw(ctx, image)
if err == nil {
return nil
}
if !client.IsErrNotFound(err) {
return fmt.Errorf("failed to inspect image %q: %w", image, err)
}
return d.PullImageWithPlatform(ctx, image, nil)
}

r, err := d.cl.ImagePull(ctx, image, types.ImagePullOptions{})
func (d *Docker) PullImageWithPlatform(
ctx context.Context,
image string,
platform *specs.Platform,
) error {
opts := types.ImagePullOptions{}
if platform != nil && platform.OS != "" {
opts.Platform = fmt.Sprintf("%s/%s", platform.OS, platform.Architecture)
}
r, err := d.cl.ImagePull(ctx, image, opts)
defer r.Close()
if err != nil {
return fmt.Errorf("failed to pull image %q: %w", image, err)
Expand All @@ -62,7 +66,15 @@ func (d *Docker) PullImage(ctx context.Context, image string) error {
}

func (d *Docker) StartContainer(ctx context.Context, cfg container.Config) (*Container, error) {
if err := d.PullImage(ctx, cfg.Image); err != nil {
return d.StartContainerWithPlatform(ctx, cfg, &specs.Platform{})
}

func (d *Docker) StartContainerWithPlatform(
ctx context.Context,
cfg container.Config,
platform *specs.Platform,
) (*Container, error) {
if err := d.PullImageWithPlatform(ctx, cfg.Image, platform); err != nil {
return nil, err
}

Expand All @@ -71,7 +83,7 @@ func (d *Docker) StartContainer(ctx context.Context, cfg container.Config) (*Con
&cfg,
&container.HostConfig{},
&network.NetworkingConfig{},
&specs.Platform{},
platform,
"",
)
if err != nil {
Expand Down
68 changes: 68 additions & 0 deletions test/e2e/imagebundle/helpers/goreleaser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2021 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package helpers

import (
"encoding/json"
"io"
"os"
"strings"
)

// Artifact is a goreleaser type defines a single artifact.
// Copied from https://github.com/goreleaser/goreleaser/blob/v1.13.1/internal/artifact/artifact.go#L159-L170
type Artifact struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Goos string `json:"goos,omitempty"`
Goarch string `json:"goarch,omitempty"`
Goarm string `json:"goarm,omitempty"`
Gomips string `json:"gomips,omitempty"`
Goamd64 string `json:"goamd64,omitempty"`
Type string `json:"type,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
}

type Artifacts []Artifact

func (as Artifacts) SelectBinary(name, goos, goarch string) (Artifact, bool) {
for i := range as {
a := as[i]
if a.Type == "Binary" && a.Name == name && a.Goos == goos && a.Goarch == goarch {
return a, true
}
}

return Artifact{}, false
}

func (as Artifacts) SelectDockerImage(namePrefix, goos, goarch string) (Artifact, bool) {
for i := range as {
a := as[i]
if a.Type == "Docker Image" && strings.HasPrefix(a.Name, namePrefix) && a.Goos == goos &&
a.Goarch == goarch {
return a, true
}
}

return Artifact{}, false
}

func ParseArtifactsFile(file string) (Artifacts, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()

return ParseArtifacts(f)
}

func ParseArtifacts(r io.Reader) (Artifacts, error) {
var as Artifacts
if err := json.NewDecoder(r).Decode(&as); err != nil {
return nil, err
}
return as, nil
}
9 changes: 7 additions & 2 deletions test/e2e/imagebundle/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ import (
)

func CreateBundle(t ginkgo.GinkgoTInterface, bundleFile, cfgFile string, platforms ...string) {
platformFlags := make([]string, 0, len(platforms))
for _, p := range platforms {
platformFlags = append(platformFlags, "--platform", p)
}

createBundleCmd := NewCommand(t, createimagebundle.NewCommand)
createBundleCmd.SetArgs([]string{
createBundleCmd.SetArgs(append([]string{
"--output-file", bundleFile,
"--images-file", cfgFile,
})
}, platformFlags...))
gomega.ExpectWithOffset(1, createBundleCmd.Execute()).To(gomega.Succeed())
}

Expand Down
14 changes: 14 additions & 0 deletions test/e2e/imagebundle/imagebundle_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@
package imagebundle_test

import (
"path/filepath"
"testing"

"github.com/mesosphere/mindthegap/test/e2e/imagebundle/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var artifacts helpers.Artifacts

func TestImagebundle(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Image Bundle Suite", Label("image", "imagebundle"))
}

var _ = BeforeSuite(func() {
var err error
artifacts, err = helpers.ParseArtifactsFile(filepath.Join("..",
"..",
"..",
"dist", "artifacts.json"),
)
Expect(err).NotTo(HaveOccurred())
})
Loading

0 comments on commit 9413ca7

Please sign in to comment.