Skip to content
Open
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
60 changes: 60 additions & 0 deletions plugins/helm/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import json
import os

from spaceforge import SpaceforgePlugin, Parameter, Variable, Context, Policy, Binary


class HelmPlugin(SpaceforgePlugin):
"""
# Plugin Helm

This plugin integrates Helm into Spacelift, allowing users to manage Kubernetes applications using Helm charts.

## Usage

1. Spin up the plugin
2. Add the autoattach label to any kubernetes stack that you intened to use helm with
3. Configure the following environment variables in your stack:
- `REPO_NAME`: The name of the Helm repository to add.
- `REPO_URL`: The URL of the Helm repository to add.
- `RELEASE_NAME`: The name of the Helm release.
- `PATH_TO_CHART`: The path to the Helm chart.
- `HELM_VALUES`: The path to the values file for the Helm chart.
"""

# Plugin metadata
__plugin_name__ = "Helm"
__labels__ = ["helm", "kubernetes"]
__version__ = "1.0.0"
__author__ = "Spacelift Team"

__binaries__ = [
Binary(
name="helm",
download_urls={
"amd64": "https://binhub.dev/h/helm/3.18.6/linux-amd64/helm",
"arm64": "https://binhub.dev//h/helm/3.18.6/linux-arm64/helm"
}
)
]

# Plugin contexts
__contexts__ = [
Context(
priority=1,
name_prefix="helm",
description="helm plugin that allows you to use helm charts in your kubernetes spacelift stacks",
hooks={
"before_init": [
'export PATH="/mnt/workspace/plugins/plugin_binaries:$PATH"',
'helm repo add $REPO_NAME $REPO_URL',
'helm template $RELEASE_NAME $PATH_TO_CHART --values $HELM_VALUES > deployment.yaml',
'rm $HELM_VALUES'
]
}
)
]

def __init__(self):
super().__init__()
self.logger.info("Initializing Helm Plugin")
161 changes: 161 additions & 0 deletions plugins/helm/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Helm
version: 1.0.0
description: |-
# Plugin Helm

This plugin integrates Helm into Spacelift, allowing users to manage Kubernetes applications using Helm charts.

## Usage

1. Spin up the plugin
2. Add the autoattach label to any kubernetes stack that you intened to use helm with
3. Configure the following environment variables in your stack:
- `REPO_NAME`: The name of the Helm repository to add.
- `REPO_URL`: The URL of the Helm repository to add.
- `RELEASE_NAME`: The name of the Helm release.
- `PATH_TO_CHART`: The path to the Helm chart.
- `HELM_VALUES`: The path to the values file for the Helm chart.
author: Spacelift Team
labels:
- helm
- kubernetes
contexts:
- name_prefix: ZZZZZ-helm
description: Main context for Helm
env: []
mounted_files:
- path: /mnt/workspace/plugins/helm/plugin.py
content: |-
import json
import os

from spaceforge import SpaceforgePlugin, Parameter, Variable, Context, Policy, Binary


class HelmPlugin(SpaceforgePlugin):
"""
# Plugin Helm

This plugin integrates Helm into Spacelift, allowing users to manage Kubernetes applications using Helm charts.

## Usage

1. Spin up the plugin
2. Add the autoattach label to any kubernetes stack that you intened to use helm with
3. Configure the following environment variables in your stack:
- `REPO_NAME`: The name of the Helm repository to add.
- `REPO_URL`: The URL of the Helm repository to add.
- `RELEASE_NAME`: The name of the Helm release.
- `PATH_TO_CHART`: The path to the Helm chart.
- `HELM_VALUES`: The path to the values file for the Helm chart.
"""

# Plugin metadata
__plugin_name__ = "Helm"
__labels__ = ["helm", "kubernetes"]
__version__ = "1.0.0"
__author__ = "Spacelift Team"

__binaries__ = [
Binary(
name="helm",
download_urls={
"amd64": "https://binhub.dev/h/helm/3.18.6/linux-amd64/helm",
"arm64": "https://binhub.dev//h/helm/3.18.6/linux-arm64/helm"
}
)
]

# Plugin contexts
__contexts__ = [
Context(
priority=1,
name_prefix="helm",
description="helm plugin that allows you to use helm charts in your kubernetes spacelift stacks",
hooks={
"before_init": [
'export PATH="/mnt/workspace/plugins/plugin_binaries:$PATH"',
'helm repo add $REPO_NAME $REPO_URL',
'helm template $RELEASE_NAME $PATH_TO_CHART --values $HELM_VALUES > deployment.yaml',
'rm $HELM_VALUES'
]
}
)
]

def __init__(self):
super().__init__()
self.logger.info("Initializing Helm Plugin")
sensitive: false
- path: /mnt/workspace/plugins/helm/binary_install_helm.sh
content: |-
#!/bin/sh

set -e

export PATH="/mnt/workspace/plugins/plugin_binaries:$PATH"
if command -v helm; then
echo "helm is already installed."
return
fi

echo "Installing helm..."
mkdir -p /mnt/workspace/plugins/plugin_binaries

ARCH="$(arch)"
if [ "$ARCH" = "x86_64" ]; then
URL="https://binhub.dev/h/helm/3.18.6/linux-amd64/helm"
elif [ "$ARCH" = "arm64" ]; then
URL="https://binhub.dev//h/helm/3.18.6/linux-arm64/helm"
else
echo "Error: Unsupported architecture '$ARCH'"
exit 1
fi

case "$URL" in
*.tar.gz|*.tar.bz2|*.zip)
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT

ARCHIVE="$TMP_DIR/archive"
curl "$URL" -o "$ARCHIVE" -fL

case "$URL" in
*.tar.gz)
tar -xzf "$ARCHIVE" -C "$TMP_DIR" || { echo "Error: Failed to extract archive"; exit 1; }
;;
*.tar.bz2)
tar -xjf "$ARCHIVE" -C "$TMP_DIR" || { echo "Error: Failed to extract archive"; exit 1; }
;;
*.zip)
unzip -o "$ARCHIVE" -d "$TMP_DIR" || { echo "Error: Failed to extract archive"; exit 1; }
;;
esac

FOUND_BINARY=$(find "$TMP_DIR" -type f -name "helm" | head -n 1)
if [ -z "$FOUND_BINARY" ]; then
echo "Error: Could not find binary 'helm' in extracted archive"
exit 1
fi

mv "$FOUND_BINARY" "/mnt/workspace/plugins/plugin_binaries/helm"
;;
*)
curl "$URL" -o "/mnt/workspace/plugins/plugin_binaries/helm" -fL
;;
esac

chmod +x "/mnt/workspace/plugins/plugin_binaries/helm"
sensitive: false
hooks:
before_init:
- mkdir -p /mnt/workspace/plugins/helm
- chmod +x /mnt/workspace/plugins/helm/binary_install_helm.sh && /mnt/workspace/plugins/helm/binary_install_helm.sh
- name_prefix: YYYYY-helm
description: helm plugin that allows you to use helm charts in your kubernetes spacelift stacks
hooks:
before_init:
- export PATH="/mnt/workspace/plugins/plugin_binaries:$PATH"
- helm repo add $REPO_NAME $REPO_URL
- helm template $RELEASE_NAME $PATH_TO_CHART --values $HELM_VALUES > deployment.yaml
- rm $HELM_VALUES