Skip to content

Commit 5759745

Browse files
committed
squash
1 parent c36cb69 commit 5759745

File tree

6 files changed

+225
-41
lines changed

6 files changed

+225
-41
lines changed

applications/wg-easy/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,21 @@ Use tools to automate repetitive tasks, reducing human error and increasing deve
5555

5656
```
5757
applications/wg-easy/
58-
├── charts/templates/ # Common templates shared across charts
59-
├── cert-manager/ # Wrapped cert-manager chart
60-
├── cert-manager-issuers/ # Chart for cert-manager issuers
58+
├── charts
59+
│   ├── cert-manager # Wrapped cert-manager chart
60+
│   ├── cert-manager-issuers # Chart for cert-manager issuers
61+
│   ├── replicated-sdk # Replicated SDK chart
62+
│   ├── templates # Common templates shared across charts
63+
│   ├── traefik # Wrapped Traefik chart
64+
│   └── wg-easy # Main application chart
6165
├── replicated/ # Root Replicated configuration
62-
├── replicated-sdk/ # Replicated SDK chart
6366
├── taskfiles/ # Task utility functions
64-
├── traefik/ # Wrapped Traefik chart
65-
├── wg-easy/ # Main application chart
6667
├── helmfile.yaml # Defines chart installation order
6768
└── Taskfile.yaml # Main task definitions
6869
```
6970

7071
## Architecture Overview
7172

72-
![Architecture Diagram](docs/architecture.png)
73-
7473
Key components:
7574
- **Taskfile**: Orchestrates the workflow with automated tasks
7675
- **Helmfile**: Manages chart dependencies and installation order

applications/wg-easy/Taskfile.yaml

Lines changed: 147 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ includes:
77
vars:
88
# Application configuration
99
APP_NAME: '{{.REPLICATED_APP | default "wg-easy"}}'
10+
APP_SLUG: '{{.REPLICATED_APP_SLUG | default "wg-easy-cre"}}'
11+
12+
# Release configuration
13+
RELEASE_CHANNELd: '{{.RELEASE_CHANNEL | default "Unstable"}}'
14+
RELEASE_VERSION: '{{.RELEASE_VERSION | default "0.0.1"}}'
15+
RELEASE_NOTES: '{{.RELEASE_NOTES | default "Release created via task release-create"}}'
1016

1117
# Cluster configuration
1218
CLUSTER_NAME: '{{.CLUSTER_NAME | default "test-cluster"}}'
@@ -38,8 +44,9 @@ vars:
3844
tasks:
3945
default:
4046
desc: Show available tasks
47+
silent: true
4148
cmds:
42-
- task -s --list
49+
- task --list
4350

4451
cluster-create:
4552
desc: Create a test cluster using Replicated Compatibility Matrix (use EMBEDDED=true for embedded clusters)
@@ -49,24 +56,24 @@ tasks:
4956
EMBEDDED: '{{.EMBEDDED | default "false"}}'
5057
LICENSE_ID: '{{if eq .EMBEDDED "true"}}{{.LICENSE_ID | default "2cmqT1dBVHZ3aSH21kPxWtgoYGr"}}{{end}}'
5158
TIMEOUT: '{{if eq .EMBEDDED "true"}}420{{else}}300{{end}}'
59+
TTL: '{{.TTL | default "4h"}}'
5260
status:
5361
- replicated cluster ls --output json | jq -e '.[] | select(.name == "{{.CLUSTER_NAME}}")' > /dev/null
5462
cmds:
5563
- |
5664
if [ "{{.EMBEDDED}}" = "true" ]; then
5765
echo "Creating embedded cluster {{.CLUSTER_NAME}} with license ID {{.LICENSE_ID}}..."
58-
replicated cluster create --distribution embedded-cluster --name {{.CLUSTER_NAME}} --license-id {{.LICENSE_ID}}
66+
replicated cluster create --distribution embedded-cluster --name {{.CLUSTER_NAME}} --license-id {{.LICENSE_ID}} --ttl {{.TTL}}
5967
else
6068
echo "Creating cluster {{.CLUSTER_NAME}} with distribution {{.DISTRIBUTION}}..."
61-
replicated cluster create --name {{.CLUSTER_NAME}} --distribution {{.DISTRIBUTION}} --version {{.K8S_VERSION}} --disk {{.DISK_SIZE}} --instance-type {{.INSTANCE_TYPE}}
69+
replicated cluster create --name {{.CLUSTER_NAME}} --distribution {{.DISTRIBUTION}} --version {{.K8S_VERSION}} --disk {{.DISK_SIZE}} --instance-type {{.INSTANCE_TYPE}} --ttl {{.TTL}}
6270
fi
6371
- task: utils:wait-for-cluster
6472
vars:
6573
TIMEOUT: "{{.TIMEOUT}}"
6674

