From f87283312d862a2bca151d8e95bcfd97ce59ff59 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Thu, 14 Sep 2023 01:46:14 -0400 Subject: [PATCH 1/5] Squashed commit of the following: commit 5a5f1a0bf351b8687530b26593016755fa94485e Author: Michael Valdron Date: Thu Apr 27 19:21:54 2023 -0400 Copy default config.yml file for cases of not having any to provide. Signed-off-by: Michael Valdron commit 9660f43714fda438fbe38352433cb5da609dee98 Author: Michael Valdron Date: Fri Mar 17 18:40:55 2023 -0400 registry-support devfile added. Signed-off-by: Michael Valdron commit 67b8bd58b4e9f0883a18f0be6f5635ed316af939 Author: Michael Valdron Date: Fri Apr 14 00:15:54 2023 -0400 add registry config file. Signed-off-by: Michael Valdron commit dc76b9df1bcc9482065cfecc83ec7d71625bc16c Author: Michael Valdron Date: Fri Mar 17 18:39:57 2023 -0400 odo ignores added. Signed-off-by: Michael Valdron Signed-off-by: Michael Valdron --- .devfile.yaml | 137 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 3 +- oci-registry/Dockerfile | 2 + oci-registry/config.yml | 18 ++++++ 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 .devfile.yaml create mode 100644 oci-registry/config.yml diff --git a/.devfile.yaml b/.devfile.yaml new file mode 100644 index 00000000..f8c79fa0 --- /dev/null +++ b/.devfile.yaml @@ -0,0 +1,137 @@ +# +# Copyright 2023 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +schemaVersion: 2.2.0 +metadata: + name: devfile-registry +components: + - name: devfile-index-base-builder + image: + imageName: quay.io/{{profile}}/{{devfileIndexBaseImage}} + autoBuild: true + dockerfile: + uri: index/server/Dockerfile + buildContext: index/server + - name: devfile-index-image-builder + image: + imageName: quay.io/{{profile}}/{{devfileIndexImage}} + autoBuild: true + dockerfile: + uri: .ci/Dockerfile + buildContext: . + - name: oci-registry-builder + image: + imageName: "{{ociRegistryImage}}" + dockerfile: + uri: oci-registry/Dockerfile + buildContext: oci-registry + - name: devfile-registry-storage + volume: + ephemeral: true + - name: config + volume: + ephemeral: true + - name: devfile-registry + attributes: + container-overrides: + securityContext: + allowPrivilegeEscalation: false + runAsNonRoot: true + capabilities: + drop: ["ALL"] + seccompProfile: + type: "RuntimeDefault" + container: + image: quay.io/{{profile}}/{{devfileIndexImage}} + memoryLimit: "{{devfileIndexMemoryLimit}}" + command: + - /entrypoint.sh + endpoints: + - exposure: public + name: http-8080 + protocol: http + targetPort: 8080 + env: + - name: REGISTRY_HEADLESS + value: "true" + - name: oci-registry + attributes: + container-overrides: + securityContext: + allowPrivilegeEscalation: false + runAsNonRoot: true + capabilities: + drop: ["ALL"] + seccompProfile: + type: "RuntimeDefault" + container: + image: "{{ociRegistryImage}}" + memoryLimit: "{{ociRegistryMemoryLimit}}" + command: + - registry + - serve + - /etc/docker/registry/config.yml + mountSources: false + volumeMounts: + - name: devfile-registry-storage + path: /var/lib/registry +commands: + - id: build-devfile-index-base-image + apply: + component: devfile-index-base-builder + - id: build-devfile-index-image + apply: + component: devfile-index-image-builder + - id: build-oci-registry + apply: + component: oci-registry-builder + - id: build + composite: + commands: + - build-devfile-index-base-image + - build-devfile-index-image + group: + isDefault: true + kind: build + - id: build-all + composite: + commands: + - build-oci-registry + - build-devfile-index-base-image + - build-devfile-index-image + group: + kind: build + - id: run-devfile-index + apply: + component: devfile-registry + - id: run-oci-registry + apply: + component: oci-registry + - id: run + composite: + commands: + - run-oci-registry + - run-devfile-index + parallel: true + group: + isDefault: true + kind: run +variables: + profile: devfile + devfileIndexBaseImage: devfile-index-base:latest + devfileIndexImage: devfile-index:latest + ociRegistryImage: quay.io/devfile/oci-registry:next + devfileIndexMemoryLimit: 256Mi + ociRegistryMemoryLimit: 256Mi diff --git a/.gitignore b/.gitignore index c88ead66..f8b92db9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .idea # Ignore the registry-viewer repo that we clone -registry-viewer \ No newline at end of file +registry-viewer +.odo \ No newline at end of file diff --git a/oci-registry/Dockerfile b/oci-registry/Dockerfile index d29d55e4..9a9b258d 100644 --- a/oci-registry/Dockerfile +++ b/oci-registry/Dockerfile @@ -22,6 +22,8 @@ RUN set -x ; \ adduser registry -u 1001 -G root && exit 0 COPY --from=registry --chown=registry:0 /bin/registry /bin/registry +# Copy default config +COPY --from=registry --chown=registry:0 /etc/docker/registry/config.yml /etc/docker/registry/config.yml USER 1001 EXPOSE 5000 ENTRYPOINT ["registry"] diff --git a/oci-registry/config.yml b/oci-registry/config.yml new file mode 100644 index 00000000..b2d3be44 --- /dev/null +++ b/oci-registry/config.yml @@ -0,0 +1,18 @@ +version: 0.1 +log: + fields: + service: registry +storage: + cache: + blobdescriptor: inmemory + filesystem: + rootdirectory: /var/lib/registry +http: + addr: :5000 + headers: + X-Content-Type-Options: [nosniff] + debug: + addr: :5001 + prometheus: + enabled: true + path: /metrics \ No newline at end of file From fa27e15c3ae8215f15a936aa8c9541235f4fbc28 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Thu, 14 Sep 2023 04:32:22 -0400 Subject: [PATCH 2/5] OCI registry builds with devfile build Signed-off-by: Michael Valdron --- .devfile.yaml | 15 ++++++++++++--- oci-registry/Dockerfile | 11 ++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.devfile.yaml b/.devfile.yaml index f8c79fa0..540ae57c 100644 --- a/.devfile.yaml +++ b/.devfile.yaml @@ -33,7 +33,8 @@ components: buildContext: . - name: oci-registry-builder image: - imageName: "{{ociRegistryImage}}" + imageName: quay.io/{{profile}}/{{ociRegistryImage}} + autoBuild: true dockerfile: uri: oci-registry/Dockerfile buildContext: oci-registry @@ -64,6 +65,8 @@ components: protocol: http targetPort: 8080 env: + - name: REGISTRY_NAME + value: "devfile-registry" - name: REGISTRY_HEADLESS value: "true" - name: oci-registry @@ -77,7 +80,7 @@ components: seccompProfile: type: "RuntimeDefault" container: - image: "{{ociRegistryImage}}" + image: quay.io/{{profile}}/{{ociRegistryImage}} memoryLimit: "{{ociRegistryMemoryLimit}}" command: - registry @@ -87,6 +90,11 @@ components: volumeMounts: - name: devfile-registry-storage path: /var/lib/registry + endpoints: + - exposure: internal + name: http-5000 + protocol: http + targetPort: 5000 commands: - id: build-devfile-index-base-image apply: @@ -100,6 +108,7 @@ commands: - id: build composite: commands: + - build-oci-registry - build-devfile-index-base-image - build-devfile-index-image group: @@ -132,6 +141,6 @@ variables: profile: devfile devfileIndexBaseImage: devfile-index-base:latest devfileIndexImage: devfile-index:latest - ociRegistryImage: quay.io/devfile/oci-registry:next + ociRegistryImage: oci-registry:latest devfileIndexMemoryLimit: 256Mi ociRegistryMemoryLimit: 256Mi diff --git a/oci-registry/Dockerfile b/oci-registry/Dockerfile index 9a9b258d..0660e8bd 100644 --- a/oci-registry/Dockerfile +++ b/oci-registry/Dockerfile @@ -15,15 +15,24 @@ FROM registry:2 as registry FROM registry.access.redhat.com/ubi8-minimal:8.2 + +# Install dependencies RUN microdnf update -y && rm -rf /var/cache/yum && microdnf install ca-certificates httpd-tools # Create a non-root user to run the server as RUN set -x ; \ adduser registry -u 1001 -G root && exit 0 +# Copy config file to myconfig.yml if specified +COPY ./config.yml /etc/docker/registry/myconfig.yml + COPY --from=registry --chown=registry:0 /bin/registry /bin/registry # Copy default config -COPY --from=registry --chown=registry:0 /etc/docker/registry/config.yml /etc/docker/registry/config.yml +COPY --from=registry --chown=registry:0 /etc/docker/registry/config.yml /etc/docker/registry/default.yml + +# Copy myconfig.yml, if exists, to config.yml +RUN if [ -f /etc/docker/registry/myconfig.yml ]; then cp /etc/docker/registry/myconfig.yml /etc/docker/registry/config.yml; else cp /etc/docker/registry/default.yml /etc/docker/registry/config.yml; fi + USER 1001 EXPOSE 5000 ENTRYPOINT ["registry"] From 1a0de3f89d79a991a4176bb1609671de0239e616 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Fri, 15 Dec 2023 23:33:19 -0500 Subject: [PATCH 3/5] odo ignores Signed-off-by: Michael Valdron --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f8b92db9..ad914506 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ # Ignore the registry-viewer repo that we clone registry-viewer -.odo \ No newline at end of file + +# Ignore odo files +.odo From 63da1970a6d4fd4ff4c58e1227de7699bc30dc43 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Fri, 15 Dec 2023 23:34:01 -0500 Subject: [PATCH 4/5] revise devfile with outerloop Signed-off-by: Michael Valdron --- .devfile.yaml | 166 ++++++++++++++++++----- deploy/devfile-resources/configmap.yaml | 42 ++++++ deploy/devfile-resources/deployment.yaml | 160 ++++++++++++++++++++++ deploy/devfile-resources/ingress.yaml | 35 +++++ deploy/devfile-resources/route.yaml | 29 ++++ deploy/devfile-resources/service.yaml | 37 +++++ 6 files changed, 437 insertions(+), 32 deletions(-) create mode 100644 deploy/devfile-resources/configmap.yaml create mode 100644 deploy/devfile-resources/deployment.yaml create mode 100644 deploy/devfile-resources/ingress.yaml create mode 100644 deploy/devfile-resources/route.yaml create mode 100644 deploy/devfile-resources/service.yaml diff --git a/.devfile.yaml b/.devfile.yaml index 540ae57c..427fcdd7 100644 --- a/.devfile.yaml +++ b/.devfile.yaml @@ -1,5 +1,5 @@ -# -# Copyright 2023 Red Hat, Inc. +# +# Copyright Red Hat # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,25 +15,40 @@ # schemaVersion: 2.2.0 metadata: - name: devfile-registry + name: registry-support + displayName: Devfile Registry Support + website: https://devfile.io + provider: Red Hat + supportUrl: https://kubernetes.slack.com/archives/C02SX9E5B55 + architectures: + - amd64 + tags: + - devfile + - registry + - http + - oci + - rest + icon: https://landscape.cncf.io/logos/devfile.svg + version: 0.0.1 + description: Workspace for developing the devfile registry support services components: - - name: devfile-index-base-builder + - name: index-base-builder image: - imageName: quay.io/{{profile}}/{{devfileIndexBaseImage}} + imageName: "{{indexBaseImageName}}:{{indexBaseImageTag}}" autoBuild: true dockerfile: uri: index/server/Dockerfile buildContext: index/server - name: devfile-index-image-builder image: - imageName: quay.io/{{profile}}/{{devfileIndexImage}} + imageName: "{{indexImageName}}:{{indexImageTag}}" autoBuild: true dockerfile: uri: .ci/Dockerfile buildContext: . - name: oci-registry-builder image: - imageName: quay.io/{{profile}}/{{ociRegistryImage}} + imageName: "{{ociImageName}}:{{ociImageTag}}" autoBuild: true dockerfile: uri: oci-registry/Dockerfile @@ -55,8 +70,8 @@ components: seccompProfile: type: "RuntimeDefault" container: - image: quay.io/{{profile}}/{{devfileIndexImage}} - memoryLimit: "{{devfileIndexMemoryLimit}}" + image: "{{indexImageName}}:{{indexImageTag}}" + memoryLimit: "{{indexMemoryLimit}}" command: - /entrypoint.sh endpoints: @@ -80,8 +95,8 @@ components: seccompProfile: type: "RuntimeDefault" container: - image: quay.io/{{profile}}/{{ociRegistryImage}} - memoryLimit: "{{ociRegistryMemoryLimit}}" + image: "{{ociImageName}}:{{ociImageTag}}" + memoryLimit: "{{ociMemoryLimit}}" command: - registry - serve @@ -95,33 +110,45 @@ components: name: http-5000 protocol: http targetPort: 5000 +# Devfile Registry Deployment resource + - name: devfile-registry-deployment + kubernetes: + uri: deploy/devfile-resources/deployment.yaml +# Devfile Registry Service resource + - name: devfile-registry-service + kubernetes: + uri: deploy/devfile-resources/service.yaml +# Devfile Registry ConfigMap resource + - name: devfile-registry-configmap + kubernetes: + uri: deploy/devfile-resources/configmap.yaml +# Devfile Registry Ingress (k8s) resource + - name: devfile-registry-ingress + kubernetes: + uri: deploy/devfile-resources/ingress.yaml +# Devfile Registry Route (Red Hat OpenShift) resource + - name: devfile-registry-route + openshift: + uri: deploy/devfile-resources/route.yaml commands: - - id: build-devfile-index-base-image + - id: build-index-base-image apply: - component: devfile-index-base-builder - - id: build-devfile-index-image + component: index-base-builder + - id: build-index-image apply: component: devfile-index-image-builder - - id: build-oci-registry + - id: build-oci-image apply: component: oci-registry-builder - id: build composite: commands: - - build-oci-registry - - build-devfile-index-base-image - - build-devfile-index-image + - build-oci-image + - build-index-base-image + - build-index-image group: isDefault: true kind: build - - id: build-all - composite: - commands: - - build-oci-registry - - build-devfile-index-base-image - - build-devfile-index-image - group: - kind: build - id: run-devfile-index apply: component: devfile-registry @@ -137,10 +164,85 @@ commands: group: isDefault: true kind: run +# Apply Deployment spec + - id: apply-deployment + apply: + component: devfile-registry-deployment +# Apply Service spec + - id: apply-service + apply: + component: devfile-registry-service +# Apply ConfigMap spec + - id: apply-configmap + apply: + component: devfile-registry-configmap +# Apply Ingress spec + - id: apply-ingress + apply: + component: devfile-registry-ingress +# Apply Route spec + - id: apply-route + apply: + component: devfile-registry-route +# Build & deploy Devfile Registry to Kubernetes + - id: build-deploy-registry-k8s + composite: + commands: + - apply-deployment + - apply-service + - apply-configmap + - apply-ingress + group: + isDefault: true + kind: deploy +# Build & deploy Devfile Registry to Red Hat OpenShift + - id: build-deploy-registry-openshift + composite: + commands: + - apply-deployment + - apply-service + - apply-configmap + - apply-route + group: + kind: deploy variables: - profile: devfile - devfileIndexBaseImage: devfile-index-base:latest - devfileIndexImage: devfile-index:latest - ociRegistryImage: oci-registry:latest - devfileIndexMemoryLimit: 256Mi - ociRegistryMemoryLimit: 256Mi +# The number of replicas for the hosted devfile registry service + replicas: "1" +# Devfile registry index base docker image, contains support services such as REST API & proxy server. Defaults to quay.io/devfile/devfile-index + indexBaseImageName: localhost/devfile-index-base +# Devfile registry index base version which defaults to latest + indexBaseImageTag: latest +# Devfile registry index docker image. Defaults to quay.io/devfile/devfile-index + indexImageName: localhost/devfile-index +# Devfile registry version which defaults to latest + indexImageTag: latest +# Never pull index image by default. + indexPullPolicy: Never +# Maximum amount of memory the devfile registry index container can use. Defaults 256Mi + indexMemoryLimit: 256Mi +# Devfile registry viewer docker image. Defaults to quay.io/devfile/registry-viewer + viewerImageName: quay.io/devfile/registry-viewer +# Devfile registry viewer version which defaults to next + viewerImageTag: next +# Always pull registry viewer image by default. + viewerPullPolicy: Always +# Maximum amount of memory the registry viewer container can use. Defaults 256Mi + viewerMemoryLimit: 256Mi +# OCI registry index docker image. Defaults to quay.io/devfile/devfile-index + ociImageName: localhost/oci-registry +# OCI registry version which defaults to latest + ociImageTag: latest +# Never pull oci registry image by default. + ociPullPolicy: Never +# Maximum amount of memory the OCI registry container can use. Defaults 256Mi + ociMemoryLimit: 256Mi +# The registry name that is used as identifier for devfile telemetry + registryName: test-registry +# The public write key to send registry analytics to segment.io + telemetryKey: "" +# The public write key to send viewer analytics to segment.io + analyticsWriteKey: "" +# The hostname alias to pass in to the devfile registry viewer's config + hostAlias: https://registry.stage.devfile.io +# Hostname for the devfile registry service. Defaults to cluster's router. + hostName: "" diff --git a/deploy/devfile-resources/configmap.yaml b/deploy/devfile-resources/configmap.yaml new file mode 100644 index 00000000..4cfe84e5 --- /dev/null +++ b/deploy/devfile-resources/configmap.yaml @@ -0,0 +1,42 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: v1 +kind: ConfigMap +metadata: + name: devfile-registry +data: + registry-config.yml: | + version: 0.1 + log: + fields: + service: registry + storage: + cache: + blobdescriptor: inmemory + filesystem: + rootdirectory: /var/lib/registry + http: + addr: :5000 + headers: + X-Content-Type-Options: [nosniff] + debug: + addr: :5001 + prometheus: + enabled: true + path: /metrics + .env.registry-viewer: | + NEXT_PUBLIC_ANALYTICS_WRITE_KEY={{analyticsWriteKey}} + DEVFILE_REGISTRIES=[{"name":"Community","url":"http://localhost:8080","fqdn":"{{hostAlias}}"}] diff --git a/deploy/devfile-resources/deployment.yaml b/deploy/devfile-resources/deployment.yaml new file mode 100644 index 00000000..5cd42927 --- /dev/null +++ b/deploy/devfile-resources/deployment.yaml @@ -0,0 +1,160 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: devfile-registry + name: devfile-registry +spec: + replicas: {{replicas}} + selector: + matchLabels: + app: devfile-registry + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + template: + metadata: + labels: + app: devfile-registry + spec: + volumes: + - name: devfile-registry-storage + emptyDir: {} + - name: config + configMap: + name: devfile-registry + items: + - key: registry-config.yml + path: config.yml + - name: viewer-env-file + configMap: + name: devfile-registry + items: + - key: .env.registry-viewer + path: .env.production + containers: + - image: "{{indexImageName}}:{{indexImageTag}}" + imagePullPolicy: "{{indexPullPolicy}}" + name: devfile-registry + ports: + - containerPort: 8080 + livenessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 3 + readinessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 3 + startupProbe: + httpGet: + path: /viewer + port: 3000 + scheme: HTTP + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 20 + resources: + requests: + cpu: 100m + memory: 64Mi + limits: + cpu: 250m + memory: "{{indexMemoryLimit}}" + env: + - name: REGISTRY_NAME + value: "{{registryName}}" + - name: TELEMETRY_KEY + value: "{{telemetryKey}}" + - image: "{{viewerImageName}}:{{viewerImageTag}}" + imagePullPolicy: "{{viewerPullPolicy}}" + name: devfile-registry-viewer + livenessProbe: + httpGet: + path: /viewer + port: 3000 + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 20 + readinessProbe: + httpGet: + path: /viewer + port: 3000 + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 10 + timeoutSeconds: 20 + resources: + requests: + cpu: 100m + memory: 64Mi + limits: + cpu: 250m + memory: "{{viewerMemoryLimit}}" + env: + - name: NEXT_PUBLIC_ANALYTICS_WRITE_KEY + value: "{{analyticsWriteKey}}" + - name: DEVFILE_REGISTRIES + value: |- + [{"name":"Community","url":"http://localhost:8080","fqdn":"{{hostAlias}}"}] + volumeMounts: + - name: viewer-env-file + mountPath: /app/.env.production + subPath: .env.production + readOnly: true + - image: "{{ociImageName}}:{{ociImageTag}}" + imagePullPolicy: "{{ociPullPolicy}}" + name: oci-registry + livenessProbe: + httpGet: + path: /v2 + port: 5000 + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 3 + readinessProbe: + httpGet: + path: /v2 + port: 5000 + initialDelaySeconds: 3 + periodSeconds: 10 + timeoutSeconds: 3 + resources: + requests: + cpu: 1m + memory: 5Mi + limits: + cpu: 100m + memory: "{{ociMemoryLimit}}" + volumeMounts: + - name: devfile-registry-storage + mountPath: "/var/lib/registry" + - name: config + mountPath: "/etc/docker/registry" + readOnly: true diff --git a/deploy/devfile-resources/ingress.yaml b/deploy/devfile-resources/ingress.yaml new file mode 100644 index 00000000..1aa28280 --- /dev/null +++ b/deploy/devfile-resources/ingress.yaml @@ -0,0 +1,35 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: devfile-registry + labels: + name: devfile-registry + annotations: + kubernetes.io/ingress.class: nginx +spec: + rules: + - host: "{{hostName}}" + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: devfile-registry + port: + number: 8080 diff --git a/deploy/devfile-resources/route.yaml b/deploy/devfile-resources/route.yaml new file mode 100644 index 00000000..fd82b6c3 --- /dev/null +++ b/deploy/devfile-resources/route.yaml @@ -0,0 +1,29 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + labels: + app: devfile-registry + name: devfile-registry +spec: + host: "{{hostName}}" + to: + kind: Service + name: devfile-registry + weight: 100 + port: + targetPort: 8080 diff --git a/deploy/devfile-resources/service.yaml b/deploy/devfile-resources/service.yaml new file mode 100644 index 00000000..0d214a07 --- /dev/null +++ b/deploy/devfile-resources/service.yaml @@ -0,0 +1,37 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +apiVersion: v1 +kind: Service +metadata: + name: devfile-registry + labels: + app: devfile-registry +spec: + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8080 + - name: oci-metrics + protocol: TCP + port: 5001 + targetPort: 5001 + - name: index-metrics + protocol: TCP + port: 7071 + targetPort: 7071 + selector: + app: devfile-registry From aad3c73ee72a38743aed05f1f2777b23c36eeff9 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Fri, 15 Dec 2023 23:36:07 -0500 Subject: [PATCH 5/5] Devfile CI Signed-off-by: Michael Valdron --- .ci/odov3_build_and_deploy.sh | 109 ++++++++++++++++++++++++++++++ .github/workflows/devfile-ci.yaml | 71 +++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 .ci/odov3_build_and_deploy.sh create mode 100644 .github/workflows/devfile-ci.yaml diff --git a/.ci/odov3_build_and_deploy.sh b/.ci/odov3_build_and_deploy.sh new file mode 100644 index 00000000..9c696a6d --- /dev/null +++ b/.ci/odov3_build_and_deploy.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Share docker env with minikube +eval $(minikube docker-env) + +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail +# error on unset variables +set -u +# print each command before executing it +set -x + +# Disable telemtry for odo +export ODO_DISABLE_TELEMETRY=true + +# Disable image pushing for odo by default +export ODO_PUSH_IMAGES=${ODO_PUSH_IMAGES:-'false'} + +# Split the registry image and image tag from the REGISTRY_IMAGE env variable +IMG="$(echo $REGISTRY_IMAGE | cut -d':' -f1)" +TAG="$(echo $REGISTRY_IMAGE | cut -d':' -f2)" + +# Split the registry base image and image tag from the REGISTRY_BASE_IMAGE env variable +REGISTRY_BASE_IMAGE=${REGISTRY_BASE_IMAGE:-'localhost/devfile-index-base:latest'} +BASE_IMG="$(echo $REGISTRY_BASE_IMAGE | cut -d':' -f1)" +BASE_TAG="$(echo $REGISTRY_BASE_IMAGE | cut -d':' -f2)" + +# Split the oci registry image and image tag from the OCI_IMAGE env variable +OCI_IMG="$(echo $OCI_IMAGE | cut -d':' -f1)" +OCI_TAG="$(echo $OCI_IMAGE | cut -d':' -f2)" + +# Set namespace +NAMESPACE=${NAMESPACE:-'devfile-registry-test'} +# Set pull policy of REGISTRY_IMAGE +PULL_POLICY=${PULL_POLICY:-'Always'} + +# Fail if odo is not installed +if [ -z $(command -v odo 2> /dev/null) ]; then + echo "install odo." + exit 1 +fi + +# Create testing namespace if does not exist, otherwise set to testing namespace +if [ -z $(kubectl describe namespace/${NAMESPACE} 2> /dev/null) ]; then + odo create namespace ${NAMESPACE} +else + odo set namespace ${NAMESPACE} +fi + +# Wait for ingress to be ready +kubectl wait pods -l app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/component=controller --namespace ingress-nginx --for=condition=Ready --timeout=600s + +# Deploy devfile registry using odo v3 +odo deploy --var hostName=${NAMESPACE}.$(minikube ip).nip.io \ + --var hostAlias=${NAMESPACE}.$(minikube ip).nip.io \ + --var indexBaseImageName=${BASE_IMG} \ + --var indexBaseImageTag=${BASE_TAG} \ + --var indexImageName=${IMG} \ + --var indexImageTag=${TAG} \ + --var indexPullPolicy=${PULL_POLICY} \ + --var ociImageName=${OCI_IMG} \ + --var ociImageTag=${OCI_TAG} \ + --var ociPullPolicy=${PULL_POLICY} + +# Wait for deployment to be ready +kubectl wait deploy/devfile-registry --for=condition=Available --timeout=600s +if [ $? -ne 0 ]; then + # Return the logs of the 3 containers in case the condition is not met + echo "devfile-registry container logs:" + kubectl logs -l app=devfile-registry --container devfile-registry + echo "oci-registry container logs:" + kubectl logs -l app=devfile-registry --container oci-registry + echo "registry-viewer container logs:" + kubectl logs -l app=devfile-registry --container registry-viewer + # Return the description of every pod + kubectl describe pods + + odo delete component --name registry-support --force + + exit 1 +fi + +# Get status code, retry for 5 times until status code is 200 otherwise fail +STATUS_CODE=$(curl --fail --retry 5 -o /dev/null -s -w "%{http_code}\n" "http://${NAMESPACE}.$(minikube ip).nip.io/health") +if [ ${STATUS_CODE} -ne 200 ]; then + echo "unexpected status code ${STATUS_CODE}, was expecting 200" + + odo delete component --name registry-support --force + + exit 1 +else + odo delete component --name registry-support --force +fi diff --git a/.github/workflows/devfile-ci.yaml b/.github/workflows/devfile-ci.yaml new file mode 100644 index 00000000..462a8cbb --- /dev/null +++ b/.github/workflows/devfile-ci.yaml @@ -0,0 +1,71 @@ +# +# Copyright Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Devfile + +on: + pull_request: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} + cancel-in-progress: true + +env: + ODOV3_VERSION: "3.15.0" + OCI_IMAGE: localhost/oci-registry:${{ github.sha }} + REGISTRY_IMAGE: localhost/devfile-index:${{ github.sha }} + PULL_POLICY: 'Never' # Use local built image with registry changes + PODMAN_CMD: "" # Forces odo to use docker + ODO_DISABLE_TELEMETRY: true + ODO_PUSH_IMAGES: false + +jobs: + odov3-build-images: + name: Check building registry-support images with odo v3 + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - name: Install odo v3 + uses: redhat-actions/openshift-tools-installer@2de9a80cf012ad0601021515481d433b91ef8fd5 # v1 + with: + odo: ${{ env.ODOV3_VERSION }} + - name: Check odo version + run: odo version + - name: Check if odo v3 builds registry-support images + run: odo build-images + odov3-build-deploy: + name: Check devfile registry (test registry) odo v3 outerloop build & deploy + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - name: Install odo v3 + uses: redhat-actions/openshift-tools-installer@2de9a80cf012ad0601021515481d433b91ef8fd5 # v1 + with: + odo: ${{ env.ODOV3_VERSION }} + - name: Setup Minikube + uses: manusa/actions-setup-minikube@3856c6fa039819f1c8e7e248b1fc5a8564e354c9 # v2.9.0 + with: + minikube version: 'v1.31.2' + kubernetes version: 'v1.26.3' + driver: 'docker' + github token: ${{ secrets.GITHUB_TOKEN }} + start args: '--addons ingress --memory 4096 --cpus 2' + - name: Check odo version + run: odo version + - name: Check if devfile registry odo v3 build & deploy is working + run: bash .ci/odov3_build_and_deploy.sh