-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
233 lines (195 loc) · 8.04 KB
/
Copy pathJustfile
File metadata and controls
233 lines (195 loc) · 8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
set shell := ["zsh", "-cu"]
set script-interpreter := ["zsh", "-eu"]
# Load project .env written by `setup` (compose also reads this file).
set dotenv-load := true
compose := "docker compose -f compose.yml"
# Canonical playground config — `setup` materializes these into `.env`.
container := "dokku-completion-harness"
example_app := "example"
data_root := justfile_directory() / "tmp" / "dokku-data"
dokku_host := "dokku-completion-harness.orb.local"
dokku_port := "22"
# Write .env, stage plugin-list into runtime data dir, chmod wrapper.
[script]
setup:
print -r -- "DOKKU_CONTAINER={{container}}" >| .env
print -r -- "DOKKU_DATA_ROOT={{data_root}}" >> .env
print -r -- "DOKKU_HOST={{dokku_host}}" >> .env
print -r -- "DOKKU_PORT={{dokku_port}}" >> .env
# tmp/dokku-data is pure runtime state (apps, plugin data, services). Plugin
# roster lives in-repo as dokku-plugins.txt; Dokku expects plugin-list here.
mkdir -p "{{data_root}}"
grep -v '^#' dokku-plugins.txt | grep -v '^[[:space:]]*$' >| "{{data_root}}/plugin-list"
chmod +x bin/dokku
# Tear down compose + plugin service containers + data so bootstrap is reliable.
[private]
[script]
reset_local_dokku:
echo "=== reset: stop compose / harness containers ==="
export DOKKU_DATA_ROOT="{{data_root}}"
{{compose}} down --remove-orphans || true
# Current name, previous name, and any accidental renames.
docker rm -f {{container}} dokku 2>/dev/null || true
echo "=== reset: remove plugin service containers for {{example_app}} ==="
# Dokku service plugins create sibling containers like dokku.postgres.example-db.
name_fmt=$(printf '%c%c%s%c%c' '{' '{' '.Names' '}' '}')
docker ps -a --format "$name_fmt" | while read -r name; do
[[ -z $name ]] && continue
case $name in
dokku.postgres.{{example_app}}*|dokku.redis.{{example_app}}*|dokku.postgres.example*|dokku.redis.example*)
echo "removing $name"
docker rm -f "$name" 2>/dev/null || true
;;
esac
done
echo "=== reset: wipe {{data_root}} ==="
rm -rf "{{data_root}}"
# Start Dokku (pulls :latest each time). Waits until healthy.
[script]
up: setup
export DOKKU_DATA_ROOT="{{data_root}}"
{{compose}} pull
{{compose}} up -d
echo "Waiting for Dokku healthcheck"
health=""
for i in {1..90}; do
# Build docker Go-template format string at runtime (avoid just interpolation braces).
fmt=$(printf '%c%c%s%c%c' '{' '{' '.State.Health.Status' '}' '}')
health=$(docker inspect --format=$fmt {{container}} 2>/dev/null || echo missing)
if [[ $health == healthy ]]; then
echo "Dokku is healthy."
exit 0
fi
if [[ $health == unhealthy ]]; then
echo "Dokku reported unhealthy. Logs:" >&2
{{compose}} logs --tail=80
exit 1
fi
sleep 2
done
echo "Timed out waiting for healthy status (last: $health)." >&2
{{compose}} logs --tail=80
exit 1
# Fresh harness: reset any prior state, start Dokku, create example app + services.
[script]
bootstrap_local_dokku: reset_local_dokku up
dk() { docker exec -i {{container}} dokku "$@"; }
echo "=== plugins ==="
dk plugin:list || true
echo "=== apps:create {{example_app}} ==="
dk apps:create {{example_app}}
echo "=== redis:create {{example_app}}-redis ==="
dk redis:create {{example_app}}-redis
echo "=== postgres:create {{example_app}}-db ==="
dk postgres:create {{example_app}}-db
echo "=== link services -> {{example_app}} ==="
dk redis:link {{example_app}}-redis {{example_app}}
dk postgres:link {{example_app}}-db {{example_app}}
echo "=== sample goals (first 30) ==="
dk --quiet help --all | awk '/^ /{ print $1 }' | head -30
echo "Playground ready. dokku --quiet help --all"
echo "Force completion cache refresh: rm -f \"\${XDG_CACHE_HOME:-\$HOME/.cache}/dokku/completion\""
# Stop containers (keeps tmp/dokku-data volume/state).
down:
DOKKU_DATA_ROOT="{{data_root}}" {{compose}} down
# Tear down containers and wipe local Dokku runtime data.
[confirm("Wipe tmp/dokku-data (apps/plugins state) and stop containers?")]
[script]
clean: reset_local_dokku
echo "Clean complete."
logs *args:
DOKKU_DATA_ROOT="{{data_root}}" {{compose}} logs {{args}}
shell:
docker exec -it {{container}} bash
dokku *args:
docker exec -i {{container}} dokku {{args}}
[script]
smoke:
out="$(docker exec -i {{container}} dokku --quiet help --all)"
print -r -- "$out" | awk '/^ /{ print $1 }' | grep -E '^(apps:|postgres:|redis:)' | head -20
print -r -- "$out" | awk '/^ /{ print $1 }' | grep -q '^postgres:'
print -r -- "$out" | awk '/^ /{ print $1 }' | grep -q '^redis:'
echo "smoke ok"
# Run hermetic syntax, registration, parser, dispatch, and cache tests.
test:
zsh tests/completion_test.zsh unit
# Run the safe tests plus read-only completion checks against the live harness.
test_integration: test
zsh tests/completion_test.zsh integration
# Create and remove one uniquely named app to verify dynamic inventory updates.
test_integration_dynamic: test_integration
zsh tests/completion_test.zsh dynamic
# Set publish permissions, update metadata, and protect master.
github_setup: github_repo_permissions_create github_repo_set_metadata github_ruleset_protect_master_create
GITHUB_PROTECT_MASTER_RULESET := """
{
"name": "Protect master from force pushes",
"target": "branch",
"enforcement": "active",
"conditions": {
"ref_name": {
"include": ["refs/heads/master"],
"exclude": []
}
},
"rules": [
{
"type": "non_fast_forward"
}
]
}
"""
[private]
_github_repo:
gh repo view --json nameWithOwner -q .nameWithOwner
# Delete the protect-master ruleset if present.
github_ruleset_protect_master_delete:
repo=$(just _github_repo) && \
ruleset_name=$(echo '{{GITHUB_PROTECT_MASTER_RULESET}}' | jq -r .name) && \
ruleset_id=$(gh api repos/$repo/rulesets --jq ".[] | select(.name == \"$ruleset_name\") | .id") && \
(([ -n "${ruleset_id}" ] || (echo "No ruleset found" && exit 0)) || gh api --method DELETE repos/$repo/rulesets/$ruleset_id)
# Prevent force-push and other non-fast-forward updates on master.
github_ruleset_protect_master_create: github_ruleset_protect_master_delete
gh api --method POST repos/$(just _github_repo)/rulesets --input - <<< '{{GITHUB_PROTECT_MASTER_RULESET}}'
# Allow workflows to write and approve PR reviews (e.g. release-please without PAT).
github_repo_permissions_create:
repo_path=$(gh repo view --json nameWithOwner --jq '.nameWithOwner') && \
gh api --method PUT "/repos/${repo_path}/actions/permissions/workflow" \
-f default_workflow_permissions=write \
-F can_approve_pull_request_reviews=true && \
gh api "/repos/${repo_path}/actions/permissions/workflow"
# Sync GitHub description, homepage, and topics from metadata.json.
github_repo_set_metadata:
gh repo edit \
--description "$(jq -r '.description' metadata.json)" \
--homepage "$(jq -r '.homepage' metadata.json)" \
--add-topic "$(jq -r '.keywords | join(",")' metadata.json)"
# Logs of the last failed build workflow for the current branch.
[script]
github_last_build_failure:
BRANCH=$(git branch --show-current)
JSON=$(gh run list -b "$BRANCH" -L 20 --json databaseId,conclusion,workflowName)
TARGET=$(echo "$JSON" | jq 'map(select(.workflowName | test("build"; "i"))) | .[0]')
if [[ "$TARGET" == "null" ]]; then
echo "No 'build' workflows found in the last 20 runs for $BRANCH."
exit 0
fi
CONCLUSION=$(echo "$TARGET" | jq -r .conclusion)
ID=$(echo "$TARGET" | jq -r .databaseId)
if [[ "$CONCLUSION" == "success" ]]; then
echo "latest build succeeded"
else
GH_PAGER=cat gh run view "$ID" --log-failed
fi
# Rerun failed jobs for the last failed build workflow on the current branch.
[script]
github_rerun_failed:
BRANCH=$(git branch --show-current)
JSON=$(gh run list -b "$BRANCH" -s failure -L 20 --json databaseId,workflowName)
ID=$(echo "$JSON" | jq -r 'map(select(.workflowName | test("build"; "i"))) | .[0].databaseId')
if [[ "$ID" == "null" ]]; then
echo "No failed 'build' workflows found for $BRANCH."
exit 0
fi
echo "Rerunning failed jobs for run $ID..."
gh run rerun "$ID" --failed