Skip to content

Commit c1f1419

Browse files
committed
wip
1 parent eac2373 commit c1f1419

File tree

3 files changed

+117
-59
lines changed

3 files changed

+117
-59
lines changed
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+
- distribution:
17+
outcomes:
18+
- pass:
19+
when: "== gke"
20+
message: GKE is a supported platform
21+
- pass:
22+
when: "== k3s"
23+
message: K3S is a supported platform
24+
- fail:
25+
when: "== kind"
26+
message: This application does not support Kind
27+
- warn:
28+
message: The Kubernetes platform is not validated, but there are no known compatibility issues.
Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,111 @@
11
version: "3"
22

3+
vars:
4+
CONTAINER_REGISTRY: '{{.CONTAINER_REGISTRY | default "ghcr.io"}}'
5+
CONTAINER_IMAGE: '{{.CONTAINER_IMAGE | default "replicatedhq/platform-examples/wg-easy-tools"}}'
6+
CONTAINER_TAG: '{{.CONTAINER_TAG | default "latest"}}'
7+
CONTAINER_NAME: '{{.CONTAINER_NAME | default "wg-easy-tools"}}'
8+
CONTAINER_RUNTIME: '{{.CONTAINER_RUNTIME | default "podman"}}'
9+
310
# Development environment tasks
411
tasks:
5-
build-image:
12+
exec:
13+
desc: Attach to development container shell
14+
silent: true
15+
requires:
16+
vars: [CONTAINER_NAME]
17+
deps:
18+
- task: start
19+
cmds:
20+
- echo "Connecting to {{.CONTAINER_NAME}}..."
21+
- "{{.CONTAINER_RUNTIME}} exec -it {{.CONTAINER_NAME}} {{.CMD}}"
22+
vars:
23+
CMD: "{{if .CMD}}bash -c '{{.CMD}}'{{else}}/bin/bash{{end}}"
24+
25+
build:
26+
run: once
627
desc: Build development container image
728
vars:
8-
IMAGE_NAME: '{{.DEV_CONTAINER_REGISTRY}}/{{.DEV_CONTAINER_IMAGE}}:{{.DEV_CONTAINER_TAG}}'
29+
IMAGE_NAME: "{{.CONTAINER_REGISTRY}}/{{.CONTAINER_IMAGE}}:{{.CONTAINER_TAG}}"
930
CONTAINERFILE: '{{.CONTAINERFILE | default "./container/Containerfile"}}'
1031
BUILD_ARGS: '{{.BUILD_ARGS | default ""}}'
11-
requires:
12-
vars: [DEV_CONTAINER_REGISTRY, DEV_CONTAINER_IMAGE, CONTAINERFILE]
32+
MESSAGE: "{{.MESSAGE}}"
33+
cmds:
34+
- '{{if .MESSAGE}}echo "{{.MESSAGE}}"{{end}}'
35+
- "{{.CONTAINER_RUNTIME}} build -t {{.IMAGE_NAME}} -f {{.CONTAINERFILE}} ."
36+
status:
37+
- "{{.CONTAINER_RUNTIME}} image exists {{.IMAGE_NAME}}"
1338

39+
pull:
40+
run: once
41+
vars:
42+
IMAGE_NAME: "{{.CONTAINER_REGISTRY}}/{{.CONTAINER_IMAGE}}:{{.CONTAINER_TAG}}"
43+
CONTAINERFILE: '{{.CONTAINERFILE | default "./container/Containerfile"}}'
1444
cmds:
15-
- '{{.CONTAINER_RUNTIME}} build -t {{.IMAGE_NAME}} -f {{.CONTAINERFILE}} .'
45+
- cmd: "{{.CONTAINER_RUNTIME}} pull {{.IMAGE_NAME}}"
46+
ignore_error: true
47+
status:
48+
- "{{.CONTAINER_RUNTIME}} image exists {{.IMAGE_NAME}}"
49+
50+
# Replaces long if/else commands with idempotent tasks and task-color user feedback
51+
check-image-exists:
52+
desc: If image does not exist, tries to pull. If pull fails, tries to build
53+
run: always
54+
vars:
55+
IMAGE_NAME: "{{.CONTAINER_REGISTRY}}/{{.CONTAINER_IMAGE}}:{{.CONTAINER_TAG}}"
56+
cmds:
57+
- echo "Image '{{.IMAGE_NAME}}' does not exist. Trying pull"
58+
- task: pull
59+
- task: build
60+
vars:
61+
MESSAGE: "Pull failed. Trying build"
62+
status:
63+
- "{{.CONTAINER_RUNTIME}} image exists {{.IMAGE_NAME}}"
1664

