diff --git a/go.mod b/go.mod index 731194a33..001aff7e1 100644 --- a/go.mod +++ b/go.mod @@ -25,8 +25,9 @@ require ( github.com/carolynvs/datetime-printer v0.2.0 github.com/carolynvs/magex v0.8.0 github.com/cbroglie/mustache v1.0.1 - github.com/cnabio/cnab-go v0.23.5 + github.com/cnabio/cnab-go v0.24.0 github.com/cnabio/cnab-to-oci v0.3.6 + github.com/cnabio/image-relocation v0.9.0 github.com/containerd/containerd v1.6.6 github.com/davecgh/go-spew v1.1.1 github.com/docker/buildx v0.8.1 @@ -53,7 +54,6 @@ require ( github.com/opencontainers/go-digest v1.0.0 github.com/osteele/liquid v1.3.0 github.com/pelletier/go-toml v1.9.4 - github.com/pivotal/image-relocation v0.0.0-20191111101224-e94aff6df06c github.com/spf13/afero v1.5.1 github.com/spf13/cobra v1.2.1 github.com/spf13/pflag v1.0.5 @@ -214,7 +214,7 @@ require ( golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect - golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect + golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect diff --git a/go.sum b/go.sum index 9b09ddf73..93ad862ae 100644 --- a/go.sum +++ b/go.sum @@ -315,10 +315,12 @@ github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cfssl v0.0.0-20181213083726-b94e044bb51e/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA= github.com/cloudflare/cfssl v1.4.1 h1:vScfU2DrIUI9VPHBVeeAQ0q5A+9yshO1Gz+3QoUQiKw= -github.com/cnabio/cnab-go v0.23.5 h1:wV2/Jw9LjUfKy3i9ycFqDMaaGnmTL4wiCocAk4mACSQ= -github.com/cnabio/cnab-go v0.23.5/go.mod h1:9EmgHR51LFqQStzaC+xHPJlkD4OPsF6Ev5Y8e/YHEns= +github.com/cnabio/cnab-go v0.24.0 h1:l5dSAEUsGoccIGRgDmH4HncHfw1a2zaiEft/RG6LS8Y= +github.com/cnabio/cnab-go v0.24.0/go.mod h1:Zm0HTH8xxzinB64SXm7KFSna7DEN0ZjZwrRwZpfgChU= github.com/cnabio/cnab-to-oci v0.3.6 h1:QVvy4WjQpGyf20xbbeYtRObX+pB8cWNuvvT/e4w1DoQ= github.com/cnabio/cnab-to-oci v0.3.6/go.mod h1:AvVNl0Hh3VBk1zqeLdyE5S3bTQ5EsZPPF4mUUJYyy1Y= +github.com/cnabio/image-relocation v0.9.0 h1:sBSchA1sRBesje0uJrPSz1lLtsIjRMxiuIJ20aYpnpI= +github.com/cnabio/image-relocation v0.9.0/go.mod h1:E1bwI4v9AFrspAWqje0clEo31bHHH/YPxk1a4L5O3ZE= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -359,7 +361,6 @@ github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4q github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= -github.com/containerd/containerd v1.2.7/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.2.10/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -851,7 +852,6 @@ github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.2.2/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= @@ -1309,8 +1309,6 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.0.3 h1:vNQKSVZNYUEAvRY9FaUXAF1XPbSOHJtDTiP41kzDz2E= github.com/pierrec/lz4/v4 v4.0.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= -github.com/pivotal/image-relocation v0.0.0-20191111101224-e94aff6df06c h1:aWFqZbzCsh4JXjW59u+taslG9zzxF5PEyINyMv33rlg= -github.com/pivotal/image-relocation v0.0.0-20191111101224-e94aff6df06c/go.mod h1:/JNbQwGylYm3AQh8q+MBF8e/h0W1Jy20JGTvozuXYTE= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -1997,8 +1995,8 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -2304,7 +2302,6 @@ gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8 gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/gorethink/gorethink.v3 v3.0.5 h1:e2Uc/Xe+hpcVQFsj6MuHlYog3r0JYpnTzwDj/y2O4MU= gopkg.in/gorethink/gorethink.v3 v3.0.5/go.mod h1:+3yIIHJUGMBK+wyPH+iN5TP+88ikFDfZdqTlK3Y9q8I= -gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -2363,7 +2360,6 @@ k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI= k8s.io/api v0.24.1 h1:BjCMRDcyEYz03joa3K1+rbshwh1Ay6oB53+iUx2H8UY= k8s.io/api v0.24.1/go.mod h1:JhoOvNiLXKTPQ60zh2g0ewpA+bnEYf5q44Flhquh4vQ= k8s.io/apimachinery v0.0.0-20180904193909-def12e63c512/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= -k8s.io/apimachinery v0.0.0-20190806215851-162a2dabc72f/go.mod h1:+ntn62igV2hyNj7/0brOvXSMONE2KxcePkSxK7/9FFQ= k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g= k8s.io/apimachinery v0.19.0/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA= k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= @@ -2412,7 +2408,6 @@ k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAE k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= -k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= @@ -2422,7 +2417,6 @@ k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc= k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc= -k8s.io/kube-openapi v0.0.0-20190709113604-33be087ad058/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o= k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= diff --git a/magefile.go b/magefile.go index c2c7b883b..89235d5e0 100644 --- a/magefile.go +++ b/magefile.go @@ -16,26 +16,26 @@ import ( "strconv" "strings" - "get.porter.sh/porter/pkg" - - "get.porter.sh/porter/mage/setup" - "get.porter.sh/magefiles/ci" "get.porter.sh/magefiles/docker" "get.porter.sh/magefiles/releases" - - // mage:import - "get.porter.sh/magefiles/tests" "get.porter.sh/magefiles/tools" - - // mage:import - _ "get.porter.sh/porter/mage/docs" + "get.porter.sh/porter/mage/setup" + "get.porter.sh/porter/pkg" + "get.porter.sh/porter/tests/tester" + mageci "github.com/carolynvs/magex/ci" "github.com/carolynvs/magex/mgx" "github.com/carolynvs/magex/shx" "github.com/carolynvs/magex/xplat" "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" "golang.org/x/sync/errgroup" + + // mage:import + "get.porter.sh/magefiles/tests" + + // mage:import + _ "get.porter.sh/porter/mage/docs" ) // Default target to run when none is specified @@ -221,9 +221,7 @@ func TestUnit() { // Run smoke tests to quickly check if Porter is broken func TestSmoke() error { - mg.Deps(copySchema) - - mg.Deps(docker.RestartDockerRegistry) + mg.Deps(copySchema, TryRegisterLocalHostAlias, docker.RestartDockerRegistry) // Only do verbose output of tests when called with `mage -v TestSmoke` v := "" @@ -434,7 +432,7 @@ func chmodRecursive(name string, mode os.FileMode) error { // Run integration tests (slow). func TestIntegration() { - mg.Deps(tests.EnsureTestCluster, copySchema, BuildTestPlugin) + mg.Deps(tests.EnsureTestCluster, copySchema, BuildTestPlugin, TryRegisterLocalHostAlias) var run string runTest := os.Getenv("PORTER_RUN_TEST") @@ -450,6 +448,23 @@ func TestIntegration() { must.Command("go", "test", verbose, "-timeout=30m", run, "-tags=integration", "./...").CollapseArgs().RunV() } +// TryRegisterLocalHostAlias edits /etc/hosts to use porter-test-registry hostname alias +// This is not safe to call more than once and is intended for use on the CI server only +func TryRegisterLocalHostAlias() { + if _, isCI := mageci.DetectBuildProvider(); !isCI { + return + } + + err := shx.RunV("sudo", "bash", "-c", "echo 127.0.0.1 porter-test-registry >> /etc/hosts") + if err != nil { + fmt.Println("skipping registering the porter-test-registry hostname alias: could not write to /etc/hosts") + return + } + + fmt.Println("Added host alias porter-test-registry to /etc/hosts") + os.Setenv(tester.TestRegistryAlias, "porter-test-registry") +} + func BuildTestPlugin() { must.RunV("go", "build", "-o", "bin/testplugin", "./cmd/testplugin") } diff --git a/pkg/cnab/config-adapter/testdata/mybuns.bundle.json b/pkg/cnab/config-adapter/testdata/mybuns.bundle.json index 289c305fb..ac75ad6fc 100644 --- a/pkg/cnab/config-adapter/testdata/mybuns.bundle.json +++ b/pkg/cnab/config-adapter/testdata/mybuns.bundle.json @@ -9,6 +9,13 @@ "image": "localhost:5000/mybuns:332dd75c541511a27fc332bdcd049d5b" } ], + "images": { + "whalesayd": { + "imageType": "docker", + "image": "carolynvs/whalesayd:latest", + "description": "Whalesay as a service" + } + }, "actions": { "boom": { "modifies": true, @@ -181,7 +188,7 @@ "version": "v1.2.3" } }, - "manifest": "IyBUaGlzIGlzIGEgdGVzdCBidW5kbGUgdGhhdCBtYWtlcyBubyBsb2dpY2FsIHNlbnNlLCBidXQgaXQgZG9lcyBleGVyY2lzZSBsb3RzIG9mIGRpZmZlcmVudCBidW5kbGUgZmVhdHVyZXMKCnNjaGVtYVZlcnNpb246IDEuMC4wCm5hbWU6IG15YnVucwp2ZXJzaW9uOiAwLjEuMgpkZXNjcmlwdGlvbjogIkEgdmVyeSB0aG9yb3VnaCB0ZXN0IGJ1bmRsZSIKcmVnaXN0cnk6IGxvY2FsaG9zdDo1MDAwCmRvY2tlcmZpbGU6IERvY2tlcmZpbGUudG1wbAoKcmVxdWlyZWQ6CiAgLSBkb2NrZXIKCmNyZWRlbnRpYWxzOgogIC0gbmFtZTogdXNlcm5hbW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gbmFtZTogZGIKICAgICAgYnVuZGxlOgogICAgICAgIHJlZmVyZW5jZTogImxvY2FsaG9zdDo1MDAwL215ZGI6djAuMS4wIgogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIGRhdGFiYXNlOiBiaWdkYgoKbWl4aW5zOgogIC0gZXhlYwoKY3VzdG9tQWN0aW9uczoKICBkcnktcnVuOgogICAgZGVzY3JpcHRpb246ICJNYWtlIHN1cmUgaXQgd2lsbCB3b3JrIGJlZm9yZSB5b3UgcnVuIGl0IgogICAgc3RhdGVsZXNzOiB0cnVlCiAgICBtb2RpZmllczogZmFsc2UKICBzdGF0dXM6CiAgICBkZXNjcmlwdGlvbjogIlByaW50IHRoZSBpbnN0YWxsYXRpb24gc3RhdHVzIgogICAgc3RhdGVsZXNzOiBmYWxzZQogICAgbW9kaWZpZXM6IGZhbHNlCgppbnN0YWxsOgogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJDaGVjayB0aGUgZG9ja2VyIHNvY2tldCIKICAgICAgY29tbWFuZDogc3RhdAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSAvdmFyL3J1bi9kb2NrZXIuc29jawogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJMZXQncyBtYWtlIHNvbWUgbWFnaWMiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBtYWtlTWFnaWMKICAgICAgICAtICIkeyBidW5kbGUuY3JlZGVudGlhbHMudXNlcm5hbWUgfSBpcyBhIHVuaWNvcm4gd2l0aCAkeyBidW5kbGUucGFyYW1ldGVycy5wYXNzd29yZCB9IHNlY3JldC4iCiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogImluc3RhbGwiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBpbnN0YWxsCiAgICAgIG91dHB1dHM6CiAgICAgICAgLSBuYW1lOiB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VudHM6CiAgICAgICAgLSBlbnN1cmVNYWdpYwogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJ1cGdyYWRlIgogICAgICBjb21tYW5kOiAuL2hlbHBlcnMuc2gKICAgICAgYXJndW1lbnRzOgogICAgICAgIC0gdXBncmFkZQogICAgICBvdXRwdXRzOgogICAgICAgIC0gbmFtZTogbXlsb2dzCiAgICAgICAgICByZWdleDogIiguKikiCiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogInJvbGwgdGhlIGRpY2Ugd2l0aCB5b3VyIGNoYW9zIG1vbmtleSIKICAgICAgY29tbWFuZDogLi9oZWxwZXJzLnNoCiAgICAgIGFyZ3VtZW50czoKICAgICAgICAtIGNoYW9zX21vbmtleQogICAgICAgIC0gJHsgYnVuZGxlLnBhcmFtZXRlcnMuY2hhb3NfbW9ua2V5IH0KICAgICAgb3V0cHV0czoKICAgICAgICAtIG5hbWU6IHJlc3VsdAogICAgICAgICAgcmVnZXg6ICIoLiopIgoKdW5pbnN0YWxsOgogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJFbnN1cmUgTWFnaWMiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBlbnN1cmVNYWdpYwogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJ1bmluc3RhbGwiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSB1bmluc3RhbGwKICAtIGV4ZWM6CiAgICAgIGRlc2NyaXB0aW9uOiAicm9sbCB0aGUgZGljZSB3aXRoIHlvdXIgY2hhb3MgbW9ua2V5IgogICAgICBjb21tYW5kOiAuL2hlbHBlcnMuc2gKICAgICAgYXJndW1lbnRzOgogICAgICAgIC0gY2hhb3NfbW9ua2V5CiAgICAgICAgLSAkeyBidW5kbGUucGFyYW1ldGVycy5jaGFvc19tb25rZXkgfQo=", + "manif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CgppbnN0YWxsOgogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJDaGVjayB0aGUgZG9ja2VyIHNvY2tldCIKICAgICAgY29tbWFuZDogc3RhdAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSAvdmFyL3J1bi9kb2NrZXIuc29jawogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJMZXQncyBtYWtlIHNvbWUgbWFnaWMiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBtYWtlTWFnaWMKICAgICAgICAtICIkeyBidW5kbGUuY3JlZGVudGlhbHMudXNlcm5hbWUgfSBpcyBhIHVuaWNvcm4gd2l0aCAkeyBidW5kbGUucGFyYW1ldGVycy5wYXNzd29yZCB9IHNlY3JldC4iCiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogImluc3RhbGwiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBpbnN0YWxsCiAgICAgIG91dHB1dHM6CiAgICAgICAgLSBuYW1lOiBteWxvZ3MKICAgICAgICAgIHJlZ2V4OiAiKC4qKSIKICAtIGV4ZWM6CiAgICAgIGRlc2NyaXB0aW9uOiAicm9sbCB0aGUgZGljZSB3aXRoIHlvdXIgY2hhb3MgbW9ua2V5IgogICAgICBjb21tYW5kOiAuL2hlbHBlcnMuc2gKICAgICAgYXJndW1lbnRzOgogICAgICAgIC0gY2hhb3NfbW9ua2V5CiAgICAgICAgLSAkeyBidW5kbGUucGFyYW1ldGVycy5jaGFvc19tb25rZXkgfQogICAgICBvdXRwdXRzOgogICAgICAgIC0gbmFtZTogcmVzdWx0CiAgICAgICAgICByZWdleDogIiguKikiCgpkcnktcnVuOgogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJDaGVjayBzb21lIHRoaW5ncyIKICAgICAgY29tbWFuZDogZWNobwogICAgICBhcmd1bWVudHM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rZXkgfQogICAgICBvdXRwdXRzOgogICAgICAgIC0gbmFtZTogcmVzdWx0CiAgICAgICAgICByZWdleDogIiguKikiCgp1bmluc3RhbGw6CiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogIkVuc3VyZSBNYWdpYyIKICAgICAgY29tbWFuZDogLi9oZWxwZXJzLnNoCiAgICAgIGFyZ3VtZW50czoKICAgICAgICAtIGVuc3VyZU1hZ2ljCiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogInVuaW5zdGFsbCIKICAgICAgY29tbWFuZDogLi9oZWxwZXJzLnNoCiAgICAgIGFyZ3VtZW50czoKICAgICAgICAtIHVuaW5zdGFsbAogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJyb2xsIHRoZSBkaWNlIHdpdGggeW91ciBjaGFvcyBtb25rZXkiCiAgICAgIGNvbW1hbmQ6IC4vaGVscGVycy5zaAogICAgICBhcmd1bWVudHM6CiAgICAgICAgLSBjaGFvc19tb25rZXkKICAgICAgICAtICR7IGJ1bmRsZS5wYXJhbWV0ZXJzLmNoYW9zX21vbmtleSB9Cg==", "version": "", "commit": "" }, diff --git a/pkg/porter/archive.go b/pkg/porter/archive.go index 89569f774..619b73733 100644 --- a/pkg/porter/archive.go +++ b/pkg/porter/archive.go @@ -147,11 +147,11 @@ func (ex *exporter) export() error { } if err := ex.prepareArtifacts(ex.bundle); err != nil { - return fmt.Errorf("error preparing artifacts: %s", err) + return fmt.Errorf("error preparing bundle artifact: %s", err) } if err := ex.chtimes(archiveDir); err != nil { - return fmt.Errorf("error preparing artifacts: %s", err) + return fmt.Errorf("error clearing timestamps on the bundle artifact: %s", err) } tarOptions := &archive.TarOptions{ diff --git a/pkg/porter/archive_test.go b/pkg/porter/archive_test.go index 8b43c339a..69965bcf7 100644 --- a/pkg/porter/archive_test.go +++ b/pkg/porter/archive_test.go @@ -8,7 +8,7 @@ import ( "get.porter.sh/porter/tests" "github.com/cnabio/cnab-go/bundle" "github.com/cnabio/cnab-to-oci/relocation" - "github.com/pivotal/image-relocation/pkg/image" + "github.com/cnabio/image-relocation/pkg/image" "github.com/stretchr/testify/require" ) diff --git a/pkg/porter/publish.go b/pkg/porter/publish.go index 71467dbdb..962383cec 100644 --- a/pkg/porter/publish.go +++ b/pkg/porter/publish.go @@ -21,10 +21,10 @@ import ( "github.com/cnabio/cnab-go/bundle/loader" "github.com/cnabio/cnab-go/packager" "github.com/cnabio/cnab-to-oci/relocation" + "github.com/cnabio/image-relocation/pkg/image" + "github.com/cnabio/image-relocation/pkg/registry" + "github.com/cnabio/image-relocation/pkg/registry/ggcr" "github.com/opencontainers/go-digest" - "github.com/pivotal/image-relocation/pkg/image" - "github.com/pivotal/image-relocation/pkg/registry" - "github.com/pivotal/image-relocation/pkg/registry/ggcr" ) // PublishOptions are options that may be specified when publishing a bundle. diff --git a/pkg/porter/publish_test.go b/pkg/porter/publish_test.go index 720f5f13e..22ff9a53e 100644 --- a/pkg/porter/publish_test.go +++ b/pkg/porter/publish_test.go @@ -9,8 +9,8 @@ import ( "get.porter.sh/porter/pkg/cnab" "github.com/cnabio/cnab-go/bundle" "github.com/cnabio/cnab-to-oci/relocation" - "github.com/pivotal/image-relocation/pkg/image" - "github.com/pivotal/image-relocation/pkg/registry" + "github.com/cnabio/image-relocation/pkg/image" + "github.com/cnabio/image-relocation/pkg/registry" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/yaml/yq.go b/pkg/yaml/yq.go index 5fb5ce6ac..d60488535 100644 --- a/pkg/yaml/yq.go +++ b/pkg/yaml/yq.go @@ -106,7 +106,17 @@ func (e *Editor) SetValue(path string, value string) error { cmd := yqlib.UpdateCommand{Command: "update", Path: path, Value: parsedValue, Overwrite: true} err := e.yq.Update(e.node, cmd, true) if err != nil { - return fmt.Errorf("could not update manifest path %q with value %q: %w", path, value, err) + return fmt.Errorf("could not update path %q with value %q: %w", path, value, err) + } + + return nil +} + +func (e *Editor) DeleteNode(path string) error { + cmd := yqlib.UpdateCommand{Command: "delete", Path: path} + err := e.yq.Update(e.node, cmd, true) + if err != nil { + return fmt.Errorf("could not delete path %q: %w", path, err) } return nil diff --git a/tests/integration/copy_test.go b/tests/integration/copy_test.go index 4b121e539..18be267f5 100644 --- a/tests/integration/copy_test.go +++ b/tests/integration/copy_test.go @@ -22,7 +22,7 @@ func TestCopy_UsesRelocationMap(t *testing.T) { reg1 := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: false}) // Publish the bundle to the insecure registry - origRef := fmt.Sprintf("localhost:%s/orig-mydb:v0.1.1", reg1.Port) + origRef := fmt.Sprintf("%s/orig-mydb:v0.1.1", reg1) test.MakeTestBundle(testdata.MyDb, origRef) ociRef, err := cnab.ParseOCIReference(origRef) @@ -35,13 +35,13 @@ func TestCopy_UsesRelocationMap(t *testing.T) { // Copy the bundle to the integration test registry, using --insecure-registry // because the destination uses a self-signed certificate - copiedRef := fmt.Sprintf("localhost:%s/copy-mydb:v0.1.1", reg2.Port) + copiedRef := fmt.Sprintf("%s/copy-mydb:v0.1.1", reg2) test.RequirePorter("copy", "--source", origRef, "--destination", copiedRef, "--insecure-registry") reg1.Close() // Copy the copied bundle to a new location. This will fail if we aren't using the relocation map. - finalRef := fmt.Sprintf("localhost:%s/copy-copy-mydb:v0.1.1", reg2.Port) + finalRef := fmt.Sprintf("%s/copy-copy-mydb:v0.1.1", reg2) test.RequirePorter("copy", "--source", copiedRef, "--destination", finalRef, "--insecure-registry") finalOCIRef, err := cnab.ParseOCIReference(finalRef) @@ -56,5 +56,5 @@ func TestCopy_UsesRelocationMap(t *testing.T) { require.NoError(t, json.Unmarshal([]byte(inspectOutput), &inspectRaw)) images := inspectRaw["invocationImages"].([]interface{}) invocationImage := images[0].(map[string]interface{}) - require.Contains(t, invocationImage["originalImage"].(string), fmt.Sprintf("localhost:%s/orig-mydb", reg1.Port)) + require.Contains(t, invocationImage["originalImage"].(string), fmt.Sprintf("%s/orig-mydb", reg1)) } diff --git a/tests/integration/registry_integration_test.go b/tests/integration/registry_integration_test.go index cfb02ce0e..730f8f1da 100644 --- a/tests/integration/registry_integration_test.go +++ b/tests/integration/registry_integration_test.go @@ -35,10 +35,9 @@ func TestRegistry_ListTags(t *testing.T) { require.NoError(t, err, "tester.NewTest failed") defer testr.Close() reg := testr.StartTestRegistry(tester.TestRegistryOptions{UseTLS: true}) - registry := fmt.Sprintf("localhost:%s", reg.Port) // Copy a test bundle to the registry - testRef := fmt.Sprintf("%s/porter-hello-nonroot:v0.1.0", registry) + testRef := fmt.Sprintf("%s/porter-hello-nonroot:v0.1.0", reg) testr.RunPorter("copy", "--source=docker.io/carolynvs/porter-hello-nonroot:v0.1.0", "--destination", testRef, "--insecure-registry") ref := cnab.MustParseOCIReference(testRef) diff --git a/tests/smoke/airgap_test.go b/tests/smoke/airgap_test.go index 5090e15eb..f76c3313b 100644 --- a/tests/smoke/airgap_test.go +++ b/tests/smoke/airgap_test.go @@ -12,7 +12,6 @@ import ( "get.porter.sh/porter/pkg/yaml" "get.porter.sh/porter/tests/testdata" "get.porter.sh/porter/tests/tester" - "github.com/carolynvs/magex/mgx" "github.com/carolynvs/magex/shx" "github.com/cnabio/cnab-go/bundle/loader" "github.com/cnabio/cnab-go/packager" @@ -22,61 +21,104 @@ import ( // Validate that we can move a bundle into an aigraped environment // and that it works without referencing the old environment/images. -// This also validates a lot of our insecure registry configuration. +// This also validates a lot of our insecure/unsecure registry configurations. func TestAirgappedEnvironment(t *testing.T) { - test, err := tester.NewTest(t) - defer test.Close() - require.NoError(t, err, "test setup failed") - - // Start a temporary insecure test registry that uses self-signed certificates - reg1 := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: true}) - - // Publish referenced image to the insecure registry - // This helps test that we can publish a bundle that references images from multiple registries - // and that we properly apply skipTLS to those registries (and not just the registry to which we are pushing) - referencedImg := "carolynvs/whalesayd@sha256:8b92b7269f59e3ed824e811a1ff1ee64f0d44c0218efefada57a4bebc2d7ef6f" - localRegRepo := fmt.Sprintf("localhost:%s/whalesayd", reg1.Port) - localRegRef := localRegRepo + ":latest" - require.NoError(t, shx.RunE("docker", "pull", referencedImg)) - require.NoError(t, shx.RunE("docker", "tag", referencedImg, localRegRef)) - output, err := shx.OutputE("docker", "push", localRegRef) - require.NoError(t, err) - digest := getDigestFromDockerOutput(test.T, output) - localRefWithDigest := fmt.Sprintf("%s@%s", localRegRepo, digest) - - // Start a second insecure test registry that uses self-signed certificates - reg2 := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: true}) - - // Edit the bundle so that it's referencing the image on the temporary registry - // make sure the referenced image is not in local image cache - shx.RunV("docker", "rmi", localRegRef) - originTestBun := filepath.Join(test.RepoRoot, fmt.Sprintf("tests/testdata/%s/porter.yaml", testdata.MyBunsWithImgReference)) - testBun := filepath.Join(test.TestDir, "mybuns-img-reference.yaml") - mgx.Must(shx.Copy(originTestBun, testBun)) - test.EditYaml(testBun, func(yq *yaml.Editor) error { - return yq.SetValue("images.whalesayd.repository", fmt.Sprintf("localhost:%s/whalesayd", reg1.Port)) - }) - - // Publish a test bundle that references the image from the temp registry, and push to another insecure registry - test.RequirePorter("publish", "--file", "mybuns-img-reference.yaml", "--dir", test.TestDir, "--registry", reg2.String(), "--insecure-registry") - reg1.Close() - - // Archive the bundle, it should not attempt to hit the first registry - archiveFilePath := filepath.Join(test.TestDir, "archive-test.tgz") - origRef := fmt.Sprintf("localhost:%s/%s:%s", reg2.Port, testdata.MyBunsWithImgReference, "v0.1.0") - test.RequirePorter("archive", archiveFilePath, "--reference", origRef, "--insecure-registry") - relocMap := getRelocationMap(test, archiveFilePath) - require.Equal(test.T, fmt.Sprintf("localhost:%s/mybun-with-img-reference@sha256:499f71eec2e3bd78f26c268bbf5b2a65f73b96216fac4a89b86b5ebf115527b6", reg2.Port), relocMap[localRefWithDigest], "expected the relocation entry for the image to be the new published location") - - // Publish from the archived bundle to a new repository on the second registry - newRef := fmt.Sprintf("localhost:%s/%s-second:%s", reg2.Port, testdata.MyBunsWithImgReference, "v0.2.0") - test.RequirePorter("publish", "--archive", archiveFilePath, "-r", newRef, "--insecure-registry") - archiveFilePath2 := filepath.Join(test.TestDir, "archive-test2.tgz") - - // Archive from the new location on the second registry - test.RequirePorter("archive", archiveFilePath2, "--reference", newRef, "--insecure-registry") - relocMap2 := getRelocationMap(test, archiveFilePath2) - require.Equal(test.T, fmt.Sprintf("localhost:%s/mybun-with-img-reference-second@sha256:499f71eec2e3bd78f26c268bbf5b2a65f73b96216fac4a89b86b5ebf115527b6", reg2.Port), relocMap2[localRefWithDigest], "expected the relocation entry for the image to be the new published location") + testcases := []struct { + name string + useTLS bool + useAlias bool + insecure bool + }{ + // Validate we "just work" with an unsecured registry on localhost, just like docker does, without specifying --insecure-registry + {name: "plain http, no alias", useTLS: false, useAlias: false, insecure: false}, + // Validate we can connect to plain http when we can't detect that it's loopback/localhost as long as --insecure-registry is specified + // We do not support docker's extra automagic where it resolves the host and treats it like localhost. You have to specify --insecure-registry with a custom hostname + {name: "plain http, use alias", useTLS: false, useAlias: true, insecure: true}, + // Validate that --insecure-registry works with self-signed certificates + {name: "untrusted tls, no alias", useTLS: false, useAlias: true, insecure: true}, + } + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + insecureFlag := fmt.Sprintf("--insecure-registry=%t", tc.insecure) + + test, err := tester.NewTest(t) + defer test.Close() + require.NoError(t, err, "test setup failed") + test.Chdir(test.TestDir) + + // Start a temporary insecure test registry + reg1 := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: tc.useTLS, UseAlias: tc.useAlias}) + + // Publish referenced image to the insecure registry + // This helps test that we can publish a bundle that references images from multiple registries + // and that we properly apply --insecure-registry to those registries (and not just the registry to which we are pushing) + referencedImg := "carolynvs/whalesayd@sha256:8b92b7269f59e3ed824e811a1ff1ee64f0d44c0218efefada57a4bebc2d7ef6f" + localRegRepo := fmt.Sprintf("%s/whalesayd", reg1) + localRegRef := localRegRepo + ":latest" + require.NoError(t, shx.RunE("docker", "pull", referencedImg)) + require.NoError(t, shx.RunE("docker", "tag", referencedImg, localRegRef)) + output, err := shx.OutputE("docker", "push", localRegRef) + require.NoError(t, err) + digest := getDigestFromDockerOutput(test.T, output) + localRefWithDigest := fmt.Sprintf("%s@%s", localRegRepo, digest) + + // Start a second insecure test registry + reg2 := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: tc.useTLS, UseAlias: tc.useAlias}) + + // Edit the bundle so that it's referencing the image on the temporary registry + // make sure the referenced image is not in local image cache + shx.RunV("docker", "rmi", localRegRef) + err = shx.Copy(filepath.Join(test.RepoRoot, fmt.Sprintf("tests/testdata/%s/*", testdata.MyBuns)), test.TestDir) + require.NoError(t, err, "failed to copy test bundle") + test.EditYaml(filepath.Join(test.TestDir, "porter.yaml"), func(yq *yaml.Editor) error { + // Remove the bundle's dependencies to simplify installation + if err := yq.DeleteNode("dependencies"); err != nil { + return err + } + + // Reference our copy of the whalesayd image + return yq.SetValue("images.whalesayd.repository", fmt.Sprintf("%s/whalesayd", reg1)) + }) + + // Publish a test bundle that references the image from the temp registry, and push to another insecure registry + test.RequirePorter("publish", "--registry", reg2.String(), insecureFlag) + + // Stop the original registry, this ensures that we are relying 100% on the copy of the bundle in the second registry + reg1.Close() + + // + // Try out the two ways to move a bundle between registries: + // 1. Copy the bundle from one registry to the other directly + // + origRef := fmt.Sprintf("%s/%s:%s", reg2, testdata.MyBuns, "v0.1.2") + newRef := fmt.Sprintf("%s/%s-second:%s", reg2, testdata.MyBuns, "v0.2.0") + test.RequirePorter("copy", "--source", origRef, "--destination", newRef, insecureFlag) + + // + // 2. Use archive + publish to copy the bundle from one registry to the other + // + archiveFilePath := filepath.Join(test.TestDir, "archive-test.tgz") + test.RequirePorter("archive", archiveFilePath, "--reference", origRef, insecureFlag) + relocMap := getRelocationMap(test, archiveFilePath) + require.Equal(test.T, fmt.Sprintf("%s/mybuns@sha256:499f71eec2e3bd78f26c268bbf5b2a65f73b96216fac4a89b86b5ebf115527b6", reg2), relocMap[localRefWithDigest], "expected the relocation entry for the image to be the new published location") + + // Publish from the archived bundle to a new repository on the second registry + test.RequirePorter("publish", "--archive", archiveFilePath, "-r", newRef, insecureFlag) + archiveFilePath2 := filepath.Join(test.TestDir, "archive-test2.tgz") + + // Archive from the new location on the second registry + test.RequirePorter("archive", archiveFilePath2, "--reference", newRef, insecureFlag) + relocMap2 := getRelocationMap(test, archiveFilePath2) + require.Equal(test.T, fmt.Sprintf("%s/mybuns-second@sha256:499f71eec2e3bd78f26c268bbf5b2a65f73b96216fac4a89b86b5ebf115527b6", reg2), relocMap2[localRefWithDigest], "expected the relocation entry for the image to be the new published location") + + // Validate that we can pull the bundle from the new location + test.RequirePorter("explain", newRef) + + // Validate that we can install from the new location + test.ApplyTestBundlePrerequisites() + test.RequirePorter("install", "-r", newRef, insecureFlag, "-c=mybuns", "-p=mybuns") + }) + } } func getRelocationMap(test tester.Tester, archiveFilePath string) relocation.ImageRelocationMap { diff --git a/tests/testdata/helpers.go b/tests/testdata/helpers.go index b9287eabf..0885349e8 100644 --- a/tests/testdata/helpers.go +++ b/tests/testdata/helpers.go @@ -12,7 +12,4 @@ const ( // MyDbRef is the full reference to the mydb test bundle. MyDbRef = "localhost:5000/mydb:v0.1.0" - - // MyBunsWithImgReference is the test bundle that contains image reference. - MyBunsWithImgReference = "mybun-with-img-reference" ) diff --git a/tests/testdata/mybun-with-img-reference/porter.yaml b/tests/testdata/mybun-with-img-reference/porter.yaml deleted file mode 100644 index 81ec0917f..000000000 --- a/tests/testdata/mybun-with-img-reference/porter.yaml +++ /dev/null @@ -1,24 +0,0 @@ -schemaVersion: 1.0.0-alpha.1 -name: mybun-with-img-reference -version: 0.1.0 -description: "An example Porter configuration that contains image reference" -registry: "localhost:5000" - -images: - whalesayd: - description: "Whalesay as a service" - imageType: "docker" - repository: localhost:5000/whalesayd - tag: "latest" - -mixins: - - exec -install: - - exec: - description: "Install Hello World" -upgrade: - - exec: - description: "World 2.0" -uninstall: - - exec: - description: "Uninstall Hello World" diff --git a/tests/testdata/mybuns/porter.yaml b/tests/testdata/mybuns/porter.yaml index 875099d5d..1ab92f3be 100644 --- a/tests/testdata/mybuns/porter.yaml +++ b/tests/testdata/mybuns/porter.yaml @@ -60,6 +60,13 @@ dependencies: parameters: database: bigdb +images: + whalesayd: + description: "Whalesay as a service" + imageType: "docker" + repository: carolynvs/whalesayd + tag: "latest" + mixins: - exec @@ -103,7 +110,6 @@ install: - name: result regex: "(.*)" - dry-run: - exec: description: "Check some things" diff --git a/tests/tester/helpers.go b/tests/tester/helpers.go index 8b8e36fc8..c605ffb04 100644 --- a/tests/tester/helpers.go +++ b/tests/tester/helpers.go @@ -15,17 +15,21 @@ import ( "github.com/stretchr/testify/require" ) -// PrepareTestBundle ensures that the mybuns test bundle has been built. +// PrepareTestBundle ensures that the mybuns test bundle is ready to use. func (t Tester) PrepareTestBundle() { - // These are environment variables referenced by the mybuns credential set - os.Setenv("USER", "porterci") - os.Setenv("ALT_USER", "porterci2") - // Build and publish an interesting test bundle and its dependency t.MakeTestBundle(testdata.MyDb, testdata.MyDbRef) t.MakeTestBundle(testdata.MyBuns, testdata.MyBunsRef) - // Import a parameter and credential set for the bundle into the global namespace + t.ApplyTestBundlePrerequisites() +} + +// ApplyTestBundlePrerequisites ensures that anything required by the test bundle, mybuns, is ready to use. +func (t Tester) ApplyTestBundlePrerequisites() { + // These are environment variables referenced by the mybuns credential set + os.Setenv("USER", "porterci") + os.Setenv("ALT_USER", "porterci2") + t.RequirePorter("parameters", "apply", filepath.Join(t.RepoRoot, "tests/testdata/params/mybuns.yaml"), "--namespace=") t.RequirePorter("credentials", "apply", filepath.Join(t.RepoRoot, "tests/testdata/creds/mybuns.yaml"), "--namespace=") } diff --git a/tests/tester/test_registry.go b/tests/tester/test_registry.go index 8a4c4ac25..169d49de6 100644 --- a/tests/tester/test_registry.go +++ b/tests/tester/test_registry.go @@ -2,6 +2,7 @@ package tester import ( "fmt" + "os" "path/filepath" "testing" @@ -10,24 +11,40 @@ import ( "github.com/stretchr/testify/require" ) +// TestRegistryAlias is the environment variable that contains a pre-configured +// hostname alias that can be used to access localhost. This environment variable +// is only set in on the linux and macos CI agents so that we can test a variant +// of communicating with a registry that is unsecured but is not obviously "localhost" or 127.0.0.1. +const TestRegistryAlias = "PORTER_TEST_REGISTRY_ALIAS" + // TestRegistryOptions controls how a test registry is run. type TestRegistryOptions struct { + // UseTLS indicates the registry should use http, secured with a self-signed certificate. UseTLS bool + + // UseAlias indicates that when the TestRegistryAlias environment variable is set, + // the registry address use the hostname alias, and not localhost. + UseAlias bool } // TestRegistry is a temporary registry that is stopped when the test completes. type TestRegistry struct { - T *testing.T - ContainerID string - Port string + t *testing.T + containerID string + + // port that the registry is running on + port string // closed tracks if Close has been called so that we only try to close once. closed bool + + // hostname is the address or name used to reference the registry + hostname string } // String prints the registry URI. func (t *TestRegistry) String() string { - return fmt.Sprintf("localhost:%s", t.Port) + return fmt.Sprintf("%s:%s", t.hostname, t.port) } // Close stops the registry. @@ -37,9 +54,9 @@ func (t *TestRegistry) Close() { return } - err := shx.RunE("docker", "rm", "-vf", t.ContainerID) + err := shx.RunE("docker", "rm", "-vf", t.containerID) t.closed = true - assert.NoError(t.T, err) + assert.NoError(t.t, err) } // StartTestRegistry runs an OCI registry in a container, @@ -61,16 +78,26 @@ func (t Tester) StartTestRegistry(opts TestRegistryOptions) *TestRegistry { cmd.Args("registry:2") var err error - reg := &TestRegistry{T: t.T} - reg.ContainerID, err = cmd.OutputE() + reg := &TestRegistry{t: t.T} + reg.containerID, err = cmd.OutputE() require.NoError(t.T, err, "Could not start a temporary registry") // Automatically close the registry when the test is done t.T.Cleanup(reg.Close) // Get the port that it is running on - reg.Port, err = shx.OutputE("docker", "inspect", reg.ContainerID, "--format", `{{ (index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort }}`) + reg.port, err = shx.OutputE("docker", "inspect", reg.containerID, "--format", `{{ (index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort }}`) require.NoError(t.T, err, "Could not get the published port of the temporary registry") + // Determine if we have a hostname alias set up for the registry + var hostname string + if opts.UseAlias { + hostname = os.Getenv(TestRegistryAlias) + } + if hostname == "" { + hostname = "localhost" + } + reg.hostname = hostname + return reg }