Merge pull request #18 from PeoplePlusAI/fix-dockerfile #70
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/ci-cd.yml | |
name: CI/CD | |
on: | |
push: | |
branches: [ langgraph ] | |
pull_request: | |
branches: [ langgraph ] | |
permissions: | |
contents: read | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
LANGCHAIN_API_KEY: ${{ secrets.LANGCHAIN_API_KEY }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest pytest-cov pytest-html flake8 | |
- name: Lint with flake8 | |
run: | | |
# Stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# Exit-zero treats all errors as warnings | |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
- name: Create logs directory | |
run: mkdir -p logs | |
# - name: Run tests | |
# run: | | |
# python -m pytest tests/ -v --cov=./ --cov-report=xml --html=test_reports/report.html | |
- name: Run API tests | |
run: | | |
python -m pytest tests/test_api.py -v --cov=./ --cov-report=xml --html=test_reports/report.html | |
- name: Upload test reports | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-reports | |
path: | | |
test_reports/ | |
logs/ | |
retention-days: 5 | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install build tools | |
run: | | |
python -m pip install --upgrade pip | |
pip install build wheel | |
- name: Build project | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
python -m build | |
- name: Verify build artifacts | |
run: | | |
ls -la dist/ | |
if [ ! -f dist/*.whl ] || [ ! -f dist/*.tar.gz ]; then | |
echo "Build artifacts missing" | |
exit 1 | |
fi | |
- name: Save build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: dist/ | |
retention-days: 5 | |
deploy-api: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
path: dist/ | |
# Using v3, merge-multiple is not needed as we're uploading a single artifact | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install dist/*.whl | |
pip install uvicorn fastapi | |
- name: Create prompts directory | |
run: | | |
mkdir -p prompts | |
touch prompts/prompts.yaml | |
- name: Start API server | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
LANGCHAIN_API_KEY: ${{ secrets.LANGCHAIN_API_KEY }} | |
run: | | |
nohup uvicorn sukoon_api:app --host 127.0.0.1 --port 8001 & | |
- name: Health check | |
run: | | |
echo "Waiting for API server to start..." | |
sleep 10 # Give the server time to start | |
max_retries=5 | |
retry_count=0 | |
until curl -s http://127.0.0.1:8001/ || [ $retry_count -eq $max_retries ] | |
do | |
echo "API server not responding yet... retrying ($((retry_count+1))/$max_retries)" | |
sleep 5 | |
retry_count=$((retry_count+1)) | |
done | |
if [ $retry_count -eq $max_retries ]; then | |
echo "API server failed to start" | |
exit 1 | |
else | |
echo "API server is up and running!" | |
fi | |