Skip to content

Commit

Permalink
add a command to publish list of extensions into OpenVSX registry dep…
Browse files Browse the repository at this point in the history
…loyed on OpenShift

Signed-off-by: Valeriy Svydenko <[email protected]>
  • Loading branch information
svor committed Nov 13, 2024
1 parent e85204b commit 74d0188
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions openshift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 12 additions & 0 deletions openshift/extensions.txt
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
40 changes: 40 additions & 0 deletions openshift/scripts/publish_extensions.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 74d0188

Please sign in to comment.