Skip to content

Commit 2d36cc2

Browse files
committed
build: helm chart build commands & successful build
1 parent 70f2ef2 commit 2d36cc2

File tree

4 files changed

+308
-3
lines changed

4 files changed

+308
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ backend/.env
3232
# Backend
3333
backend/backend
3434
backend/tmp
35+
36+
# Helm chart
37+
xlsform-builder-*.tgz

Justfile

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
set dotenv-load
2+
3+
mod chart 'tasks/chart'
4+
5+
# List available commands
6+
[private]
7+
default:
8+
just help
9+
10+
# List available commands
11+
help:
12+
just --justfile {{justfile()}} --list
13+
14+
# Install curl if missing
15+
[private]
16+
_install-curl:
17+
#!/usr/bin/env bash
18+
set -e
19+
20+
if ! command -v curl &> /dev/null; then
21+
echo "📦 Installing curl..."
22+
if command -v apt-get &> /dev/null; then
23+
sudo apt-get update -qq && sudo apt-get install -y curl
24+
elif command -v yum &> /dev/null; then
25+
sudo yum install -y curl
26+
elif command -v apk &> /dev/null; then
27+
sudo apk add --no-cache curl
28+
else
29+
echo "❌ Error: curl is not installed and no package manager found"
30+
echo " Please install curl manually"
31+
exit 1
32+
fi
33+
echo "✓ curl installed"
34+
fi
35+
36+
# Install Helm if missing
37+
[private]
38+
_install-helm:
39+
#!/usr/bin/env bash
40+
set -e
41+
42+
if command -v helm &> /dev/null; then
43+
exit 0
44+
fi
45+
46+
echo "📦 Installing Helm..."
47+
48+
# Only Linux / amd64 automated install for now; otherwise instruct user
49+
UNAME_S="$(uname -s || echo unknown)"
50+
UNAME_M="$(uname -m || echo unknown)"
51+
52+
if [ "$UNAME_S" != "Linux" ] || { [ "$UNAME_M" != "x86_64" ] && [ "$UNAME_M" != "amd64" ]; }; then
53+
echo "❌ Automatic Helm install only supported on Linux amd64."
54+
echo " Please install Helm manually: https://helm.sh/docs/intro/install/"
55+
exit 1
56+
fi
57+
58+
TMP_DIR="$(mktemp -d)"
59+
trap 'rm -rf "$TMP_DIR"' EXIT
60+
61+
# Get latest Helm release tag
62+
HELM_TAG="$(curl -sSL https://api.github.com/repos/helm/helm/releases/latest | grep -oE '\"tag_name\":\s*\"v[0-9.]+\"' | head -1 | sed -E 's/\"tag_name\":\s*\"(v[0-9.]+)\"/\1/')"
63+
if [ -z "$HELM_TAG" ]; then
64+
echo "❌ Failed to determine latest Helm version."
65+
exit 1
66+
fi
67+
68+
ARCHIVE="helm-${HELM_TAG}-linux-amd64.tar.gz"
69+
URL="https://get.helm.sh/${ARCHIVE}"
70+
71+
echo "⬇️ Downloading ${URL}..."
72+
curl -sSL "$URL" -o "$TMP_DIR/helm.tar.gz"
73+
tar -xzf "$TMP_DIR/helm.tar.gz" -C "$TMP_DIR"
74+
75+
if sudo mv "$TMP_DIR/linux-amd64/helm" /usr/local/bin/helm 2>/dev/null; then
76+
chmod +x /usr/local/bin/helm
77+
echo "✓ Helm installed to /usr/local/bin/helm"
78+
else
79+
mkdir -p "$HOME/.local/bin"
80+
mv "$TMP_DIR/linux-amd64/helm" "$HOME/.local/bin/helm"
81+
chmod +x "$HOME/.local/bin/helm"
82+
export PATH="$HOME/.local/bin:$PATH"
83+
echo "✓ Helm installed to ~/.local/bin/helm"
84+
fi
85+
86+
if ! command -v helm &> /dev/null; then
87+
echo "❌ Error: Failed to install Helm"
88+
exit 1
89+
fi
90+
91+
# Start compose services (backend, frontend, minio s3)
92+
start:
93+
#!/usr/bin/env bash
94+
set -e
95+
docker compose up -d
96+
97+
# Stop compose services
98+
stop:
99+
docker compose down --remove-orphans
100+
101+
# Start all services for development
102+
dev:
103+
just start
104+
105+
# Echo to terminal with blue colour
106+
[no-cd]
107+
_echo-blue text:
108+
#!/usr/bin/env sh
109+
printf "\033[0;34m%s\033[0m\n" "{{ text }}"
110+
111+
# Echo to terminal with yellow colour
112+
[no-cd]
113+
_echo-yellow text:
114+
#!/usr/bin/env sh
115+
printf "\033[0;33m%s\033[0m\n" "{{ text }}"
116+
117+
# Echo to terminal with red colour
118+
[no-cd]
119+
_echo-red text:
120+
#!/usr/bin/env sh
121+
printf "\033[0;41m%s\033[0m\n" "{{ text }}"

