Add automatic deployment
FastAPI CI/CD / test-and-deploy (push) Successful in 1m33s

This commit is contained in:
m1000 committed 2026-11-13 03:07:28 +03:00
1 parent eeed160755
commit 79e5bf9023
1 file changed
+20 -3
+20 -3
View File
@@ -1,4 +1,4 @@
name: FastAPI CI name: FastAPI CI/CD
on: on:
push: push:
@@ -7,7 +7,7 @@ on:
pull_request: pull_request:
jobs: jobs:
test: test-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -30,12 +30,29 @@ jobs:
- name: Build Docker image - name: Build Docker image
run: docker build -t fastapi-demo:latest . run: docker build -t fastapi-demo:latest .
- name: Deploy application - name: Deploy to home server
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: | run: |
docker rm -f fastapi-demo || true docker rm -f fastapi-demo || true
docker run -d \ docker run -d \
--name fastapi-demo \ --name fastapi-demo \
--network web \
--restart unless-stopped \ --restart unless-stopped \
-p 127.0.0.1:8000:8000 \ -p 127.0.0.1:8000:8000 \
fastapi-demo:latest fastapi-demo:latest
- name: Health check
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
for i in $(seq 1 15); do
if docker exec fastapi-demo python -c \
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2)"; then
echo "Deployment successful!"
exit 0
fi
sleep 2
done
docker logs fastapi-demo
exit 1