-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (198 loc) · 7.35 KB
/
Copy pathtest.yaml
File metadata and controls
237 lines (198 loc) · 7.35 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
234
235
236
237
name: Docker Infrastructure Test
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
docker-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: install Docker compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Create test environment file
run: |
cd src
cat > .env << EOF
MYSQL_ROOT_PASSWORD=test_root_pass_123
MYSQL_DATABASE=test_wordpress
MYSQL_USER=test_user
MYSQL_PASSWORD=test_user_pass_123
EOF
- name: Generate test SSL certificates
run: |
cd src/nginx
openssl req -x509 -nodes -days 1 -newkey rsa:2048 \
-keyout server.key \
-out server.crt \
-subj "/C=US/ST=Test/L=Test/O=Test/CN=localhost"
- name: Build Docker images
run: |
cd src
docker-compose build --no-cache
- name: Start services
run: |
cd src
docker-compose up -d
- name: Wait for services to be ready
run: |
echo "Waiting for MariaDB to be ready..."
timeout 60 bash -c 'until docker exec mariadb mysqladmin ping -h localhost --silent; do sleep 2; done'
echo "Waiting for Nginx to be ready..."
timeout 30 bash -c 'until docker exec nginx nginx -t; do sleep 2; done'
- name: Check container status
run: |
cd src
docker-compose ps
# Check if containers are running
if ! docker-compose ps | grep -q "Up"; then
echo "❌ Some containers are not running"
docker-compose logs
exit 1
fi
echo "✅ All containers are running"
- name: Test MariaDB connectivity
run: |
echo "Testing MariaDB connection..."
# Test root connection
docker exec mariadb mysql -u root -ptest_root_pass_123 -e "SELECT 1;" || {
echo "❌ Root connection failed"
exit 1
}
echo "✅ Root connection successful"
# Test user connection and database access
docker exec mariadb mysql -u test_user -ptest_user_pass_123 test_wordpress -e "SELECT 1;" || {
echo "❌ User connection failed"
exit 1
}
echo "✅ User connection successful"
# Test database exists
docker exec mariadb mysql -u root -ptest_root_pass_123 -e "SHOW DATABASES;" | grep test_wordpress || {
echo "❌ Database test_wordpress not found"
exit 1
}
echo "✅ Database exists"
- name: Test Nginx SSL configuration
run: |
echo "Testing Nginx SSL configuration..."
# Test SSL certificate
docker exec nginx openssl x509 -in /etc/nginx/certs/server.crt -text -noout | grep "CN=localhost" || {
echo "❌ SSL certificate invalid"
exit 1
}
echo "✅ SSL certificate valid"
# Test nginx configuration
docker exec nginx nginx -t || {
echo "❌ Nginx configuration invalid"
exit 1
}
echo "✅ Nginx configuration valid"
- name: Test HTTP to HTTPS redirect
run: |
echo "Testing HTTP to HTTPS redirect..."
# Add port 80 temporarily for this test
cd src
docker-compose down
# Modify compose file to expose port 80
sed -i 's/- "443:443"/- "80:80"\n - "443:443"/' docker-compose.yaml
docker-compose up -d
sleep 10
# Test redirect
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:80 || echo "000")
if [ "$response" = "301" ] || [ "$response" = "302" ]; then
echo "✅ HTTP redirect working (Status: $response)"
else
echo "❌ HTTP redirect not working (Status: $response)"
docker-compose logs nginx
exit 1
fi
- name: Test HTTPS endpoint
run: |
echo "Testing HTTPS endpoint..."
# Test HTTPS response
response=$(curl -k -s https://localhost:443)
if echo "$response" | grep -q "Connected Securely over TLS"; then
echo "✅ HTTPS endpoint working"
echo "Response: $response"
else
echo "❌ HTTPS endpoint not working"
echo "Response: $response"
docker-compose logs nginx
exit 1
fi
- name: Test data persistence
run: |
echo "Testing data persistence..."
cd src
# Create test data
docker exec mariadb mysql -u test_user -ptest_user_pass_123 test_wordpress -e "
CREATE TABLE test_table (id INT PRIMARY KEY, data VARCHAR(100));
INSERT INTO test_table VALUES (1, 'persistence_test');
"
# Restart containers
docker-compose restart mariadb
sleep 15
# Check if data persists
result=$(docker exec mariadb mysql -u test_user -ptest_user_pass_123 test_wordpress -e "SELECT data FROM test_table WHERE id=1;" -s -N)
if [ "$result" = "persistence_test" ]; then
echo "✅ Data persistence working"
else
echo "❌ Data persistence failed"
exit 1
fi
- name: Security checks
run: |
echo "Running security checks..."
# Check if containers run as non-root
nginx_user=$(docker exec nginx whoami)
mariadb_user=$(docker exec mariadb whoami)
echo "Nginx running as: $nginx_user"
echo "MariaDB running as: $mariadb_user"
# Check SSL protocols
docker exec nginx nginx -T | grep -q "ssl_protocols.*TLSv1.2.*TLSv1.3" || {
echo "❌ SSL protocols not properly configured"
exit 1
}
echo "✅ SSL protocols properly configured"
# Check for anonymous users (should be empty)
anonymous_count=$(docker exec mariadb mysql -u root -ptest_root_pass_123 -e "SELECT COUNT(*) FROM mysql.user WHERE User='';" -s -N)
if [ "$anonymous_count" = "0" ]; then
echo "✅ No anonymous users found"
else
echo "❌ Anonymous users found"
exit 1
fi
- name: Performance checks
run: |
echo "Running performance checks..."
# Check memory usage
docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.CPUPerc}}"
# Test multiple concurrent connections to nginx
for i in {1..5}; do
curl -k -s https://localhost:443 > /dev/null &
done
wait
echo "✅ Concurrent connections handled"
- name: Cleanup and show logs on failure
if: failure()
run: |
cd src
echo "=== Docker Compose Logs ==="
docker-compose logs
echo "=== Container Status ==="
docker-compose ps
echo "=== System Info ==="
docker system df
docker-compose down -v
- name: Cleanup on success
if: success()
run: |
cd src
docker-compose down -v
docker system prune -f