Skip to content

Merge pull request #230 from Project-Guideon/develop #28

Merge pull request #230 from Project-Guideon/develop

Merge pull request #230 from Project-Guideon/develop #28

Workflow file for this run

name: Deploy FastAPI
on:
push:
branches: [main]
workflow_dispatch:
env:
IMAGE_PREFIX: ghcr.io/project-guideon
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push fastapi
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: |
${{ env.IMAGE_PREFIX }}/fastapi:latest
${{ env.IMAGE_PREFIX }}/fastapi:${{ github.sha }}
deploy:
needs: build-and-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy FastAPI to server
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd ~/guideon-deploy
docker compose pull fastapi
docker compose up -d fastapi
echo "=== FastAPI Deploy complete ==="
docker compose ps fastapi