Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix manifest #171

Merged
merged 5 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions index/server/pkg/server/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
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
component: runtime
group:
isDefault: true
kind: run
workingDir: /project
workingDir: ${PROJECT_SOURCE}
id: run

3 changes: 1 addition & 2 deletions tests/registry/stacks/go/1.2.0/devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ commands:
isDefault: true
kind: run
workingDir: /project
id: run

id: run
79 changes: 79 additions & 0 deletions tests/registry/stacks/go/2.0.0/devfile.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/registry/stacks/go/2.0.0/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
41 changes: 41 additions & 0 deletions tests/registry/stacks/go/2.0.0/kubernetes/deploy.yaml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 4 additions & 3 deletions tests/registry/stacks/go/stack.yaml
Original file line number Diff line number Diff line change
@@ -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