Skip to content

Commit 9885131

Browse files
committed
Use docker swarm for deployment
1 parent 413f2b9 commit 9885131

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,37 @@ jobs:
6161
- name: 🚀 Deploy over SSH
6262
run: |
6363
ssh "${{ secrets.DEPLOY_SERVER }}" << 'EOF'
64+
set -e
6465
mkdir -p ~/lncrawl/appdata
66+
67+
# Initialize Swarm if not already initialized
68+
if ! docker info | grep -q "Swarm: active"; then
69+
echo "Initializing Docker Swarm..."
70+
docker swarm init --advertise-addr 127.0.0.1 || true
71+
fi
72+
73+
# Pull latest image
74+
echo "Pulling latest image..."
6575
docker pull ${{ env.IMAGE_NAME }}:server
66-
docker compose -f ~/lncrawl/compose.yml up -d
76+
77+
# Deploy stack with rolling update
78+
echo "Deploying stack with rolling update..."
79+
docker stack deploy -c ~/lncrawl/compose.yml lncrawl --with-registry-auth
80+
81+
# Wait for service to be healthy
82+
echo "Waiting for service to be healthy..."
83+
ELAPSED=0
84+
while [ $ELAPSED -lt 90 ]; do
85+
echo "Waiting for service to be healthy... ($ELAPSED seconds)"
86+
if curl -sf --max-time 3 "http://localhost:23480/api/ping" > /dev/null 2>&1; then
87+
echo "✅ Service is healthy!"
88+
exit 0
89+
fi
90+
sleep 2
91+
ELAPSED=$((ELAPSED + 2))
92+
done
93+
94+
echo "❌ Service health check failed"
95+
docker service ps lncrawl_server --no-trunc
96+
exit 1
6797
EOF

lncrawl/server/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@
9797
tags=['Admin'],
9898
dependencies=[Depends(ensure_admin)],
9999
)
100+
101+
102+
@router.api_route("/ping", methods=["GET", "HEAD", "OPTIONS"], include_in_schema=False)
103+
def ping() -> str:
104+
return "pong"

scripts/server-compose.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
# SE_SCREEN_WIDTH: "1920"
1616
# SE_SCREEN_HEIGHT: "1080"
1717
# SE_NODE_GRID_URL: "false"
18+
# networks:
19+
# - lncrawl_network
1820
# deploy:
1921
# resources:
2022
# limits:
@@ -33,6 +35,14 @@ services:
3335
POSTGRES_DB: lncrawl
3436
volumes:
3537
- pgdata:/var/lib/postgresql/data
38+
networks:
39+
- lncrawl_network
40+
healthcheck:
41+
test: ["CMD-SHELL", "pg_isready -U pguser -d lncrawl"]
42+
interval: 5s
43+
timeout: 3s
44+
retries: 5
45+
start_period: 10s
3646
deploy:
3747
resources:
3848
limits:
@@ -55,19 +65,44 @@ services:
5565
- DATABASE_URL=postgresql+psycopg://pguser:pgpass@postgres:5432/lncrawl
5666
volumes:
5767
- ./appdata:/data
58-
depends_on:
59-
# - chrome
60-
- postgres
68+
networks:
69+
- lncrawl_network
6170
extra_hosts:
6271
- "host.docker.internal:host-gateway"
72+
healthcheck:
73+
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://0.0.0.0:8080/api/ping || exit 1"]
74+
interval: 10s
75+
timeout: 5s
76+
retries: 3
77+
start_period: 30s
6378
deploy:
79+
replicas: 1
80+
update_config:
81+
order: start-first
82+
parallelism: 1
83+
delay: 10s
84+
failure_action: rollback
85+
monitor: 30s
86+
rollback_config:
87+
order: stop-first
88+
parallelism: 1
89+
restart_policy:
90+
condition: on-failure
91+
delay: 5s
92+
max_attempts: 3
93+
window: 120s
6494
resources:
6595
limits:
6696
cpus: '3.50'
6797
memory: 5G
6898
reservations:
6999
cpus: '2.00'
70100
memory: 3G
71-
101+
102+
networks:
103+
lncrawl_network:
104+
driver: overlay
105+
attachable: true
106+
72107
volumes:
73108
pgdata:

0 commit comments

Comments
 (0)