17-
# Start development container in background.
1865
start:
1966
desc: Start development container in background
20-
silent: true
2167
run: once
2268
vars:
23-
IMAGE_NAME: '{{.DEV_CONTAINER_REGISTRY}}/{{.DEV_CONTAINER_IMAGE}}:{{.DEV_CONTAINER_TAG}}'
69+
IMAGE_NAME: "{{.CONTAINER_REGISTRY}}/{{.CONTAINER_IMAGE}}:{{.CONTAINER_TAG}}"
2470
CONTAINERFILE: '{{.CONTAINERFILE | default "./container/Containerfile"}}'
2571
BUILD_ARGS: '{{.BUILD_ARGS | default ""}}'
2672
requires:
27-
vars: [DEV_CONTAINER_REGISTRY, DEV_CONTAINER_IMAGE, DEV_CONTAINER_TAG, DEV_CONTAINER_NAME, REPLICATED_API_TOKEN]
28-
29-
status:
30-
- '{{.CONTAINER_RUNTIME}} ps | grep -q "{{.DEV_CONTAINER_NAME}}"'
73+
vars:
74+
[
75+
CONTAINER_REGISTRY,
76+
CONTAINER_IMAGE,
77+
CONTAINER_TAG,
78+
CONTAINER_NAME,
79+
REPLICATED_API_TOKEN,
80+
]
3181
cmds:
82+
- task: check-image-exists
83+
# Start with host networking for kubectl port-forward compatibility
3284
- |
33-
# Check if the image exists locally
34-
# If not, pull it from the registry
35-
# If that fails, build it locally
36-
if ! {{.CONTAINER_RUNTIME}} image exists {{.IMAGE_NAME}}; then
37-
echo "Image {{.IMAGE_NAME}} not found locally."
38-
echo "Attempting to pull the image..."
39-
if ! {{.CONTAINER_RUNTIME}} pull {{.IMAGE_NAME}}; then
40-
echo "Failed to pull image. Building it locally..."
41-
{{.CONTAINER_RUNTIME}} build -t {{.IMAGE_NAME}} -f {{.CONTAINERFILE}} .
42-
fi
43-
fi
44-
45-
# Start container with host networking for kubectl port-forward compatibility
46-
CONTAINER_ID=$({{.CONTAINER_RUNTIME}} run --rm --name {{.DEV_CONTAINER_NAME}} -d \
85+
{{.CONTAINER_RUNTIME}} run --rm --name {{.CONTAINER_NAME}} -d \
4786
-v $(pwd):/workspace \
87+
-v $(pwd)/taskfiles/internal.yaml:/workspace/Taskfile.yaml \
4888
-e REPLICATED_API_TOKEN={{ .REPLICATED_API_TOKEN }} \
49-
{{.IMAGE_NAME}} bash -c 'trap "exit 0" TERM; sleep infinity & wait')
50-
51-
if [ $? -eq 0 ]; then
52-
echo "Development container started successfully with ID: $CONTAINER_ID"
53-
else
54-
echo "Failed to start development container"
55-
exit 1
56-
fi
57-
58-
shell:
59-
desc: Attach to development container shell
60-
silent: true
61-
requires:
62-
vars: [DEV_CONTAINER_NAME]
63-
deps:
64-
- task: start
65-
cmds:
66-
- echo "Connecting to {{.DEV_CONTAINER_NAME}}..."
67-
- '{{.CONTAINER_RUNTIME}} exec -it {{.DEV_CONTAINER_NAME}} /bin/bash'
89+
{{.IMAGE_NAME}} bash -c 'trap "exit 0" TERM; sleep infinity & wait'
90+
status:
91+
- '[[ $({{.CONTAINER_RUNTIME}} ps | grep -c "{{.CONTAINER_NAME}}") -eq 1 ]] && exit 0'
6892

6993
stop:
7094
desc: Stop development container
71-
silent: true
95+
run: once
7296
requires:
73-
vars: [DEV_CONTAINER_NAME]
97+
vars: [CONTAINER_NAME]
7498
cmds:
75-
- |
76-
if {{.CONTAINER_RUNTIME}} ps | grep -q "{{.DEV_CONTAINER_NAME}}"; then
77-
echo "Stopping {{.DEV_CONTAINER_NAME}} development container..."
78-
{{.CONTAINER_RUNTIME}} stop {{.DEV_CONTAINER_NAME}}
79-
else
80-
echo "Container {{.DEV_CONTAINER_NAME}} is not running"
81-
fi
99+
- "{{.CONTAINER_RUNTIME}} stop {{.CONTAINER_NAME}}"
100+
status:
101+
- 'exit $({{.CONTAINER_RUNTIME}} ps | grep -c "{{.CONTAINER_NAME}}")'
82102

83103
restart:
84104
desc: Restart development container
105+
run: once
85106
silent: true
86107
requires:
87-
vars: [DEV_CONTAINER_NAME]
108+
vars: [CONTAINER_NAME]
88109
cmds:
89110
- task: stop
90111
- task: start

applications/wg-easy/taskfiles/internal.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,21 @@ tasks:
126126
- echo "All dependencies updated!"
127127

128128
helm-preflight:
129-
desc: Run preflight checks on the Helm chart using preflight tool
129+
desc: Run preflight checks on all Helm charts using preflight tool
130130
silent: false
131131
cmds:
132-
- defer: rm preflightbundle-*.tar.gz
133-
- echo "Running preflight check on wg-easy helm chart..."
134-
- eval "helm template wg-easy | KUBECONFIG={{.KUBECONFIG_FILE}} preflight - -v=5"
132+
- defer: rm -f preflightbundle-*.tar.gz
133+
- echo "Running preflight checks on all helm charts..."
134+
- |
135+
# Find all charts and template them together
136+
TEMPLATE_OUTPUT=""
137+
for chart_dir in $(find . -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
138+
TEMPLATE_OUTPUT="${TEMPLATE_OUTPUT}$(helm template "$chart_dir")"$'\n---\n'
139+
done
140+
141+
# Pipe all templates to preflight at once
142+
echo "Running preflight checks on all templates..."
143+
echo "$TEMPLATE_OUTPUT" | KUBECONFIG={{.KUBECONFIG_FILE}} preflight - -v=5
135144
- echo "Preflight check completed!"
136145
deps:
137146
- cluster-create

0 commit comments

Comments
 (0)