-
Notifications
You must be signed in to change notification settings - Fork 5
140 lines (120 loc) · 3.78 KB
/
Copy pathdocker.yml
File metadata and controls
140 lines (120 loc) · 3.78 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
name: Docker Build and Test
on:
push:
branches: [ main, develop ]
paths:
- 'Dockerfile'
- 'docker-compose*.yml'
- 'requirements.txt'
- '*.py'
pull_request:
branches: [ main ]
paths:
- 'Dockerfile'
- 'docker-compose*.yml'
- 'requirements.txt'
- '*.py'
jobs:
docker-build:
name: Build and Test Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: workflows-doc:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
run: |
# Test container starts successfully with CI mode
docker run --name test-container -d -p 8002:8000 -e CI=true workflows-doc:test
# Wait for container to be ready (max 30 seconds)
echo "Waiting for container to start..."
for i in {1..30}; do
if curl -f http://localhost:8002/api/stats 2>/dev/null; then
echo "Container is ready!"
break
fi
if [ $i -eq 30 ]; then
echo "Container failed to start within 30 seconds"
docker logs test-container
exit 1
fi
echo "Attempt $i/30..."
sleep 1
done
# Test container logs for errors
docker logs test-container
# Cleanup
docker stop test-container
docker rm test-container
- name: Test Docker Compose
run: |
# Test basic docker-compose with CI mode
CI=true docker compose -f docker-compose.yml up -d --build
# Wait for services (max 30 seconds)
echo "Waiting for services to start..."
for i in {1..30}; do
if curl -f http://localhost:8000/api/stats 2>/dev/null; then
echo "Services are ready!"
break
fi
if [ $i -eq 30 ]; then
echo "Services failed to start within 30 seconds"
docker compose logs
exit 1
fi
echo "Attempt $i/30..."
sleep 1
done
# Show logs
docker compose logs --tail=50
# Cleanup
docker compose down
- name: Test security scanning
run: |
# Install Trivy
sudo apt-get update
sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy
# Scan the built image using our configuration
# Exit code 0 = report only mode (won't fail the build)
trivy image \
--config trivy.yaml \
--ignorefile .trivyignore \
--exit-code 0 \
--severity HIGH,CRITICAL \
workflows-doc:test
multi-platform:
name: Test Multi-platform Build
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build multi-platform image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
tags: workflows-doc:multi-platform
cache-from: type=gha
cache-to: type=gha,mode=max
# Don't load multi-platform images (not supported)
push: false