67-
list-cluster:
75+
cluster-list:
6876
desc: List the cluster
69-
silent: false
7077
cmds:
7178
- |
7279
CLUSTER_ID=$(replicated cluster ls --output json | jq -r '.[] | select(.name == "{{.CLUSTER_NAME}}") | .id')
@@ -82,7 +89,6 @@ tasks:
8289
- sleep 5
8390
- echo "Tests completed!"
8491

85-
8692
verify-kubeconfig:
8793
desc: Verify kubeconfig
8894
silent: false
@@ -126,18 +132,19 @@ tasks:
126132
dependencies-update:
127133
desc: Update Helm dependencies for all charts
128134
silent: false
135+
run: once
129136
cmds:
130137
- echo "Updating Helm dependencies for all charts..."
131138
- |
132139
# Find all charts and update their dependencies
133-
for chart_dir in $(find . -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
140+
for chart_dir in $(find charts/ -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
134141
echo "Updating dependency $chart_dir"
135-
helm dependency update "$chart_dir"
142+
helm dependency update --skip-refresh "$chart_dir"
136143
done
137144
- echo "All dependencies updated!"
138145

139-
ports-expose:
140-
desc: Expose configured ports and capture exposed URLs
146+
cluster-ports-expose:
147+
desc: Expose configured ports for a cluster and capture exposed URLs
141148
silent: false
142149
run: once
143150
status:
@@ -165,8 +172,8 @@ tasks:
165172
deps:
166173
- cluster-create
167174

168-
helm-deploy:
169-
desc: Deploy all charts using helmfile
175+
helm-install:
176+
desc: Install all charts using helmfile
170177
silent: false
171178
cmds:
172179
- echo "Installing all charts via helmfile"
@@ -184,11 +191,10 @@ tasks:
184191
# Deploy with helmfile
185192
echo "Using $ENV_VARS"
186193
eval "KUBECONFIG={{.KUBECONFIG_FILE}} $ENV_VARS helmfile sync --wait"
187-
- echo "All charts deployed!"
194+
- echo "All charts installed!"
188195
deps:
189196
- setup-kubeconfig
190-
- ports-expose
191-
197+
- cluster-ports-expose
192198

193199
cluster-delete:
194200
desc: Delete all test clusters with matching name and clean up kubeconfig
@@ -270,33 +276,83 @@ tasks:
270276
- echo "Packaging Helm charts..."
271277
- |
272278
# Find top-level directories containing Chart.yaml files
273-
for chart_dir in $(find . -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
279+
for chart_dir in $(find charts/ -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
274280
echo "Packaging chart: $chart_dir"
275281
# Navigate to chart directory, package it, and move the resulting .tgz to release folder
276-
(cd "$chart_dir" && helm package . && mv *.tgz ../release/)
282+
(cd "$chart_dir" && helm package . && mv *.tgz ../../release/)
277283
done
278284
279285
- echo "Release files prepared in ./release/ directory"
280286
deps:
281-
- update-version
282-
287+
- dependencies-update
283288

284289
release-create:
285290
desc: Create and promote a release using the Replicated CLI
286291
silent: false
292+
run: once
287293
vars:
288294
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
295+
VERSION: '{{.VERSION | default "0.0.1"}}'
289296
RELEASE_NOTES: '{{.RELEASE_NOTES | default "Release created via task release-create"}}'
297+
requires:
298+
vars: [APP_SLUG, VERSION]
290299
cmds:
291-
- echo "Creating and promoting release for $APP_NAME to channel $CHANNEL..."
300+
- echo "Creating and promoting release for {{.APP_SLUG}} to channel {{.CHANNEL}}..."
292301
- |
293302
# Create and promote the release in one step
294303
echo "Creating release from files in ./release directory..."
295-
replicated release create --app $APP_NAME --yaml-dir ./release --release-notes "$RELEASE_NOTES" --promote $CHANNEL --version $VERSION
296-
echo "Release version $VERSION created and promoted to channel $CHANNEL"
304+
replicated release create --app {{.APP_SLUG}} --yaml-dir ./release --release-notes "{{.RELEASE_NOTES}}" --promote {{.CHANNEL}} --version {{.VERSION}}
305+
echo "Release version {{.VERSION}} created and promoted to channel {{.CHANNEL}}"
297306
deps:
298307
- release-prepare
299308

309+
customer-create:
310+
desc: Create a new customer or get existing customer with matching name and return their ID
311+
silent: false
312+
run: once
313+
vars:
314+
CUSTOMER_NAME: '{{.CUSTOMER_NAME | default "test-customer"}}'
315+
CUSTOMER_EMAIL: '{{.CUSTOMER_EMAIL | default "[email protected]"}}'
316+
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
317+
LICENSE_TYPE: '{{.LICENSE_TYPE | default "dev"}}'
318+
EXPIRES_IN: '{{.EXPIRES_IN | default ""}}'
319+
requires:
320+
vars: [APP_SLUG]
321+
cmds:
322+
- |
323+
# First check if customer already exists
324+
echo "Looking for existing customer {{.CUSTOMER_NAME}} for app {{.APP_SLUG}}..."
325+
EXISTING_CUSTOMER=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.name=="{{.CUSTOMER_NAME}}") | .id' | head -1)
326+
327+
if [ -n "$EXISTING_CUSTOMER" ]; then
328+
echo "Found existing customer {{.CUSTOMER_NAME}} with ID: $EXISTING_CUSTOMER"
329+
echo "$EXISTING_CUSTOMER"
330+
exit 0
331+
fi
332+
333+
# No existing customer found, create a new one
334+
echo "Creating new customer {{.CUSTOMER_NAME}} for app {{.APP_SLUG}}..."
335+
336+
# Build the command with optional expiration
337+
CMD="replicated customer create \
338+
--app {{.APP_SLUG}} \
339+
--name {{.CUSTOMER_NAME}} \
340+
--email {{.CUSTOMER_EMAIL}} \
341+
--channel {{.CHANNEL}} \
342+
--type {{.LICENSE_TYPE}} \
343+
--output json"
344+
345+
# Add expiration if specified
346+
if [ -n "{{.EXPIRES_IN}}" ]; then
347+
CMD="$CMD --expires-in {{.EXPIRES_IN}}"
348+
fi
349+
350+
# Create the customer and capture the output
351+
CUSTOMER_JSON=$($CMD)
352+
353+
# Extract and output just the customer ID
354+
echo "$CUSTOMER_JSON" | jq -r '.id'
355+
300356
gcp-vm-create:
301357
desc: Create a simple GCP VM instance
302358
silent: false
@@ -342,26 +398,91 @@ tasks:
342398
status:
343399
- |
344400
# Check if the application tarball has already been downloaded and extracted
345-
gcloud compute ssh {{.VM_NAME}} --project={{.GCP_PROJECT}} --zone={{.GCP_ZONE}} --command="test -d ./{{.APP_NAME}}" &>/dev/null
401+
gcloud compute ssh {{.VM_NAME}} --project={{.GCP_PROJECT}} --zone={{.GCP_ZONE}} --command="test -d ./{{.APP_SLUG}}" &>/dev/null
346402
cmds:
347403
- task: utils:gcp-operations
348404
vars:
349405
OPERATION: "setup-embedded"
350-
APP_NAME: '{{.APP_NAME}}'
406+
APP_SLUG: '{{.APP_SLUG}}'
351407
CHANNEL: '{{.CHANNEL}}'
352408
AUTH_TOKEN: '{{.AUTH_TOKEN}}'
353409
GCP_PROJECT: '{{.GCP_PROJECT}}'
354410
GCP_ZONE: '{{.GCP_ZONE}}'
355411
VM_NAME: '{{.VM_NAME}}'
356412

413+
customer-ls:
414+
desc: List customers for the application
415+
silent: false
416+
vars:
417+
OUTPUT_FORMAT: '{{.OUTPUT_FORMAT | default "table"}}'
418+
requires:
419+
vars: [APP_SLUG]
420+
cmds:
421+
- echo "Listing customers for app {{.APP_SLUG}}..."
422+
- replicated customer ls --app {{.APP_SLUG}} --output {{.OUTPUT_FORMAT}}
423+
424+
customer-delete:
425+
desc: Archive a customer by ID
426+
silent: false
427+
vars:
428+
CUSTOMER_ID: '{{.CUSTOMER_ID}}'
429+
requires:
430+
vars: [APP_SLUG, CUSTOMER_ID]
431+
cmds:
432+
- echo "Archiving customer with ID {{.CUSTOMER_ID}} from app {{.APP_SLUG}}..."
433+
- |
434+
# Verify customer exists before attempting to archive
435+
CUSTOMER_EXISTS=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.id=="{{.CUSTOMER_ID}}") | .id')
436+
if [ -z "$CUSTOMER_EXISTS" ]; then
437+
echo "Error: Customer with ID {{.CUSTOMER_ID}} not found for app {{.APP_SLUG}}"
438+
exit 1
439+
fi
440+
441+
# Get customer name for confirmation message
442+
CUSTOMER_NAME=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.id=="{{.CUSTOMER_ID}}") | .name')
443+
444+
# Archive the customer
445+
replicated customer archive {{.CUSTOMER_ID}} --app {{.APP_SLUG}}
446+
447+
# Confirm archiving
448+
echo "Customer '$CUSTOMER_NAME' (ID: {{.CUSTOMER_ID}}) successfully archived"
449+
450+
clean:
451+
desc: Remove temporary Helm directories, chart dependencies, and release folder
452+
silent: false
453+
cmds:
454+
- echo "Cleaning temporary directories and dependencies..."
455+
- |
456+
# Remove the release directory
457+
if [ -d "./release" ]; then
458+
echo "Removing release directory..."
459+
rm -rf ./release
460+
fi
461+
462+
# Find and remove tmpcharts-* directories in charts/
463+
echo "Removing temporary chart directories..."
464+
find charts/ -type d -name "tmpcharts-*" -print
465+
find charts/ -type d -name "tmpcharts-*" -exec rm -rf {} \; 2>/dev/null || true
466+
467+
# Clean up chart dependencies (.tgz files) in charts/*/charts/
468+
echo "Removing chart dependencies..."
469+
find charts/ -path "*/charts/*.tgz" -type f -print
470+
find charts/ -path "*/charts/*.tgz" -type f -delete
471+
472+
# Clean up any tmpcharts directories in subdirectories
473+
echo "Cleaning up any remaining tmpcharts directories..."
474+
find . -type d -name "tmpcharts-*" -print
475+
find . -type d -name "tmpcharts-*" -exec rm -rf {} \; 2>/dev/null || true
476+
- echo "Cleaning complete!"
477+
357478
full-test-cycle:
358479
desc: Create cluster, get kubeconfig, expose ports, update dependencies, deploy charts, test, and delete
359480
silent: false
360481
cmds:
361482
- task: cluster-create
362483
- task: setup-kubeconfig
363-
- task: ports-expose
484+
- task: cluster-ports-expose
364485
- task: dependencies-update
365-
- task: helm-deploy
486+
- task: helm-install
366487
- task: test
367488
- task: cluster-delete
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: cert-manager-preflights
5+
labels:
6+
troubleshoot.sh/kind: preflight
7+
type: Opaque
8+
stringData:
9+
preflight.yaml: |
10+
apiVersion: troubleshoot.sh/v1beta2
11+
kind: Preflight
12+
metadata:
13+
name: cert-manager-preflights
14+
spec:
15+
analyzers:
16+
# https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/README.template.md#prerequisites
17+
- clusterVersion:
18+
outcomes:
19+
- fail:
20+
when: "< 1.22.0"
21+
message: The application requires at least Kubernetes 1.22.0, and recommends 1.25.0.
22+
uri: https://kubernetes.io
23+
- warn:
24+
when: "< 1.25.0"
25+
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.25.0 or later.
26+
uri: https://kubernetes.io
27+
- pass:
28+
message: Your cluster meets the recommended and required versions of Kubernetes.

applications/wg-easy/container/Containerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ RUN apt-get update && apt-get install -y \
1717
curl \
1818
jq \
1919
less \
20-
yq \
2120
gnupg \
2221
bash-completion \
2322

@@ -56,7 +55,19 @@ RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | b
5655
| cut -d : -f 2,3 \
5756
| tr -d \") -o replicated.tar.gz \
5857
&& tar xf replicated.tar.gz replicated && rm replicated.tar.gz \
59-
&& mv replicated /usr/local/bin/replicated
58+
&& mv replicated /usr/local/bin/replicated \
59+
60+
# Install Preflight CLI
61+
&& curl -Ls https://github.com/replicatedhq/troubleshoot/releases/latest/download/preflight_linux_amd64.tar.gz -o preflight.tar.gz \
62+
&& tar xf preflight.tar.gz preflight && rm preflight.tar.gz \
63+
&& mv preflight /usr/local/bin/preflight \
64+
65+
# Install yq
66+
&& BINARY=yq_linux_amd64 \
67+
&& VERSION=v4.45.1 \
68+
&& curl -Ls https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O \
69+
&& tar xf ${BINARY}.tar.gz && rm ${BINARY}.tar.gz \
70+
&& mv ${BINARY} /usr/local/bin/yq
6071

6172
# Create a non-root user for better security
6273
RUN groupadd -r devuser && useradd -r -g devuser -m -s /bin/bash devuser

0 commit comments

Comments
 (0)