diff --git a/.devfile.yaml b/.devfile.yaml index 949e4314..a1bfeb5b 100644 --- a/.devfile.yaml +++ b/.devfile.yaml @@ -216,3 +216,10 @@ commands: kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "ovsx create-namespace '$EXTENSION_NAMESPACE_NAME'" || true && kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "ovsx publish /tmp/extension.vsix" && kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "rm /tmp/extension.vsix" + + - id: publish-extensions + exec: + label: "2.7. Publish list of VS Code Extensions" + component: tool + workingDir: ${PROJECTS_ROOT}/openvsx/openshift + commandLine: ./scripts/publish_extensions.sh diff --git a/openshift/README.md b/openshift/README.md index 081a37c1..fe9277af 100644 --- a/openshift/README.md +++ b/openshift/README.md @@ -33,6 +33,10 @@ In case you have deployed Eclipse Che on the cluster, you can patch it to use yo This command facilitates publishing a VS Code extension to the local OpenVSX registry. It prompts the user to provide the extension's namespace name and download URL. The extension is then downloaded into a temporary folder inside the ovsx-cli pod, a namespace is created (if not already present), and the extension is published to the OpenVSX registry. Afterward, the temporary file is deleted. This command is ideal for adding custom or internal extensions to a local OpenVSX instance. +* 2.7. Publish list of VS Code Extensions + +This command facilitates publishing a list of VS Code extensions to a local OpenVSX registry based on URLs specified in the `extensions.txt` file. For each extension listed, it downloads the `.vsix` file into a temporary directory on the ovsx-cli pod, creates a namespace if it doesn’t already exist, and publishes the extension to the OpenVSX registry. After each extension is published, the temporary file is deleted from the pod. This command is ideal for managing multiple extensions by automating the download, namespace creation, and publishing steps, making it easy to maintain a custom set of extensions in a local OpenVSX instance. + ## OpenShift Template (openvsx-deployment.yml) You can find the deployment YAML configuration in the `openvsx-deployment.yml` file. This template defines the deployments, services, and route for the PostgreSQL database, Elasticsearch, OpenVSX Server, and OpenVSX CLI. diff --git a/openshift/extensions.txt b/openshift/extensions.txt new file mode 100644 index 00000000..6f79de74 --- /dev/null +++ b/openshift/extensions.txt @@ -0,0 +1,12 @@ +https://open-vsx.org/api/redhat/vscode-xml/0.27.1/file/redhat.vscode-xml-0.27.1.vsix +https://open-vsx.org/api/redhat/vscode-yaml/1.15.0/file/redhat.vscode-yaml-1.15.0.vsix +https://open-vsx.org/api/redhat/java/1.35.1/file/redhat.java-1.35.1.vsix +https://open-vsx.org/api/vscode/html-language-features/1.88.1/file/vscode.html-language-features-1.88.1.vsix +https://open-vsx.org/api/redhat/vscode-quarkus/1.18.1/file/redhat.vscode-quarkus-1.18.1.vsix +https://open-vsx.org/api/redhat/fabric8-analytics/0.9.5/file/redhat.fabric8-analytics-0.9.5.vsix +https://open-vsx.org/api/redhat/vscode-redhat-account/0.2.0/file/redhat.vscode-redhat-account-0.2.0.vsix +https://open-vsx.org/api/redhat/vscode-openshift-connector/linux-x64/1.16.0/file/redhat.vscode-openshift-connector-1.16.0@linux-x64.vsix +https://open-vsx.org/api/redhat/vscode-commons/0.0.6/file/redhat.vscode-commons-0.0.6.vsix +https://open-vsx.org/api/redhat/vscode-tekton-pipelines/1.0.1/file/redhat.vscode-tekton-pipelines-1.0.1.vsix +https://open-vsx.org/api/ms-python/python/2024.14.1/file/ms-python.python-2024.14.1.vsix +https://open-vsx.org/api/redhat/ansible/24.8.4/file/redhat.ansible-24.8.4.vsix diff --git a/openshift/scripts/publish_extensions.sh b/openshift/scripts/publish_extensions.sh new file mode 100755 index 00000000..4ccb144d --- /dev/null +++ b/openshift/scripts/publish_extensions.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# This script automates the process of downloading, configuring, and publishing VS Code extensions to an OpenVSX registry +# deployed on an OpenShift cluster. + +# Path to the extensions.txt file +current_dir=$(pwd) +EXTENSIONS_FILE="$current_dir/extensions.txt" + +listOfPublishers=() +containsElement () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; } + +# Get ovsx-cli pod name +export OVSX_POD_NAME=$(kubectl get pods -n "$OPENVSX_NAMESPACE" -o jsonpath="{.items[*].metadata.name}" | tr ' ' '\n' | grep ^ovsx-cli) + +# Read the extensions.txt file line by line +while IFS= read -r line; do + # Extract the vsix file name from the URL + vsix_url="$line" + vsix_filename=$(basename "$vsix_url") + + # Download the vsix file into the /tmp directory + echo "Downloading $vsix_url" + kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "wget -q -P /tmp '$vsix_url' " + + # Extract namespace_name (everything before the first .) + namespace_name=$(echo "$vsix_filename" | cut -d. -f1) + + # Execute ovsx commands + # check if publisher is in the list of publishers + if ! containsElement "${namespace_name}" "${listOfPublishers[@]}"; then + listOfPublishers+=("${namespace_name}") + # create namespace + kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "ovsx create-namespace '$namespace_name'" || true + fi + # publish extension + kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "ovsx publish /tmp/'$vsix_filename'" + + # remove the downloaded file + kubectl exec -n "${OPENVSX_NAMESPACE}" "${OVSX_POD_NAME}" -- bash -c "rm /tmp/'$vsix_filename'" +done < "$EXTENSIONS_FILE"