Skip to content

Commit ad49f97

Browse files
committed
Add GitHub Actions workflow for Docker Compose CI with CouchDB and MongoDB integration tests
- Introduced `docker-compose.yml` GitHub Actions workflow for continuous integration. - Configured matrix testing for CouchDB and MongoDB setups. - Added integration tests to verify database coexistence. - Implemented automated cleanup processes to ensure isolation between test runs.
1 parent acdb72b commit ad49f97

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Docker Compose CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch: # Allow manual triggering
9+
10+
jobs:
11+
docker-compose-test:
12+
runs-on: ubuntu-24.04
13+
14+
strategy:
15+
matrix:
16+
database: [couchdb, mongodb]
17+
fail-fast: false # Continue testing other databases even if one fails
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Make test script executable
27+
run: chmod +x test-docker-setups.sh
28+
29+
- name: Set database credentials
30+
run: |
31+
case "${{ matrix.database }}" in
32+
couchdb)
33+
echo "COUCHDB_USERNAME=ci_test_admin" >> $GITHUB_ENV
34+
echo "COUCHDB_PASSWORD=ci_test_password_$(date +%s)" >> $GITHUB_ENV
35+
echo "COUCHDB_DATABASE=ci_test_notes" >> $GITHUB_ENV
36+
;;
37+
mongodb)
38+
echo "MONGODB_USERNAME=ci_test_user" >> $GITHUB_ENV
39+
echo "MONGODB_PASSWORD=ci_test_password_$(date +%s)" >> $GITHUB_ENV
40+
echo "MONGODB_DATABASE=ci_test_notes" >> $GITHUB_ENV
41+
;;
42+
esac
43+
44+
- name: Display environment info
45+
run: |
46+
echo "Testing database: ${{ matrix.database }}"
47+
echo "Docker version:"
48+
docker --version
49+
echo "Docker Compose version:"
50+
docker compose version
51+
echo "Available disk space:"
52+
df -h
53+
echo "Available memory:"
54+
free -h
55+
56+
- name: Clean up any existing containers
57+
run: |
58+
# Clean up any potentially conflicting containers/networks
59+
docker container prune -f || true
60+
docker network prune -f || true
61+
docker volume prune -f || true
62+
63+
- name: Test ${{ matrix.database }} setup
64+
run: |
65+
echo "🚀 Starting ${{ matrix.database }} test..."
66+
./test-docker-setups.sh ${{ matrix.database }}
67+
68+
- name: Show container logs on failure
69+
if: failure()
70+
run: |
71+
echo "=== Docker containers ==="
72+
docker ps -a
73+
echo "=== Docker networks ==="
74+
docker network ls
75+
echo "=== Docker volumes ==="
76+
docker volume ls
77+
78+
# Show logs for any running containers
79+
for container in $(docker ps --format "{{.Names}}" 2>/dev/null || true); do
80+
echo "=== Logs for $container ==="
81+
docker logs "$container" || true
82+
done
83+
84+
- name: Clean up after test
85+
if: always()
86+
run: |
87+
echo "🧹 Cleaning up..."
88+
89+
# Stop and remove containers for this database
90+
case "${{ matrix.database }}" in
91+
couchdb)
92+
docker compose -f docker-compose.couchdb.yml down -v --remove-orphans || true
93+
;;
94+
mongodb)
95+
docker compose -f docker-compose.mongodb.yml down -v --remove-orphans || true
96+
;;
97+
esac
98+
99+
# Additional cleanup
100+
docker container prune -f || true
101+
docker network prune -f || true
102+
docker volume prune -f || true
103+
104+
echo "✅ Cleanup completed"
105+
106+
# Job to verify both databases can coexist (not run simultaneously)
107+
integration-test:
108+
runs-on: ubuntu-24.04
109+
needs: docker-compose-test
110+
111+
steps:
112+
- name: Checkout code
113+
uses: actions/checkout@v4
114+
115+
- name: Set up Docker Buildx
116+
uses: docker/setup-buildx-action@v3
117+
118+
- name: Make test script executable
119+
run: chmod +x test-docker-setups.sh
120+
121+
- name: Test both databases sequentially
122+
run: |
123+
echo "🔄 Testing both databases in sequence..."
124+
./test-docker-setups.sh both
125+
126+
- name: Show final status
127+
if: always()
128+
run: |
129+
echo "=== Final cleanup ==="
130+
docker container prune -f || true
131+
docker network prune -f || true
132+
docker volume prune -f || true
133+
echo "✅ Integration test completed"

0 commit comments

Comments
 (0)