1+ name : CI/CD with Docker Compose Linux Host
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ jobs :
9+ build-and-test :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - name : Checkout code
13+ uses : actions/checkout@v4
14+
15+ - name : Set up Docker Buildx
16+ uses : docker/setup-buildx-action@v3
17+
18+ - name : Install Docker Compose
19+ uses : docker/setup-buildx-action@v3 # This action also sets up Compose
20+ with :
21+ install-compose : true
22+
23+ - name : Build and start Docker Compose services
24+ run : docker compose -f compose_linux_host.yaml up --build
25+
26+ - name : Wait for services to be healthy (optional, but recommended)
27+ # You can use a dedicated action or a script to wait for health checks
28+ # Example using a simple sleep (adjust as needed for your application)
29+ run : sleep 120
30+
31+ - name : Test noVNC is up
32+ run : |
33+ SERVICE_URL="http://localhost:3080"
34+ EXPECTED_RESPONSE="200"
35+ RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $SERVICE_URL)
36+ if [ "$RESPONSE" == "$EXPECTED_RESPONSE" ]; then
37+ echo "Test Passed: Service returned expected response."
38+ echo "Expected: $EXPECTED_RESPONSE"
39+ echo "Actual: $RESPONSE"
40+ exit 0
41+ else
42+ echo "Test Failed: Service response did not match expected response."
43+ echo "Expected: $EXPECTED_RESPONSE"
44+ echo "Actual: $RESPONSE"
45+ exit 1
46+ fi
47+
48+ - name : Test code-server is up
49+ run : |
50+ SERVICE_URL="http://localhost:3081"
51+ EXPECTED_RESPONSE="200"
52+ RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $SERVICE_URL)
53+ if [ "$RESPONSE" == "$EXPECTED_RESPONSE" ]; then
54+ echo "Test Passed: Service returned expected response."
55+ echo "Expected: $EXPECTED_RESPONSE"
56+ echo "Actual: $RESPONSE"
57+ exit 0
58+ else
59+ echo "Test Failed: Service response did not match expected response."
60+ echo "Expected: $EXPECTED_RESPONSE"
61+ echo "Actual: $RESPONSE"
62+ exit 1
63+ fi
64+ - name : Test sshd is up
65+ run : |
66+ EXPECTED_RESPONSE="1"
67+ RESPONSE=$(netstat -an | grep 0.0.0.0:3022 | grep tcp | grep LISTEN | wc -l)
68+ if [ "$RESPONSE" == "$EXPECTED_RESPONSE" ]; then
69+ echo "Test Passed: Service returned expected response."
70+ echo "Expected: $EXPECTED_RESPONSE"
71+ echo "Actual: $RESPONSE"
72+ exit 0
73+ else
74+ echo "Test Failed: Service response did not match expected response."
75+ echo "Expected: $EXPECTED_RESPONSE"
76+ echo "Actual: $RESPONSE"
77+ exit 1
78+ fi
79+
80+ - name : Check running containers (optional for debugging)
81+ run : docker ps -a
82+
83+ - name : Stop and remove containers
84+ run : docker compose -f compose_linux_host.yaml down
0 commit comments