Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI/CD with FastAPI

on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
workflow_dispatch:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
IMAGE: ${{ secrets.DOCKER_USERNAME }}/menu-ai

jobs:
docker-build-push:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build & Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ github.sha }}

deploy:
name: Deploy to Server
needs: docker-build-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

steps:
- name: Deploy via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
docker pull ${{ env.IMAGE }}:latest
docker stop menu-ai || true
docker rm menu-ai || true
docker run -d --name menu-ai \
-p 8000:8000 \
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
-e OPENAI_MODEL=${{ secrets.OPENAI_MODEL }} \
${{ env.IMAGE }}:latest
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
File renamed without changes.