Skip to content

Commit 260ee6e

Browse files
committed
Add support for external embed test image list
Signed-off-by: apostasie <[email protected]>
1 parent 2a2834d commit 260ee6e

14 files changed

+127
-87
lines changed

pkg/testutil/images.env

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Future: images to update once we have proofing in place.
2+
#BUSYBOX=busybox:1.37.0@sha256:37f7b378a29ceb4c551b1b5582e27747b855bbfaa73fa11914fe0df028dc581f
3+
#DEBIAN=debian:bookworm-slim@sha256:b1211f6d19afd012477bd34fdcabb6b663d680e0f4b0537da6e6b0fd057a3ec3
4+
#GITLAB=gitlab/gitlab-ee:17.11.0-ee.0@sha256:e0d9d5e0d0068f4b4bac3e15eb48313b5c3bb508425645f421bf2773a964c4ae
5+
#HARBOR=bitnami/harbor-portal:v2.13.0@sha256:636f39610b359369aeeddd7859cb56274d9a1bc3e467e21d74ea89e1516c1a0c
6+
#MARIADB=mariadb:11.7.2@sha256:81e893032978c4bf8ad43710b7a979774ed90787fa32d199162148ce28fe3b76
7+
#NGINX=nginx:alpine3.21@sha256:65645c7bb6a0661892a8b03b89d0743208a18dd2f3f17a54ef4b76fb8e2f2a10
8+
#WORDPRESS=wordpress:6.8.0-php8.4-fpm-alpine@sha256:309b64fa4266d8a3fe6f0973ae3172fec1023c9b18242ccf1dffbff5dc8b81a8
9+
10+
ALPINE=ghcr.io/stargz-containers/alpine:3.13-org
11+
BUSYBOX=ghcr.io/containerd/busybox:1.36
12+
DOCKER_AUTH=ghcr.io/stargz-containers/cesanta/docker_auth:1.7-org
13+
FLUENTD=fluentd:v1.18.0-debian-1.0
14+
GOLANG=golang:1.23.8-bookworm
15+
KUBO=ghcr.io/stargz-containers/ipfs/kubo:v0.16.0-org
16+
MARIADB=ghcr.io/stargz-containers/mariadb:10.5-org
17+
NANOSERVER=mcr.microsoft.com/windows/nanoserver:ltsc2022
18+
NGINX=ghcr.io/stargz-containers/nginx:1.19-alpine-org
19+
# FIXME: update to v3 soon. Right now, this is breaking tests.
20+
# REGISTRY=ghcr.io/distribution/distribution:3.0.0@sha256:4ba3adf47f5c866e9a29288c758c5328ef03396cb8f5f6454463655fa8bc83e2
21+
REGISTRY=ghcr.io/stargz-containers/registry:2-org
22+
STARGZ=ghcr.io/containerd/stargz-snapshotter:0.15.1-kind
23+
WORDPRESS=ghcr.io/stargz-containers/wordpress:5.7-org
24+
FEDORAESGZ=ghcr.io/stargz-containers/fedora:30-esgz
25+
# SOCI
26+
FFMPEGSOCI=public.ecr.aws/soci-workshop-examples/ffmpeg:latest
27+
# Large enough for testing soci index creation
28+
UBUNTU=public.ecr.aws/docker/library/ubuntu:23.10

pkg/testutil/images_linux.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package testutil
18+
19+
import (
20+
_ "embed"
21+
"fmt"
22+
"strings"
23+
24+
"github.com/containerd/nerdctl/v2/pkg/referenceutil"
25+
)
26+
27+
//go:embed images.env
28+
var imagesList string
29+
30+
// getImage retrieves (from the env file) the fully qualified reference of an image, from its short name.
31+
// No particular error handling effort is done here.
32+
// If the env file is broken, or if the requested image does not exist, this is fatal.
33+
func getImage(name string) string {
34+
key := strings.ToUpper(name)
35+
36+
for _, k := range strings.Split(imagesList, "\n") {
37+
k = strings.TrimSpace(k)
38+
if strings.HasPrefix(k, "#") || k == "" {
39+
continue
40+
}
41+
42+
spl := strings.Split(k, "=")
43+
if len(spl) != 2 {
44+
continue
45+
}
46+
47+
if key == spl[0] {
48+
item, err := referenceutil.Parse(spl[1])
49+
50+
if err != nil {
51+
panic(fmt.Errorf("malformed image found in env file: %w (%s)", err, spl[1]))
52+
}
53+
54+
return item.Domain + "/" + item.Path + ":" + item.Tag
55+
}
56+
}
57+
58+
panic(fmt.Sprintf("no such test image is defined: %s", name))
59+
60+
//nolint:govet
61+
return ""
62+
}

