Skip to content

Commit 5d33612

Browse files
committed
Migrate customer tasks to internal taskfile
1 parent 337a5ae commit 5d33612

File tree

1 file changed

+127
-13
lines changed

1 file changed

+127
-13
lines changed

applications/wg-easy/taskfiles/internal.yaml

Lines changed: 127 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ includes:
66

77
vars:
88
# Application configuration
9-
APP_NAME: '{{.REPLICATED_APP | default "wg-easy"}}'
9+
APP_SLUG: '{{.REPLICATED_APP | default "wg-easy"}}'
10+
11+
# Release configuration
12+
RELEASE_CHANNEL: '{{.RELEASE_CHANNEL | default "Unstable"}}'
13+
RELEASE_VERSION: '{{.RELEASE_VERSION | default "0.0.1"}}'
14+
RELEASE_NOTES: '{{.RELEASE_NOTES | default "Release created via task release-create"}}'
1015

1116
# Cluster configuration
1217
CLUSTER_NAME: '{{.CLUSTER_NAME | default "test-cluster"}}'
@@ -71,7 +76,6 @@ tasks:
7176
- sleep 5
7277
- echo "Tests completed!"
7378

74-
7579
verify-kubeconfig:
7680
desc: Verify kubeconfig
7781
silent: false
@@ -125,7 +129,7 @@ tasks:
125129
done
126130
- echo "All dependencies updated!"
127131

128-
ports-expose:
132+
cluster-ports-expose:
129133
desc: Expose configured ports and capture exposed URLs
130134
silent: false
131135
run: once
@@ -154,7 +158,7 @@ tasks:
154158
deps:
155159
- cluster-create
156160

157-
helm-deploy:
161+
helm-install:
158162
desc: Deploy all charts using helmfile
159163
silent: false
160164
cmds:
@@ -178,7 +182,6 @@ tasks:
178182
- setup-kubeconfig
179183
- ports-expose
180184

181-
182185
cluster-delete:
183186
desc: Delete all test clusters with matching name and clean up kubeconfig
184187
silent: false
@@ -267,8 +270,7 @@ tasks:
267270
268271
- echo "Release files prepared in ./release/ directory"
269272
deps:
270-
- update-version
271-
273+
- dependencies-update
272274

273275
release-create:
274276
desc: Create and promote a release using the Replicated CLI
@@ -277,15 +279,99 @@ tasks:
277279
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
278280
RELEASE_NOTES: '{{.RELEASE_NOTES | default "Release created via task release-create"}}'
279281
cmds:
280-
- echo "Creating and promoting release for $APP_NAME to channel $CHANNEL..."
282+
- echo "Creating and promoting release for $APP_SLUG to channel $CHANNEL..."
281283
- |
282284
# Create and promote the release in one step
283285
echo "Creating release from files in ./release directory..."
284-
replicated release create --app $APP_NAME --yaml-dir ./release --release-notes "$RELEASE_NOTES" --promote $CHANNEL --version $VERSION
286+
replicated release create --app $APP_SLUG --yaml-dir ./release --release-notes "$RELEASE_NOTES" --promote $CHANNEL --version $VERSION
285287
echo "Release version $VERSION created and promoted to channel $CHANNEL"
286288
deps:
287289
- release-prepare
288290

