Skip to content

Commit

Permalink
update workflow files for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Chen authored and Mark Chen committed Jan 25, 2024
1 parent e168868 commit c642060
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Optionally set up Python if needed for other steps (not shown here)
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'

# Pull the latest version of the base image to ensure it's up to date
- name: Pull latest base image
run: docker pull tiangolo/uvicorn-gunicorn-fastapi:python3.9

# Build the Docker image, with caching of Docker layers
- name: Build Docker image
run: |
docker build -t fastapirepo . --cache-from tiangolo/uvicorn-gunicorn-fastapi:python3.9
# Run unit tests in the Docker container
- name: Unit Tests
run: |
docker build -t fastapirepo .
docker run -e OPENAI_ORG_ID=${{ secrets.OPENAI_ORG_ID }} -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} fastapirepo pytest
docker run -e OPENAI_ORG_ID=${{ secrets.OPENAI_ORG_ID }} -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} fastapirepo pytest
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9

# Set default values for environment variables
ENV OPENAI_ORG_ID=default_org_id
ENV OPENAI_API_KEY=default_api_key

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./src /app

CMD ["uvicorn", "index.main:app", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "index.main:app", "--host", "0.0.0.0", "--port", "80"]
4 changes: 2 additions & 2 deletions src/ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from openai import OpenAI

client = OpenAI(
organization=os.environ["OPENAI_ORG_ID"],
api_key=os.environ["OPENAI_API_KEY"],
organization=os.getenv('OPENAI_ORG_ID'),
api_key=os.getenv('OPENAI_API_KEY')
)


Expand Down

0 comments on commit c642060

Please sign in to comment.