This commit is contained in:
1 parent
eeed160755
commit
79e5bf9023
1 file changed
+20
-3
+20
-3
@@ -1,4 +1,4 @@
|
||||
name: FastAPI CI
|
||||
name: FastAPI CI/CD
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -7,7 +7,7 @@ on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
test-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -30,12 +30,29 @@ jobs:
|
||||
- name: Build Docker image
|
||||
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'
|
||||
run: |
|
||||
docker rm -f fastapi-demo || true
|
||||
|
||||
docker run -d \
|
||||
--name fastapi-demo \
|
||||
--network web \
|
||||
--restart unless-stopped \
|
||||
-p 127.0.0.1:8000:8000 \
|
||||
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
|
||||
Reference in new issue
Block a user