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

WIP: [Devtools Week] Create registry-support devfile workspace #195

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
109 changes: 109 additions & 0 deletions .ci/odov3_build_and_deploy.sh
Original file line number Diff line number Diff line change
@@ -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
248 changes: 248 additions & 0 deletions .devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#
# 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.
#
schemaVersion: 2.2.0
metadata:
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: index-base-builder
image:
imageName: "{{indexBaseImageName}}:{{indexBaseImageTag}}"
autoBuild: true
dockerfile:
uri: index/server/Dockerfile
buildContext: index/server
- name: devfile-index-image-builder
image:
imageName: "{{indexImageName}}:{{indexImageTag}}"
autoBuild: true
dockerfile:
uri: .ci/Dockerfile
buildContext: .
- name: oci-registry-builder
image:
imageName: "{{ociImageName}}:{{ociImageTag}}"
autoBuild: true
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: "{{indexImageName}}:{{indexImageTag}}"
memoryLimit: "{{indexMemoryLimit}}"
command:
- /entrypoint.sh
endpoints:
- exposure: public
name: http-8080
protocol: http
targetPort: 8080
env:
- name: REGISTRY_NAME
value: "devfile-registry"
- name: REGISTRY_HEADLESS
value: "true"
- name: oci-registry
attributes:
container-overrides:
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: "RuntimeDefault"
container:
image: "{{ociImageName}}:{{ociImageTag}}"
memoryLimit: "{{ociMemoryLimit}}"
command:
- registry
- serve
- /etc/docker/registry/config.yml
mountSources: false
volumeMounts:
- name: devfile-registry-storage
path: /var/lib/registry
endpoints:
- exposure: internal
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-index-base-image
apply:
component: index-base-builder
- id: build-index-image
apply:
component: devfile-index-image-builder
- id: build-oci-image
apply:
component: oci-registry-builder
- id: build
composite:
commands:
- build-oci-image
- build-index-base-image
- build-index-image
group:
isDefault: true
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
# 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:
# 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: ""
Loading
Loading