-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.test.yml
More file actions
211 lines (196 loc) · 5.63 KB
/
docker-compose.test.yml
File metadata and controls
211 lines (196 loc) · 5.63 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
# Docker Compose Test Environment
# Used to validate templates and test the Docker Compose integration
# Run: docker-compose -f docker-compose.test.yml up
version: '3.8'
networks:
test-network:
driver: bridge
volumes:
test-postgres-data:
test-redis-data:
test-mongo-data:
services:
# =====================================
# Template Testing Services
# =====================================
test-python-template:
build:
context: templates/compose
dockerfile: Dockerfile.python
container_name: test-python-template
volumes:
- ./test-workspace/python:/workspace
networks:
- test-network
environment:
- PYTHONDONTWRITEBYTECODE=1
- PYTHONUNBUFFERED=1
command: |
bash -c "
echo '✅ Python template loaded successfully'
python --version
pip list | head -10
echo 'Testing database connectivity...'
python -c 'import psycopg2; print(\"✅ PostgreSQL client available\")'
python -c 'import redis; print(\"✅ Redis client available\")'
echo '✅ All Python template tests passed'
"
depends_on:
- test-postgres
- test-redis
profiles:
- templates
test-nodejs-template:
build:
context: templates/compose
dockerfile: Dockerfile.nodejs
container_name: test-nodejs-template
volumes:
- ./test-workspace/nodejs:/workspace
networks:
- test-network
environment:
- NODE_ENV=test
command: |
bash -c "
echo '✅ Node.js template loaded successfully'
node --version
npm --version
echo 'Testing global packages...'
which typescript && echo '✅ TypeScript installed'
which nodemon && echo '✅ Nodemon installed'
which prisma && echo '✅ Prisma installed'
echo '✅ All Node.js template tests passed'
"
profiles:
- templates
# =====================================
# Service Stack Testing
# =====================================
test-postgres:
image: postgres:15-alpine
container_name: test-postgres
environment:
- POSTGRES_USER=testuser
- POSTGRES_PASSWORD=testpass
- POSTGRES_DB=testdb
volumes:
- test-postgres-data:/var/lib/postgresql/data
ports:
- "15432:5432" # Different port to avoid conflicts
networks:
- test-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U testuser"]
interval: 5s
timeout: 5s
retries: 5
profiles:
- databases
test-mongodb:
image: mongo:7
container_name: test-mongodb
environment:
- MONGO_INITDB_DATABASE=testdb
volumes:
- test-mongo-data:/data/db
ports:
- "37017:27017" # Different port to avoid conflicts
networks:
- test-network
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 5s
timeout: 5s
retries: 5
profiles:
- databases
test-redis:
image: redis:7-alpine
container_name: test-redis
volumes:
- test-redis-data:/data
ports:
- "16379:6379" # Different port to avoid conflicts
networks:
- test-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
profiles:
- databases
# =====================================
# Integration Tests
# =====================================
integration-test:
build:
context: .
dockerfile: Dockerfile.test
container_name: integration-tests
volumes:
- ./:/workspace
- /var/run/docker.sock:/var/run/docker.sock
networks:
- test-network
environment:
- TEST_ENV=docker
- POSTGRES_URL=postgresql://testuser:testpass@test-postgres:5432/testdb
- REDIS_URL=redis://test-redis:6379
- MONGODB_URI=mongodb://test-mongodb:27017/testdb
command: |
bash -c "
echo '🧪 Running integration tests...'
echo 'Testing template generation...'
bash -n scripts/dev-container-quickstart.sh && echo '✅ Script syntax valid'
echo 'Testing Docker Compose configurations...'
for file in templates/compose/*.yml; do
docker-compose -f \$file config > /dev/null 2>&1 && echo \"✅ \$file is valid\" || echo \"❌ \$file has errors\"
done
echo '🎉 Integration tests complete'
"
depends_on:
- test-postgres
- test-redis
- test-mongodb
profiles:
- integration
# =====================================
# Smoke Tests (Quick validation)
# =====================================
smoke-test:
image: alpine:latest
container_name: smoke-tests
networks:
- test-network
command: |
sh -c "
echo '🔥 Running smoke tests...'
apk add --no-cache postgresql-client redis mongodb-tools curl
echo 'Testing connectivity...'
pg_isready -h test-postgres -p 5432 && echo '✅ PostgreSQL reachable'
redis-cli -h test-redis ping && echo '✅ Redis reachable'
echo '✅ Smoke tests passed'
"
depends_on:
- test-postgres
- test-redis
profiles:
- smoke
# Usage Examples:
#
# Test everything:
# docker-compose -f docker-compose.test.yml --profile templates --profile databases --profile integration up
#
# Test just databases:
# docker-compose -f docker-compose.test.yml --profile databases up
#
# Test just templates:
# docker-compose -f docker-compose.test.yml --profile templates --profile databases up
#
# Run smoke tests:
# docker-compose -f docker-compose.test.yml --profile databases --profile smoke up
#
# Clean up:
# docker-compose -f docker-compose.test.yml down -v