Repository navigation
131 lines (123 loc) · 6.23 KB
/
Copy pathcompose-validation.yml
File metadata and controls
131 lines (123 loc) · 6.23 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
name: Validate Compose files
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
validate:
name: Compose files
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Clone this repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check the service list in README.md
run: bash .github/scripts/check-service-list.sh
# arcane-registry.json lists the stacks for the Arcane template registry.
# The script rebuilds it from the service rows in README.md and the files
# of each stack. When the result differs from the committed file, the
# author of the pull request runs the script and commits the file.
- name: Check the Arcane registry
if: ${{ !cancelled() }}
run: |
python3 .github/scripts/build-arcane-registry.py
if ! git diff --quiet -- arcane-registry.json; then
echo "::error file=arcane-registry.json::arcane-registry.json is out of date. Run python3 .github/scripts/build-arcane-registry.py from the repository root and commit the file."
exit 1
fi
# Some stacks require the user to set their own secrets and stop with
# "required variable X is missing". Supply a dummy value for those and
# retry, so that the rest of the file is still checked. The template
# leaves SERVICE and IMAGE_URL empty, so it starts with dummy values for
# both. A variable that compose.yaml uses but .env does not define
# ("The X variable is not set") is an error, and so is a required
# variable that .env does not list or a Serve configuration that is not
# valid JSON. Compose leaves a config that no service uses out of its
# output, so a second pass without interpolation reads those. This step
# also runs when the service list check above fails, so that one run
# reports both.
- name: Run docker compose config
if: ${{ !cancelled() }}
shell: bash
run: |
docker compose version
status=0
for dir in services/*/ templates/service-template/; do
vars=()
if [ "$dir" = templates/service-template/ ]; then
vars=(SERVICE IMAGE_URL)
fi
ok=0
for _ in $(seq 1 30); do
if out=$(cd "$dir" && env "${vars[@]/%/=dummy}" docker compose config --quiet 2>&1); then
ok=1
unset_vars=$(sed -nE 's/.*The \\?"([A-Za-z0-9_]+)\\?" variable is not set.*/\1/p' <<<"$out" | sort -u | paste -sd' ' -)
if [ -n "$unset_vars" ]; then
echo "::error file=${dir}compose.yaml::Used in compose.yaml but not defined in ${dir}.env: ${unset_vars}"
status=1
fi
for v in "${vars[@]}"; do
grep -qE "^${v}=" "${dir}.env" || { echo "::error file=${dir}compose.yaml::${v} is required but not listed in ${dir}.env"; status=1; }
done
if ! (cd "$dir" && env "${vars[@]/%/=dummy}" docker compose config --format json 2>/dev/null \
| jq -r '(.configs // {}) | to_entries[] | select(.key | startswith("ts-serve")) | .value.content' \
| jq empty); then
echo "::error file=${dir}compose.yaml::The Tailscale Serve configuration is not valid JSON"
status=1
fi
used=$(cd "$dir" && env "${vars[@]/%/=dummy}" docker compose config --format json 2>/dev/null \
| jq -c '[(.configs // {}) | keys[] | select(startswith("ts-serve"))]') || used='[]'
raw=$(cd "$dir" && env "${vars[@]/%/=dummy}" docker compose config --no-interpolate --format json 2>/dev/null) || raw='{}'
while read -r name; do
if ! jq -r --arg n "$name" '.configs[$n].content' <<<"$raw" | jq empty; then
echo "::error file=${dir}compose.yaml::The Tailscale Serve configuration ${name}, which the stack does not use by default, is not valid JSON"
status=1
fi
done < <(jq -r --argjson used "$used" '(.configs // {}) | keys[] | select(startswith("ts-serve")) | select(. as $k | $used | index($k) | not)' <<<"$raw")
break
fi
missing=$(grep -oE 'required variable [A-Za-z0-9_]+' <<<"$out" | awk '{print $3}' | sort -u | grep -vxFf <(printf '%s\n' "${vars[@]}") || true)
if [ -z "$missing" ]; then
echo "::error file=${dir}compose.yaml::docker compose config failed in ${dir}"
echo "$out"
status=1
ok=2
break
fi
mapfile -t new <<<"$missing"
vars+=("${new[@]}")
done
if [ "$ok" = 0 ]; then
echo "::error file=${dir}compose.yaml::too many required variables in ${dir}"
status=1
fi
done
exit $status
# A container that uses the network of the Tailscale sidecar must
# restart with it, and the application must wait until it is healthy.
# The step above reports stacks that do not parse.
- name: Check the sidecar dependencies
if: ${{ !cancelled() }}
run: bash .github/scripts/check-sidecar.sh
# Line 11 of .gitignore is "Icon[<CR>]", with a carriage-return byte
# between the brackets. Editors often turn it into a newline, which
# breaks the rule without any visible change in the diff.
- name: Check the Icon rule in .gitignore
if: ${{ !cancelled() }}
shell: bash
run: |
if ! grep -qP '^Icon\[\r\]$' .gitignore; then
echo "::error file=.gitignore,line=11::The Icon rule lost its carriage return. Line 11 must be Icon[<CR>], as one line. Restore the file with: git checkout origin/main -- .gitignore, then add your change again without saving the file in an editor that rewrites line endings."
exit 1
fi