diff --git a/index/server/pkg/server/registry.go b/index/server/pkg/server/registry.go index 2d9d9fd6..b9ddf4dd 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.1.0/devfile.yaml b/tests/registry/stacks/go/1.0.2/devfile.yaml similarity index 54% rename from tests/registry/stacks/go/1.1.0/devfile.yaml rename to tests/registry/stacks/go/1.0.2/devfile.yaml index d4726d07..bb9aaa14 100644 --- a/tests/registry/stacks/go/1.1.0/devfile.yaml +++ b/tests/registry/stacks/go/1.0.2/devfile.yaml @@ -1,43 +1,46 @@ -schemaVersion: 2.0.0 +schemaVersion: 2.1.0 metadata: - description: Stack with the latest Go version with devfile v2.0.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: - Go - version: 1.1.0 + 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.2.0/devfile.yaml b/tests/registry/stacks/go/1.2.0/devfile.yaml index 4cb263fd..0bb7f96b 100644 --- a/tests/registry/stacks/go/1.2.0/devfile.yaml +++ b/tests/registry/stacks/go/1.2.0/devfile.yaml @@ -46,5 +46,4 @@ commands: isDefault: true kind: run workingDir: /project - id: run - + id: run \ No newline at end of file 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 00000000..9a80424e --- /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 00000000..4b95b84d --- /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 00000000..2cd45e0a --- /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 4ac2bf82..f8e3187e 100644 --- a/tests/registry/stacks/go/stack.yaml +++ b/tests/registry/stacks/go/stack.yaml @@ -1,8 +1,9 @@ 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.0.2 - version: 1.2.0 + default: true # should have one and only one default version + - version: 2.0.0