Skip to content

Wait for Caprover ready #7

Wait for Caprover ready

Wait for Caprover ready #7

name: Test Stack Deploy
on:
push:
branches: [ main, test-stack_deploy ]
pull_request:
branches: [ main ]
jobs:
test-stack-deploy:
runs-on: ubuntu-latest
services:
docker:
image: docker:dind
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Docker
run: |
# Docker is pre-installed on GitHub Actions runners
docker --version
docker info
- name: Initialize Docker Swarm
run: |
docker swarm init --advertise-addr 127.0.0.1
- name: Install CapRover
run: |
# Add CapRover domain to hosts file for proper routing
echo "127.0.0.1 captain.localhost.test" | sudo tee -a /etc/hosts
echo "127.0.0.1 localhost.test" | sudo tee -a /etc/hosts
# Install CapRover CLI
npm install -g caprover
# Install CapRover server
docker run -d \
--name captain-captain \
-p 80:80 -p 443:443 -p 3000:3000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v captain-root-dir:/captain \
caprover/caprover:latest
# Wait for CapRover to be ready
echo "Waiting for CapRover to start..."
for i in {1..30}; do
if docker logs captain-captain 2>&1 | grep -q "Captain is available"; then
echo "CapRover is ready!"
break
fi
echo "Waiting... ($i/30)"
sleep 5
done
# Verify DNS resolution
echo "Testing DNS resolution:"
nslookup captain.localhost.test || echo "nslookup failed"
ping -c 1 captain.localhost.test || echo "ping failed"
# Wait for HTTP endpoint to be available
echo "Waiting for CapRover HTTP endpoint..."
for i in {1..30}; do
if curl -f -s http://captain.localhost.test/api/v2/login >/dev/null 2>&1; then
echo "CapRover HTTP endpoint is ready!"
break
elif curl -f -s http://127.0.0.1:3000/api/v2/login >/dev/null 2>&1; then
echo "CapRover HTTP endpoint is ready on localhost!"
break
fi
echo "Waiting for HTTP endpoint... ($i/30)"
sleep 5
done
# Setup CapRover
echo "Setting up CapRover..."
docker exec captain-captain caprover-root setup \
--captainPassword test-captain-password \
--rootDomain localhost.test \
--skipVerifyingDomains \
--force || echo "Setup may have failed, continuing..."
- name: Install Python dependencies
run: |
cd caprover
pip install -r requirements.txt
# Install unreleased caprover-api from git (as per INSTALL_GC_STACK.md)
git clone https://github.com/IamJeffG/Caprover-API.git /tmp/caprover-api
cd /tmp/caprover-api
git checkout fix-oneclick-repo
python setup.py install
- name: Test stack_deploy.py dry run
run: |
cd caprover
python stack_deploy.py --config-file stack.test.yaml --dry-run
- name: Test stack_deploy.py with minimal deployment
run: |
cd caprover
# Only deploy postgres and filebrowser for testing
timeout 600 python stack_deploy.py --config-file stack.test.yaml || {
echo "Deployment failed or timed out"
exit 1
}
continue-on-error: true
- name: Verify deployment
run: |
# Check if CapRover is still running
docker ps | grep captain-captain
# Check deployed apps (if any)
docker service ls || echo "No services deployed"
- name: Cleanup
if: always()
run: |
docker swarm leave --force || true
docker stop captain-captain || true
docker rm captain-captain || true