chart/templates/_helpers.tpl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
{{- define "xlsform-builder.name" -}}
2-
{{- default .Chart.name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
2+
{{- default .Chart.Name .Values.nameOverride -}}
3+
{{- end -}}
4+
5+
{{- define "xlsform-builder.fullname" -}}
6+
{{- if .Values.fullnameOverride -}}
7+
{{- .Values.fullnameOverride -}}
8+
{{- else -}}
9+
{{- $name := default .Chart.Name .Values.nameOverride -}}
10+
{{- if contains $name .Release.Name -}}
11+
{{- .Release.Name -}}
12+
{{- else -}}
13+
{{- printf "%s-%s" .Release.Name $name -}}
14+
{{- end -}}
15+
{{- end -}}
316
{{- end -}}
417

518
{{- define "xlsform-builder.backendFullname" -}}
6-
{{- printf "%s-backend" (include "xlsform-builder.name" .) | trunc 63 | trimSuffix "-" -}}
19+
{{- printf "%s-backend" (include "xlsform-builder.fullname" .) -}}
720
{{- end -}}
821

922
{{- define "xlsform-builder.frontendFullname" -}}
10-
{{- printf "%s-frontend" (include "xlsform-builder.name" .) | trunc 63 | trimSuffix "-" -}}
23+
{{- printf "%s-frontend" (include "xlsform-builder.fullname" .) -}}
1124
{{- end -}}

tasks/chart

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# List available commands
2+
[private]
3+
default:
4+
just --justfile {{justfile()}} --list chart
5+
6+
# Publish the packaged chart to an OCI registry.
7+
# Registry URL is resolved in the script from env, not from Justfile interpolation.
8+
# Defaults to ghcr.io/<owner>/charts, which results in charts at ghcr.io/<owner>/charts/<chartname>
9+
publish registry="":
10+
#!/usr/bin/env bash
11+
set -e
12+
13+
cd {{justfile_directory()}}
14+
15+
echo "🔐 Logging in to Helm registry..."
16+
# Resolve full registry path:
17+
# 1. CLI arg: `just chart publish registry="ghcr.io/org/charts"`
18+
# 2. Env: HELM_REGISTRY (e.g. "ghcr.io/hotosm/charts")
19+
# 3. Default: ghcr.io/<owner>/charts
20+
REGISTRY="{{ registry }}"
21+
if [ -z "$REGISTRY" ]; then
22+
if [ -n "${HELM_REGISTRY:-}" ]; then
23+
REGISTRY="${HELM_REGISTRY}"
24+
else
25+
OWNER="${HELM_REGISTRY_OWNER:-${GITHUB_REPOSITORY_OWNER:-}}"
26+
if [ -z "$OWNER" ]; then
27+
echo "❌ Unable to determine chart registry owner."
28+
echo " Provide one of:"
29+
echo " - just chart publish registry=\"ghcr.io/<owner>/charts\""
30+
echo " - HELM_REGISTRY=\"ghcr.io/<owner>/charts\""
31+
echo " - HELM_REGISTRY_OWNER or GITHUB_REPOSITORY_OWNER"
32+
exit 1
33+
fi
34+
REGISTRY="ghcr.io/${OWNER}/charts"
35+
fi
36+
fi
37+
38+
REGISTRY_HOST="$(printf '%s\n' "$REGISTRY" | cut -d/ -f1)"
39+
echo "REGISTRY: ${REGISTRY}"
40+
echo "REGISTRY_HOST: ${REGISTRY_HOST}"
41+
42+
# Prefer explicit Helm registry creds, fall back to GitHub defaults in CI
43+
USERNAME="${HELM_REGISTRY_USERNAME:-${GITHUB_ACTOR:-}}"
44+
PASSWORD="${HELM_REGISTRY_PASSWORD:-${GITHUB_TOKEN:-}}"
45+
46+
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
47+
echo "❌ Missing registry credentials."
48+
echo " Set HELM_REGISTRY_USERNAME / HELM_REGISTRY_PASSWORD"
49+
echo " or rely on GITHUB_ACTOR / GITHUB_TOKEN in GitHub Actions."
50+
exit 1
51+
fi
52+
53+
echo "$PASSWORD" | helm registry login "$REGISTRY_HOST" \
54+
--username "$USERNAME" \
55+
--password-stdin
56+
57+
just chart build
58+
59+
CHART_FILE=$(ls -t xlsform-builder-*.tgz | head -1)
60+
if [ -z "$CHART_FILE" ]; then
61+
echo "❌ No chart file found. Run build first"
62+
exit 1
63+
fi
64+
65+
echo "🚀 Publishing chart to OCI registry..."
66+
echo "📦 Chart file: $CHART_FILE"
67+
68+
echo "🔎 Checking if chart version already exists in registry..."
69+
CHART_VERSION=$(helm show chart "$CHART_FILE" | grep '^version:' | awk '{ print $2 }')
70+
if helm show chart "oci://$REGISTRY/xlsform-builder" --version "$CHART_VERSION" >/dev/null 2>&1; then
71+
echo "ℹ️ Chart version $CHART_VERSION already exists in OCI registry."
72+
echo " Skipping push."
73+
exit 0
74+
fi
75+
76+
echo "📤 Pushing to: oci://$REGISTRY"
77+
helm push "$CHART_FILE" "oci://$REGISTRY"
78+
79+
echo "✅ Chart published!"
80+
81+
# Build the Helm chart: lint, update deps, test, and package
82+
build:
83+
#!/usr/bin/env bash
84+
set -e
85+
86+
# Ensure Helm is available (works locally and in CI)
87+
just _install-helm
88+
89+
cd {{justfile_directory()}}
90+
91+
echo "🔨 Building Helm chart..."
92+
echo ""
93+
94+
just chart lint
95+
just chart dependencies
96+
just chart validate
97+
just chart package
98+
99+
# Lint the Helm chart
100+
lint:
101+
#!/usr/bin/env sh
102+
set -e
103+
104+
cd {{justfile_directory()}}
105+
echo "🔍 Linting chart..."
106+
helm lint ./chart
107+
echo "✓ Lint passed"
108+
echo ""
109+
110+
# Update chart dependences
111+
dependencies:
112+
#!/usr/bin/env sh
113+
set -e
114+
115+
cd {{justfile_directory()}}/chart
116+
echo "📥 Updating dependencies..."
117+
helm dependency update
118+
cd ..
119+
echo "✓ Dependencies updated"
120+
echo ""
121+
122+
# Validate chart templates
123+
validate:
124+
#!/usr/bin/env sh
125+
set -e
126+
127+
cd {{justfile_directory()}}
128+
echo "🧪 Testing chart (dry-run)..."
129+
helm install xlsform-builder-test ./chart --dry-run=client --take-ownership --debug > /dev/null
130+
echo "✓ Test passed"
131+
echo ""
132+
133+
# Package the Helm chart
134+
package:
135+
#!/usr/bin/env bash
136+
set -e
137+
138+
cd {{justfile_directory()}}
139+
echo "📦 Packaging chart..."
140+
helm package ./chart
141+
PACKAGE=$(ls -t xlsform-builder-*.tgz | head -1)
142+
echo "✓ Chart packaged: $PACKAGE"
143+
echo ""
144+
echo "✅ Build complete!"
145+
146+
# Render chart templates
147+
template:
148+
#!/usr/bin/env bash
149+
set -e
150+
cd {{justfile_directory()}}
151+
helm template xlsform-builder ./chart
152+
153+
# Show chart information
154+
show:
155+
#!/usr/bin/env bash
156+
set -e
157+
cd {{justfile_directory()}}
158+
helm show all ./chart
159+
160+
# Clean up packaged charts
161+
clean:
162+
#!/usr/bin/env bash
163+
set -e
164+
165+
cd {{justfile_directory()}}
166+
rm -f xlsform-builder-*.tgz
167+
rm -rf chart/charts/
168+
echo "✓ Cleaned up chart artifacts"

0 commit comments

Comments
 (0)