So it's been a few months since my last post - during that time, there have been six Che 7.x releases, and Red Hat CodeReady Workspaces 2.0 was released!
Continuing my series about Che (& Che accessories), here's how to inject new content into a running registry pod, without having to build a custom registry container. Why would you want this?
Say you've got a great idea for a devfile or plugin and just want to test it out, but don't want to deal with building & releasing container(s). This technique lets you just update the running pod with your new content.
NOTE: content won't persist if you roll out a new deployment, so don't do this in production. For that you'll want a custom container image.
Want to learn more about devfiles? Read this.
NOTE: content won't persist if you roll out a new deployment, so don't do this in production. For that you'll want a custom container image.
Want to learn more about devfiles? Read this.
Adding a devfile at runtime
Procedure
To add a devfile:
- Check out the devfile registry sources.
git clone https://github.com/redhat-developer/codeready-workspaces/; \ cd codeready-workspaces/dependencies/che-devfile-registry # or for Che 7 git clone https://github.com/eclipse/che-devfile-registry; \ cd che-devfile-registry
- Create a
devfile.yaml
andmeta.yaml
in some local folder. This can be done from scratch or by copying from an existing devfile.STACK="new-stack"; \ mkdir -p devfiles/${STACK}; cp devfiles/nodejs/* devfiles/${STACK}/
- If copying from an existing devfile, make changes to the devfile to suit your needs. Make sure your new devfile has a unique
displayName
anddescription
. - Get the name of the pod that hosts the devfile registry container. To do this, filter the
component=devfile-registry
label. Note: for Che 7, use kubectl instead of oc.DEVFILE_REG_POD=$(oc get -o custom-columns=NAME:.metadata.name \ --no-headers pod -l component=devfile-registry)
- Regenerate the registry’s
index.json
file to include your new devfile.cd .../che-devfile-registry; \ "$(pwd)/build/scripts/check_mandatory_fields.sh" devfiles; \ "$(pwd)/build/scripts/index.sh" > index.json
- Copy the new
index.json
,devfile.yaml
andmeta.yaml
files from your new local devfile folder to the container.cd .../che-devfile-registry; \ LOCAL_FILES="$(pwd)/${STACK}/meta.yaml $(pwd)/${STACK}/devfile.yaml $(pwd)/index.json"; \ oc exec ${DEVFILE_REG_POD} -i -t -- mkdir -p /var/www/html/devfiles/${STACK}; \ for f in $LOCAL_FILES; do e=${f/$(pwd)\//}; echo "Upload ${f} -> /var/www/html/devfiles/${e}" oc cp "${f}" ${DEVFILE_REG_POD}:/var/www/html/devfiles/${e}; done
- If you have administrative rights on the cluster, you can browse to the running pod and log into it to check your changes have actually happened:
- The new devfile can now be used from the existing Che instance’s devfile registry. To discover it, go to the Che dashboard, then click the
Workspaces
link. From there, clickAdd Workspace
to see the updated list of available devfiles.
Adding a plug-in at runtime
Procedure
To add a plug-in:
- Check out the plugin registry sources.
git clone https://github.com/redhat-developer/codeready-workspaces/; \ cd codeready-workspaces/dependencies/che-plugin-registry # or for Che 7 git clone https://github.com/eclipse/che-plugin-registry; \ cd che-plugin-registry
- Create a
meta.yaml
in some local folder. This can be done from scratch or by copying from an existing plug-in’smeta.yaml
file.PLUGIN="v3/plugins/new-org/new-plugin/0.0.1"; \ mkdir -p ${PLUGIN}; cp v3/plugins/che-incubator/cpptools/0.1/* ${PLUGIN}/ echo "${PLUGIN##*/}" > ${PLUGIN}/../latest.txt
- If copying from an existing plug-in, make changes to the
meta.yaml
file to suit your needs. Make sure your new plug-in has a uniquetitle
,displayName
anddescription
. Update thefirstPublicationDate
to today’s date. - These fields in
meta.yaml
must match the path defined inPLUGIN
above.publisher: new-org name: new-plugin version: 0.0.1
- Get the name of the pod that hosts the plug-in registry container. To do this, filter the
component=plugin-registry
label.Note: for Che 7, use kubectl instead of oc.PLUGIN_REG_POD=$(oc get -o custom-columns=NAME:.metadata.name \ --no-headers pod -l component=plugin-registry)
- Regenerate the registry’s
index.json
file to include your new plug-in.cd .../che-plugin-registry; \ "$(pwd)/build/scripts/generate_latest_metas.sh" v3 && \ "$(pwd)/build/scripts/check_plugins_location.sh" v3 && \ "$(pwd)/build/scripts/set_plugin_dates.sh" v3 && \ "$(pwd)/build/scripts/check_plugins_viewer_mandatory_fields.sh" v3 && \ "$(pwd)/build/scripts/index.sh" v3 > v3/plugins/index.json
- Copy the new
index.json
andmeta.yaml
files from your new local plug-in folder to the container.cd .../che-plugin-registry; \ LOCAL_FILES="$(pwd)/${PLUGIN}/meta.yaml $(pwd)/v3/plugins/index.json"; \ oc exec ${PLUGIN_REG_POD} -i -t -- mkdir -p /var/www/html/${PLUGIN}; \ for f in $LOCAL_FILES; do e=${f/$(pwd)\//}; echo "Upload ${f} -> /var/www/html/${e}"; \ oc cp "${f}" ${PLUGIN_REG_POD}:/var/www/html/${e}; done
- If you have administrative rights on the cluster, you can browse to the running pod and log into it to check your changes have actually happened:
- The new plug-in can now be used from the existing Che instance’s plug-in registry. To discover it, go to the Che dashboard, then click the
Workspaces
link. From there, click the gear icon to configure one of your workspaces. Select thePlugins
tab to see the updated list of available plug-ins.
Note: much of this content is derived from my contribution to https://www.eclipse.org/che/docs/che-7/editing-a-devfile-and-plug-in-at-runtime/ ... so it's not plagiarism, it's reuse of open source content. ;)
See anything wrong? Want to contribute? We're always on the lookout for people to improve or contribute to the Che 7 and the CodeReady Workspaces docs.
0 comments:
Post a Comment