291+
customer-create:
292+
desc: Create a new customer or get existing customer with matching name and return their ID
293+
silent: false
294+
run: once
295+
vars:
296+
CUSTOMER_NAME: '{{.CUSTOMER_NAME | default "test-customer"}}'
297+
CUSTOMER_EMAIL: '{{.CUSTOMER_EMAIL | default "[email protected]"}}'
298+
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
299+
LICENSE_TYPE: '{{.LICENSE_TYPE | default "dev"}}'
300+
EXPIRES_IN: '{{.EXPIRES_IN | default ""}}'
301+
requires:
302+
vars: [APP_SLUG]
303+
cmds:
304+
- |
305+
# First check if customer already exists
306+
echo "Looking for existing customer {{.CUSTOMER_NAME}} for app {{.APP_SLUG}}..."
307+
EXISTING_CUSTOMER=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.name=="{{.CUSTOMER_NAME}}") | .id' | head -1)
308+
309+
if [ -n "$EXISTING_CUSTOMER" ]; then
310+
echo "Found existing customer {{.CUSTOMER_NAME}} with ID: $EXISTING_CUSTOMER"
311+
echo "$EXISTING_CUSTOMER"
312+
exit 0
313+
fi
314+
315+
# No existing customer found, create a new one
316+
echo "Creating new customer {{.CUSTOMER_NAME}} for app {{.APP_SLUG}}..."
317+
318+
# Build the command with optional expiration
319+
CMD="replicated customer create \
320+
--app {{.APP_SLUG}} \
321+
--name {{.CUSTOMER_NAME}} \
322+
--email {{.CUSTOMER_EMAIL}} \
323+
--channel {{.CHANNEL}} \
324+
--type {{.LICENSE_TYPE}} \
325+
--output json"
326+
327+
# Add expiration if specified
328+
if [ -n "{{.EXPIRES_IN}}" ]; then
329+
CMD="$CMD --expires-in {{.EXPIRES_IN}}"
330+
fi
331+
332+
# Create the customer and capture the output
333+
CUSTOMER_JSON=$($CMD)
334+
335+
# Extract and output just the customer ID
336+
echo "$CUSTOMER_JSON" | jq -r '.id'
337+
338+
customer-ls:
339+
desc: List customers for the application
340+
silent: false
341+
vars:
342+
OUTPUT_FORMAT: '{{.OUTPUT_FORMAT | default "table"}}'
343+
requires:
344+
vars: [APP_SLUG]
345+
cmds:
346+
- echo "Listing customers for app {{.APP_SLUG}}..."
347+
- replicated customer ls --app {{.APP_SLUG}} --output {{.OUTPUT_FORMAT}}
348+
349+
customer-delete:
350+
desc: Archive a customer by ID
351+
silent: false
352+
vars:
353+
CUSTOMER_ID: '{{.CUSTOMER_ID}}'
354+
requires:
355+
vars: [APP_SLUG, CUSTOMER_ID]
356+
cmds:
357+
- echo "Archiving customer with ID {{.CUSTOMER_ID}} from app {{.APP_SLUG}}..."
358+
- |
359+
# Verify customer exists before attempting to archive
360+
CUSTOMER_EXISTS=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.id=="{{.CUSTOMER_ID}}") | .id')
361+
if [ -z "$CUSTOMER_EXISTS" ]; then
362+
echo "Error: Customer with ID {{.CUSTOMER_ID}} not found for app {{.APP_SLUG}}"
363+
exit 1
364+
fi
365+
366+
# Get customer name for confirmation message
367+
CUSTOMER_NAME=$(replicated customer ls --app {{.APP_SLUG}} --output json | jq -r '.[] | select(.id=="{{.CUSTOMER_ID}}") | .name')
368+
369+
# Archive the customer
370+
replicated customer archive {{.CUSTOMER_ID}} --app {{.APP_SLUG}}
371+
372+
# Confirm archiving
373+
echo "Customer '$CUSTOMER_NAME' (ID: {{.CUSTOMER_ID}}) successfully archived"
374+
289375
gcp-vm-create:
290376
desc: Create a simple GCP VM instance
291377
silent: false
@@ -331,26 +417,54 @@ tasks:
331417
status:
332418
- |
333419
# Check if the application tarball has already been downloaded and extracted
334-
gcloud compute ssh {{.VM_NAME}} --project={{.GCP_PROJECT}} --zone={{.GCP_ZONE}} --command="test -d ./{{.APP_NAME}}" &>/dev/null
420+
gcloud compute ssh {{.VM_NAME}} --project={{.GCP_PROJECT}} --zone={{.GCP_ZONE}} --command="test -d ./{{.APP_SLUG}}" &>/dev/null
335421
cmds:
336422
- task: utils:gcp-operations
337423
vars:
338424
OPERATION: "setup-embedded"
339-
APP_NAME: '{{.APP_NAME}}'
425+
APP_SLUG: '{{.APP_SLUG}}'
340426
CHANNEL: '{{.CHANNEL}}'
341427
AUTH_TOKEN: '{{.AUTH_TOKEN}}'
342428
GCP_PROJECT: '{{.GCP_PROJECT}}'
343429
GCP_ZONE: '{{.GCP_ZONE}}'
344430
VM_NAME: '{{.VM_NAME}}'
345431

432+
clean:
433+
desc: Remove temporary Helm directories, chart dependencies, and release folder
434+
silent: false
435+
cmds:
436+
- echo "Cleaning temporary directories and dependencies..."
437+
- |
438+
# Remove the release directory
439+
if [ -d "./release" ]; then
440+
echo "Removing release directory..."
441+
rm -rf ./release
442+
fi
443+
444+
# Find and remove tmpcharts-* directories in charts/
445+
echo "Removing temporary chart directories..."
446+
find charts/ -type d -name "tmpcharts-*" -print
447+
find charts/ -type d -name "tmpcharts-*" -exec rm -rf {} \; 2>/dev/null || true
448+
449+
# Clean up chart dependencies (.tgz files) in charts/*/charts/
450+
echo "Removing chart dependencies..."
451+
find charts/ -path "*/charts/*.tgz" -type f -print
452+
find charts/ -path "*/charts/*.tgz" -type f -delete
453+
454+
# Clean up any tmpcharts directories in subdirectories
455+
echo "Cleaning up any remaining tmpcharts directories..."
456+
find . -type d -name "tmpcharts-*" -print
457+
find . -type d -name "tmpcharts-*" -exec rm -rf {} \; 2>/dev/null || true
458+
- echo "Cleaning complete!"
459+
346460
full-test-cycle:
347461
desc: Create cluster, get kubeconfig, expose ports, update dependencies, deploy charts, test, and delete
348462
silent: false
349463
cmds:
350464
- task: cluster-create
351465
- task: setup-kubeconfig
352-
- task: ports-expose
466+
- task: cluster-ports-expose
353467
- task: dependencies-update
354-
- task: helm-deploy
468+
- task: helm-install
355469
- task: test
356470
- task: cluster-delete

0 commit comments

Comments
 (0)