pkg/testutil/nerdtest/platform/platform_darwin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func DataHome() (string, error) {
2323
var (
2424
// The following are here solely for darwin to compile / lint. They are not used, as the corresponding tests are running only on linux.
2525
RegistryImageStable = "registry:2"
26-
RegistryImageNext = "ghcr.io/distribution/distribution:"
2726
KuboImage = "ipfs/kubo:v0.16.0"
2827
DockerAuthImage = "cesanta/docker_auth:1.7"
2928
)

pkg/testutil/nerdtest/platform/platform_freebsd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func DataHome() (string, error) {
2323
var (
2424
// The following are here solely for freebsd to compile / lint. They are not used, as the corresponding tests are running only on linux.
2525
RegistryImageStable = "registry:2"
26-
RegistryImageNext = "ghcr.io/distribution/distribution:"
2726
KuboImage = "ipfs/kubo:v0.16.0"
2827
DockerAuthImage = "cesanta/docker_auth:1.7"
2928
)

pkg/testutil/nerdtest/platform/platform_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func DataHome() (string, error) {
2727

2828
var (
2929
RegistryImageStable = testutil.RegistryImageStable
30-
RegistryImageNext = testutil.RegistryImageNext
3130
KuboImage = testutil.KuboImage
3231
DockerAuthImage = testutil.DockerAuthImage
3332
)

pkg/testutil/nerdtest/platform/platform_windows.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@
1616

1717
package platform
1818

19-
import (
20-
"fmt"
21-
)
22-
2319
func DataHome() (string, error) {
2420
panic("not supported")
2521
}
2622

27-
// The following are here solely for windows to compile. They are not used, as the corresponding tests are running only on linux.
28-
func mirrorOf(s string) string {
29-
return fmt.Sprintf("ghcr.io/stargz-containers/%s-org", s)
30-
}
31-
3223
var (
33-
RegistryImageStable = mirrorOf("registry:2")
34-
RegistryImageNext = "ghcr.io/distribution/distribution:"
35-
KuboImage = mirrorOf("ipfs/kubo:v0.16.0")
36-
DockerAuthImage = mirrorOf("cesanta/docker_auth:1.7")
24+
RegistryImageStable = "there-is-no-such-test-on-windows"
25+
KuboImage = "there-is-no-such-test-on-windows"
26+
DockerAuthImage = "there-is-no-such-test-on-windows"
3727
)

pkg/testutil/nerdtest/registry/docker.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package registry
1919
import (
2020
"fmt"
2121
"net"
22-
"os"
2322
"strconv"
2423

2524
"gotest.tools/v3/assert"
@@ -71,15 +70,7 @@ func NewDockerRegistry(data test.Data, helpers test.Helpers, currentCA *testca.C
7170
// Attach authentication params returns by authenticator
7271
args = append(args, auth.Params(data)...)
7372

74-
// Get the right registry version
7573
registryImage := platform.RegistryImageStable
76-
up := os.Getenv("DISTRIBUTION_VERSION")
77-
if up != "" {
78-
if up[0:1] != "v" {
79-
up = "v" + up
80-
}
81-
registryImage = platform.RegistryImageNext + up
82-
}
8374
args = append(args, registryImage)
8475

8576
cleanup := func(data test.Data, helpers test.Helpers) {

pkg/testutil/nerdtest/requirements.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"os"
2423
"os/exec"
2524
"strings"
2625

@@ -275,13 +274,6 @@ var Registry = require.All(
275274
// - when we start a large number of registries in subtests, no need to round-trip to ghcr everytime
276275
// This of course assumes that the subtests are NOT going to prune / rmi images
277276
registryImage := platform.RegistryImageStable
278-
up := os.Getenv("DISTRIBUTION_VERSION")
279-
if up != "" {
280-
if up[0:1] != "v" {
281-
up = "v" + up
282-
}
283-
registryImage = platform.RegistryImageNext + up
284-
}
285277
helpers.Ensure("pull", "--quiet", registryImage)
286278
helpers.Ensure("pull", "--quiet", platform.DockerAuthImage)
287279
helpers.Ensure("pull", "--quiet", platform.KuboImage)

pkg/testutil/testregistry/testregistry_linux.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ type TokenAuthServer struct {
5656

5757
func EnsureImages(base *testutil.Base) {
5858
registryImage := platform.RegistryImageStable
59-
up := os.Getenv("DISTRIBUTION_VERSION")
60-
if up != "" {
61-
if up[0:1] != "v" {
62-
up = "v" + up
63-
}
64-
registryImage = platform.RegistryImageNext + up
65-
}
6659
base.Cmd("pull", "--quiet", registryImage).AssertOK()
6760
base.Cmd("pull", "--quiet", platform.DockerAuthImage).AssertOK()
6861
base.Cmd("pull", "--quiet", platform.KuboImage).AssertOK()
@@ -284,14 +277,6 @@ func NewRegistry(base *testutil.Base, ca *testca.CA, port int, auth Auth, boundC
284277

285278
args = append(args, auth.Params(base)...)
286279
registryImage := testutil.RegistryImageStable
287-
288-
up := os.Getenv("DISTRIBUTION_VERSION")
289-
if up != "" {
290-
if up[0:1] != "v" {
291-
up = "v" + up
292-
}
293-
registryImage = testutil.RegistryImageNext + up
294-
}
295280
args = append(args, registryImage)
296281

297282
cleanup := func(err error) {

pkg/testutil/testutil.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,3 @@ func RegisterBuildCacheCleanup(t *testing.T) {
763763
NewBase(t).Cmd("builder", "prune", "--all", "--force").Run()
764764
})
765765
}
766-
767-
func mirrorOf(s string) string {
768-
// plain mirror, NOT stargz-converted images
769-
return fmt.Sprintf("ghcr.io/stargz-containers/%s-org", s)
770-
}

pkg/testutil/testutil_darwin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const (
2828
)
2929

3030
var (
31-
BusyboxImage = "ghcr.io/containerd/busybox:1.36"
32-
AlpineImage = mirrorOf("alpine:3.13")
33-
NginxAlpineImage = mirrorOf("nginx:1.19-alpine")
34-
GolangImage = mirrorOf("golang:1.18")
31+
BusyboxImage = "there-is-no-test-on-darwin"
32+
AlpineImage = "there-is-no-test-on-darwin"
33+
NginxAlpineImage = "there-is-no-test-on-darwin"
34+
GolangImage = "there-is-no-test-on-darwin"
3535
)

pkg/testutil/testutil_freebsd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const (
2828
)
2929

3030
var (
31-
BusyboxImage = "ghcr.io/containerd/busybox:1.36"
32-
AlpineImage = mirrorOf("alpine:3.13")
33-
NginxAlpineImage = mirrorOf("nginx:1.19-alpine")
34-
GolangImage = mirrorOf("golang:1.18")
31+
BusyboxImage = "there-is-no-such-test-on-freebsd"
32+
AlpineImage = "there-is-no-such-test-on-freebsd"
33+
NginxAlpineImage = "there-is-no-such-test-on-freebsd"
34+
GolangImage = "there-is-no-such-test-on-freebsd"
3535
)

pkg/testutil/testutil_linux.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,38 @@
1717
package testutil
1818

1919
var (
20-
BusyboxImage = "ghcr.io/containerd/busybox:1.36"
21-
AlpineImage = mirrorOf("alpine:3.13")
22-
NginxAlpineImage = mirrorOf("nginx:1.19-alpine")
23-
NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
24-
RegistryImageStable = mirrorOf("registry:2")
25-
RegistryImageNext = "ghcr.io/distribution/distribution:"
26-
WordpressImage = mirrorOf("wordpress:5.7")
27-
WordpressIndexHTMLSnippet = "<title>WordPress &rsaquo; Installation</title>"
28-
MariaDBImage = mirrorOf("mariadb:10.5")
29-
DockerAuthImage = mirrorOf("cesanta/docker_auth:1.7")
30-
FluentdImage = "fluent/fluentd:v1.17.0-debian-1.0"
31-
KuboImage = mirrorOf("ipfs/kubo:v0.16.0")
32-
SystemdImage = "ghcr.io/containerd/stargz-snapshotter:0.15.1-kind"
33-
GolangImage = mirrorOf("golang:1.18")
34-
35-
// Source: https://gist.github.com/cpuguy83/fcf3041e5d8fb1bb5c340915aabeebe0
36-
NonDistBlobImage = "ghcr.io/cpuguy83/non-dist-blob:latest"
37-
// Foreign layer digest
38-
NonDistBlobDigest = "sha256:be691b1535726014cdf3b715ff39361b19e121ca34498a9ceea61ad776b9c215"
20+
AlpineImage = getImage("alpine")
21+
BusyboxImage = getImage("busybox")
22+
DockerAuthImage = getImage("docker_auth")
23+
FluentdImage = getImage("fluentd")
24+
GolangImage = getImage("golang")
25+
KuboImage = getImage("kubo")
26+
MariaDBImage = getImage("mariadb")
27+
NginxAlpineImage = getImage("nginx")
28+
RegistryImageStable = getImage("registry")
29+
SystemdImage = getImage("stargz")
30+
WordpressImage = getImage("wordpress")
3931

4032
CommonImage = AlpineImage
4133

34+
FedoraESGZImage = getImage("fedoraesgz") // eStargz
35+
FfmpegSociImage = getImage("ffmpegsoci") // SOCI
36+
UbuntuImage = getImage("ubuntu") // Large enough for testing soci index creation
37+
)
38+
39+
const (
4240
// This error string is expected when attempting to connect to a TCP socket
4341
// for a service which actively refuses the connection.
4442
// (e.g. attempting to connect using http to an https endpoint).
4543
// It should be "connection refused" as per the TCP RFC.
4644
// https://www.rfc-editor.org/rfc/rfc793
4745
ExpectedConnectionRefusedError = "connection refused"
48-
)
4946

50-
const (
51-
FedoraESGZImage = "ghcr.io/stargz-containers/fedora:30-esgz" // eStargz
52-
FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest" // SOCI
53-
UbuntuImage = "public.ecr.aws/docker/library/ubuntu:23.10" // Large enough for testing soci index creation
47+
NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
48+
WordpressIndexHTMLSnippet = "<title>WordPress &rsaquo; Installation</title>"
49+
50+
// Source: https://gist.github.com/cpuguy83/fcf3041e5d8fb1bb5c340915aabeebe0
51+
NonDistBlobImage = "ghcr.io/cpuguy83/non-dist-blob:latest@sha256:8859ffb0bb604463fe19f1e606ceda9f4f8f42e095bf78c42458cf6da7b5c7e7"
52+
// Foreign layer digest
53+
NonDistBlobDigest = "sha256:be691b1535726014cdf3b715ff39361b19e121ca34498a9ceea61ad776b9c215"
5454
)

pkg/testutil/testutil_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const (
5353
)
5454

5555
var (
56-
GolangImage = mirrorOf("fixme-test-using-this-image-is-disabled-on-windows")
57-
AlpineImage = mirrorOf("fixme-test-using-this-image-is-disabled-on-windows")
56+
GolangImage = "fixme-test-using-this-image-is-disabled-on-windows"
57+
AlpineImage = "fixme-test-using-this-image-is-disabled-on-windows"
5858

5959
hypervContainer bool
6060
hypervSupported bool

0 commit comments

Comments
 (0)