From 087e236c82f11cf9b755edb119bd492eed4bb8d3 Mon Sep 17 00:00:00 2001 From: Kim Tsao Date: Mon, 3 Apr 2023 11:45:27 -0400 Subject: [PATCH 1/5] fix manifest Signed-off-by: Kim Tsao --- index/server/pkg/server/registry.go | 30 ++++--- .../stacks/go/{1.2.0 => 1.0.2}/devfile.yaml | 32 ++++---- tests/registry/stacks/go/1.1.0/devfile.yaml | 50 ------------ tests/registry/stacks/go/2.0.0/devfile.yaml | 79 +++++++++++++++++++ .../stacks/go/2.0.0/docker/Dockerfile | 14 ++++ .../stacks/go/2.0.0/kubernetes/deploy.yaml | 41 ++++++++++ tests/registry/stacks/go/stack.yaml | 8 +- 7 files changed, 176 insertions(+), 78 deletions(-) rename tests/registry/stacks/go/{1.2.0 => 1.0.2}/devfile.yaml (54%) delete mode 100644 tests/registry/stacks/go/1.1.0/devfile.yaml create mode 100644 tests/registry/stacks/go/2.0.0/devfile.yaml create mode 100644 tests/registry/stacks/go/2.0.0/docker/Dockerfile create mode 100644 tests/registry/stacks/go/2.0.0/kubernetes/deploy.yaml diff --git a/index/server/pkg/server/registry.go b/index/server/pkg/server/registry.go index 2d9d9fd60..b9ddf4dd8 100644 --- a/index/server/pkg/server/registry.go +++ b/index/server/pkg/server/registry.go @@ -19,6 +19,8 @@ import ( "context" "errors" "fmt" + "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "io/ioutil" "log" "os" @@ -35,6 +37,7 @@ import ( func pushStackToRegistry(versionComponent indexSchema.Version, stackName string) error { // Load the devfile into memory and set up the pushing resource (file name, file content, media type, ref) memoryStore := content.NewMemory() + pushContents := []ocispec.Descriptor{} ref := path.Join(registryService, "/", versionComponent.Links["self"]) for _, resource := range versionComponent.Resources { @@ -77,16 +80,25 @@ func pushStackToRegistry(versionComponent indexSchema.Version, stackName string) if err != nil { return err } - manifest, manifestDesc, config, configDesc, err := content.GenerateManifestAndConfig(nil, nil, desc) - if err != nil { - return err - } - memoryStore.Set(configDesc, config) - err = memoryStore.StoreManifest(ref, manifestDesc, manifest) - if err != nil { - return err - } + pushContents = append(pushContents, desc) + } + + configBytes := []byte("{}") + dig := digest.FromBytes(configBytes) + configDesc := ocispec.Descriptor{ + MediaType: devfileConfigMediaType, + Digest: dig, + Size: int64(len(configBytes)), + } + manifest, manifestDesc, err := content.GenerateManifest(&configDesc, nil, pushContents...) + if err != nil { + return err + } + memoryStore.Set(configDesc, configBytes) + err = memoryStore.StoreManifest(ref, manifestDesc, manifest) + if err != nil { + return err } ctx := context.Background() diff --git a/tests/registry/stacks/go/1.2.0/devfile.yaml b/tests/registry/stacks/go/1.0.2/devfile.yaml similarity index 54% rename from tests/registry/stacks/go/1.2.0/devfile.yaml rename to tests/registry/stacks/go/1.0.2/devfile.yaml index 4cb263fd6..bb9aaa146 100644 --- a/tests/registry/stacks/go/1.2.0/devfile.yaml +++ b/tests/registry/stacks/go/1.0.2/devfile.yaml @@ -1,43 +1,46 @@ schemaVersion: 2.1.0 metadata: - description: Stack with the latest Go version with devfile v2.1.0 schema verison + description: "Go is an open source programming language that makes it easy to build simple, reliable, and efficient software." displayName: Go Runtime icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg - language: go name: go + projectType: Go provider: Red Hat - projectType: go + language: Go tags: - - testtag - version: 1.2.0 + - Go + version: 1.0.2 starterProjects: - name: go-starter + description: A Go project with a simple HTTP server git: checkoutFrom: revision: main remotes: origin: https://github.com/devfile-samples/devfile-stack-go.git - - name: go-starter-offline - zip: - location: go-starter-offline.zip components: - container: endpoints: - - name: http + - name: http-go targetPort: 8080 - image: golang:latest + image: registry.access.redhat.com/ubi9/go-toolset:latest + args: ["tail", "-f", "/dev/null"] memoryLimit: 1024Mi mountSources: true - sourceMapping: /project name: runtime commands: - exec: - commandLine: GOCACHE=/project/.cache go build main.go + env: + - name: GOPATH + value: ${PROJECT_SOURCE}/.go + - name: GOCACHE + value: ${PROJECT_SOURCE}/.cache + commandLine: go build main.go component: runtime group: isDefault: true kind: build - workingDir: /project + workingDir: ${PROJECT_SOURCE} id: build - exec: commandLine: ./main @@ -45,6 +48,5 @@ commands: group: isDefault: true kind: run - workingDir: /project + workingDir: ${PROJECT_SOURCE} id: run - diff --git a/tests/registry/stacks/go/1.1.0/devfile.yaml b/tests/registry/stacks/go/1.1.0/devfile.yaml deleted file mode 100644 index d4726d07f..000000000 --- a/tests/registry/stacks/go/1.1.0/devfile.yaml +++ /dev/null @@ -1,50 +0,0 @@ -schemaVersion: 2.0.0 -metadata: - description: Stack with the latest Go version with devfile v2.0.0 schema verison - displayName: Go Runtime - icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg - language: go - name: go - provider: Red Hat - projectType: go - tags: - - Go - version: 1.1.0 -starterProjects: - - name: go-starter - git: - checkoutFrom: - revision: main - remotes: - origin: https://github.com/devfile-samples/devfile-stack-go.git - - name: go-starter-offline - zip: - location: go-starter-offline.zip -components: - - container: - endpoints: - - name: http - targetPort: 8080 - image: golang:latest - memoryLimit: 1024Mi - mountSources: true - sourceMapping: /project - name: runtime -commands: - - exec: - commandLine: GOCACHE=/project/.cache go build main.go - component: runtime - group: - isDefault: true - kind: build - workingDir: /project - id: build - - exec: - commandLine: ./main - component: runtime - group: - isDefault: true - kind: run - workingDir: /project - id: run - diff --git a/tests/registry/stacks/go/2.0.0/devfile.yaml b/tests/registry/stacks/go/2.0.0/devfile.yaml new file mode 100644 index 000000000..9a80424eb --- /dev/null +++ b/tests/registry/stacks/go/2.0.0/devfile.yaml @@ -0,0 +1,79 @@ +schemaVersion: 2.2.0 +metadata: + description: 'Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.' + displayName: Go Runtime + icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg + name: go + projectType: Go + provider: Red Hat + language: Go + tags: + - Go + version: 2.0.0 +starterProjects: + - name: go-starter + description: A Go project with a simple HTTP server + git: + checkoutFrom: + revision: main + remotes: + origin: https://github.com/devfile-samples/devfile-stack-go.git +components: + - name: build + image: + imageName: go-image:latest + dockerfile: + uri: docker/Dockerfile + buildContext: . + rootRequired: false + - name: deploy + kubernetes: + uri: kubernetes/deploy.yaml + endpoints: + - name: http-8081 + targetPort: 8081 + - container: + endpoints: + - name: http-go + targetPort: 8080 + image: registry.access.redhat.com/ubi9/go-toolset:latest + args: ['tail', '-f', '/dev/null'] + memoryLimit: 1024Mi + mountSources: true + name: runtime +commands: + - id: build-image + apply: + component: build + - id: deployk8s + apply: + component: deploy + - id: deploy + composite: + commands: + - build-image + - deployk8s + group: + kind: deploy + isDefault: true + - exec: + env: + - name: GOPATH + value: ${PROJECT_SOURCE}/.go + - name: GOCACHE + value: ${PROJECT_SOURCE}/.cache + commandLine: go build main.go + component: runtime + group: + isDefault: true + kind: build + workingDir: ${PROJECT_SOURCE} + id: build + - exec: + commandLine: ./main + component: runtime + group: + isDefault: true + kind: run + workingDir: ${PROJECT_SOURCE} + id: run diff --git a/tests/registry/stacks/go/2.0.0/docker/Dockerfile b/tests/registry/stacks/go/2.0.0/docker/Dockerfile new file mode 100644 index 000000000..4b95b84db --- /dev/null +++ b/tests/registry/stacks/go/2.0.0/docker/Dockerfile @@ -0,0 +1,14 @@ +FROM registry.access.redhat.com/ubi9/go-toolset:latest + +WORKDIR /app + +COPY go.mod ./ +RUN go mod download + +COPY *.go ./ + +RUN go build -o ./main + +EXPOSE 8081 + +CMD [ "app/main" , "-p=8081"] diff --git a/tests/registry/stacks/go/2.0.0/kubernetes/deploy.yaml b/tests/registry/stacks/go/2.0.0/kubernetes/deploy.yaml new file mode 100644 index 000000000..2cd45e0a4 --- /dev/null +++ b/tests/registry/stacks/go/2.0.0/kubernetes/deploy.yaml @@ -0,0 +1,41 @@ +kind: Service +apiVersion: v1 +metadata: + name: my-go-svc +spec: + ports: + - name: http-8081 + port: 8081 + protocol: TCP + targetPort: 8081 + selector: + app: go-app +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: my-go +spec: + replicas: 1 + selector: + matchLabels: + app: go-app + template: + metadata: + labels: + app: go-app + spec: + containers: + - name: my-go + image: go-image:latest + ports: + - name: http + containerPort: 8081 + protocol: TCP + resources: + requests: + memory: "10Mi" + cpu: "10m" + limits: + memory: "100Mi" + cpu: "100m" diff --git a/tests/registry/stacks/go/stack.yaml b/tests/registry/stacks/go/stack.yaml index 4ac2bf82a..11b3b4cf4 100644 --- a/tests/registry/stacks/go/stack.yaml +++ b/tests/registry/stacks/go/stack.yaml @@ -1,8 +1,8 @@ name: go -description: Stack with the latest Go version +description: 'Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.' displayName: Go Runtime icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg versions: - - version: 1.1.0 - default: true #should have one and only one default version - - version: 1.2.0 + - version: 1.0.2 + default: true # should have one and only one default version + - version: 2.0.0 From 99d80136a77fafd4a32cf54baae6b196f5456f30 Mon Sep 17 00:00:00 2001 From: Kim Tsao Date: Mon, 3 Apr 2023 12:21:44 -0400 Subject: [PATCH 2/5] restore go 1.2.0 stack for testing Signed-off-by: Kim Tsao --- tests/registry/stacks/go/1.2.0/devfile.yaml | 49 +++++++++++++++++++++ tests/registry/stacks/go/stack.yaml | 1 + 2 files changed, 50 insertions(+) create mode 100644 tests/registry/stacks/go/1.2.0/devfile.yaml diff --git a/tests/registry/stacks/go/1.2.0/devfile.yaml b/tests/registry/stacks/go/1.2.0/devfile.yaml new file mode 100644 index 000000000..0bb7f96bb --- /dev/null +++ b/tests/registry/stacks/go/1.2.0/devfile.yaml @@ -0,0 +1,49 @@ +schemaVersion: 2.1.0 +metadata: + description: Stack with the latest Go version with devfile v2.1.0 schema verison + displayName: Go Runtime + icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg + language: go + name: go + provider: Red Hat + projectType: go + tags: + - testtag + version: 1.2.0 +starterProjects: + - name: go-starter + git: + checkoutFrom: + revision: main + remotes: + origin: https://github.com/devfile-samples/devfile-stack-go.git + - name: go-starter-offline + zip: + location: go-starter-offline.zip +components: + - container: + endpoints: + - name: http + targetPort: 8080 + image: golang:latest + memoryLimit: 1024Mi + mountSources: true + sourceMapping: /project + name: runtime +commands: + - exec: + commandLine: GOCACHE=/project/.cache go build main.go + component: runtime + group: + isDefault: true + kind: build + workingDir: /project + id: build + - exec: + commandLine: ./main + component: runtime + group: + isDefault: true + kind: run + workingDir: /project + id: run \ No newline at end of file diff --git a/tests/registry/stacks/go/stack.yaml b/tests/registry/stacks/go/stack.yaml index 11b3b4cf4..29417f586 100644 --- a/tests/registry/stacks/go/stack.yaml +++ b/tests/registry/stacks/go/stack.yaml @@ -5,4 +5,5 @@ icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main versions: - version: 1.0.2 default: true # should have one and only one default version + - version: 1.2.0 - version: 2.0.0 From 886bbef9acf247582840e06b2b7d15d3bae7b4bb Mon Sep 17 00:00:00 2001 From: Kim Tsao Date: Mon, 3 Apr 2023 17:28:48 -0400 Subject: [PATCH 3/5] registry tests - update go 1.2.0 as default Signed-off-by: Kim Tsao --- tests/registry/stacks/go/stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/registry/stacks/go/stack.yaml b/tests/registry/stacks/go/stack.yaml index 29417f586..f8e3187e3 100644 --- a/tests/registry/stacks/go/stack.yaml +++ b/tests/registry/stacks/go/stack.yaml @@ -4,6 +4,6 @@ displayName: Go Runtime icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg versions: - version: 1.0.2 - default: true # should have one and only one default version - version: 1.2.0 + default: true # should have one and only one default version - version: 2.0.0 From 767ce885f7d7f920462a4ba91be7b9517253db42 Mon Sep 17 00:00:00 2001 From: Kim Tsao Date: Mon, 3 Apr 2023 20:10:43 -0400 Subject: [PATCH 4/5] add devfile library test Signed-off-by: Kim Tsao --- .../pkg/tests/devfilelibrary_tests.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/integration/pkg/tests/devfilelibrary_tests.go b/tests/integration/pkg/tests/devfilelibrary_tests.go index d8686a1cf..af63a5221 100644 --- a/tests/integration/pkg/tests/devfilelibrary_tests.go +++ b/tests/integration/pkg/tests/devfilelibrary_tests.go @@ -128,6 +128,26 @@ var _ = ginkgo.Describe("[Verify registry library works with registry]", func() gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) + ginkgo.It("should properly retrieve a devfile with a deploy.yaml", func() { + tempDir := path.Join(os.TempDir(), goStack) + util.CmdShouldPass("registry-library", "pull", config.Registry, goStack+":latest", "--context", tempDir, "--new-index-schema") + devfilePath := path.Join(tempDir, "devfile.yaml") + _, err := os.Stat(devfilePath) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + + // The devfile.yaml should be valid, verify that devfile parser doesn't throw an error + parserArgs := parser.ParserArgs{ + Path: devfilePath, + } + _, _, err = devfilePkg.ParseDevfileAndValidate(parserArgs) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + + deployPath := path.Join(tempDir, "kubernetes/deploy.yaml") + _, err = os.Stat(deployPath) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + + }) + ginkgo.It("should properly download stack starter project", func() { tempDir := path.Join(os.TempDir(), javaMavenStarter) util.CmdShouldPass("registry-library", "download", publicDevfileRegistry, javaMavenStack, javaMavenStarter, "--context", tempDir) From 9fcac9ce5fb699d5336533004e5934ef55bd923c Mon Sep 17 00:00:00 2001 From: Kim Tsao Date: Mon, 3 Apr 2023 21:30:16 -0400 Subject: [PATCH 5/5] remove test, wrong library Signed-off-by: Kim Tsao --- .../pkg/tests/devfilelibrary_tests.go | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/integration/pkg/tests/devfilelibrary_tests.go b/tests/integration/pkg/tests/devfilelibrary_tests.go index af63a5221..d8686a1cf 100644 --- a/tests/integration/pkg/tests/devfilelibrary_tests.go +++ b/tests/integration/pkg/tests/devfilelibrary_tests.go @@ -128,26 +128,6 @@ var _ = ginkgo.Describe("[Verify registry library works with registry]", func() gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) - ginkgo.It("should properly retrieve a devfile with a deploy.yaml", func() { - tempDir := path.Join(os.TempDir(), goStack) - util.CmdShouldPass("registry-library", "pull", config.Registry, goStack+":latest", "--context", tempDir, "--new-index-schema") - devfilePath := path.Join(tempDir, "devfile.yaml") - _, err := os.Stat(devfilePath) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - - // The devfile.yaml should be valid, verify that devfile parser doesn't throw an error - parserArgs := parser.ParserArgs{ - Path: devfilePath, - } - _, _, err = devfilePkg.ParseDevfileAndValidate(parserArgs) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - - deployPath := path.Join(tempDir, "kubernetes/deploy.yaml") - _, err = os.Stat(deployPath) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - - }) - ginkgo.It("should properly download stack starter project", func() { tempDir := path.Join(os.TempDir(), javaMavenStarter) util.CmdShouldPass("registry-library", "download", publicDevfileRegistry, javaMavenStack, javaMavenStarter, "--context", tempDir)