-
-
Notifications
You must be signed in to change notification settings - Fork 2
149 lines (125 loc) Β· 6.18 KB
/
Copy pathdocker-compose-validate.yml
File metadata and controls
149 lines (125 loc) Β· 6.18 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
---
# This workflow validates docker-compose configuration including syntax,
# service definitions, dependencies, and security best practices.
# It is called by the build.yml workflow.
name: Docker Compose Validate
on:
workflow_call:
env:
CI: true
COMPOSE_VERSION: "v2.32.0"
permissions:
contents: read
jobs:
validate-compose:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: π Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: π§ Install docker-compose
uses: alexellis/arkade-get@1eef818e467c387d3f50cfe0d2c565d1cbe82b03 # master
with:
docker-compose: ${{ env.COMPOSE_VERSION }}
- name: π Validate docker-compose syntax
run: |
docker-compose config --quiet
echo "β
docker-compose.yml is valid"
if [ -f docker-compose.prod.yml ]; then
docker-compose -f docker-compose.yml -f docker-compose.prod.yml config --quiet
echo "β
docker-compose.prod.yml overlay is valid"
fi
- name: π Check docker-compose services
run: |
services=$(docker-compose config --services | sort | tr "\n" " " | sed "s/ $//")
expected="api brainzgraphinator brainztableinator dashboard explore"
expected="$expected extractor-discogs extractor-musicbrainz graphinator"
expected="$expected insights neo4j postgres rabbitmq redis schema-init tableinator"
if [ "$services" != "$expected" ]; then
echo "β Service mismatch!"
echo "Expected: $expected"
echo "Got: $services"
exit 1
fi
echo "β
All expected services are defined"
- name: π Validate service dependencies
run: |
# Check that services have correct dependencies
deps=$(docker-compose config | yq eval '.services.dashboard.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "api neo4j postgres rabbitmq redis schema-init" ]; then
echo "β Dashboard should depend on api, neo4j, postgres, rabbitmq, redis, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.extractor-discogs.depends_on | keys | .[]' -)
if [ "$deps" != "rabbitmq" ]; then
echo "β Extractor-discogs should only depend on rabbitmq"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.extractor-musicbrainz.depends_on | keys | .[]' -)
if [ "$deps" != "rabbitmq" ]; then
echo "β Extractor-musicbrainz should only depend on rabbitmq"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.brainzgraphinator.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "neo4j rabbitmq schema-init" ]; then
echo "β Brainzgraphinator should depend on neo4j, rabbitmq, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.graphinator.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "neo4j rabbitmq schema-init" ]; then
echo "β Graphinator should depend on neo4j, rabbitmq, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.explore.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "api schema-init" ]; then
echo "β Explore should depend on api and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.tableinator.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "postgres rabbitmq schema-init" ]; then
echo "β Tableinator should depend on postgres, rabbitmq, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.brainztableinator.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "postgres rabbitmq schema-init" ]; then
echo "β Brainztableinator should depend on postgres, rabbitmq, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.schema-init.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "neo4j postgres" ]; then
echo "β Schema-init should depend on neo4j and postgres"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.insights.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "api postgres redis schema-init" ]; then
echo "β Insights should depend on api, postgres, redis, and schema-init"
exit 1
fi
deps=$(docker-compose config | yq eval '.services.api.depends_on | keys | sort | join(" ")' -)
if [ "$deps" != "neo4j postgres redis schema-init" ]; then
echo "β API should depend on neo4j, postgres, redis, and schema-init"
exit 1
fi
echo "β
Service dependencies are correct"
- name: π‘οΈ Check for security best practices
run: |
# Check that services run as non-root user
for service in api brainzgraphinator brainztableinator dashboard explore \
extractor-discogs extractor-musicbrainz graphinator insights schema-init tableinator; do
user=$(docker-compose config | yq eval ".services.$service.user" -)
if [ -z "$user" ] || [ "$user" = "null" ]; then
echo "β $service should have a user configured"
exit 1
fi
done
echo "β
All services run as non-root user"
# Check security options
for service in api brainzgraphinator brainztableinator dashboard explore \
extractor-discogs extractor-musicbrainz graphinator insights schema-init tableinator; do
security_opt=$(docker-compose config | yq eval ".services.$service.security_opt[]" - | grep "no-new-privileges:true" || true)
if [ -z "$security_opt" ]; then
echo "β $service should have no-new-privileges security option"
exit 1
fi
done
echo "β
Security options are properly set"