diff --git a/backend/Dockerfile b/backend/Dockerfile index 7115ff5..c828a2f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -3,14 +3,11 @@ FROM python:3.13.3-slim WORKDIR /app COPY Pipfile Pipfile.lock ./ -COPY app ./app - -RUN pip install --no-cache-dir pipenv -ENV PIPENV_VENV_IN_PROJECT=1 +RUN pip install --no-cache-dir pipenv && pipenv install --dev -RUN pipenv install --dev +COPY app ./app EXPOSE 8000 -CMD ["pipenv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] \ No newline at end of file +CMD ["pipenv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/backend/README.md b/backend/README.md index 07937e8..ef3705f 100644 --- a/backend/README.md +++ b/backend/README.md @@ -28,21 +28,38 @@ export PIPENV_PIPFILE=$(pwd)/Pipfile pipenv run fastapi dev ``` -## Docker +## Docker compose -build the image locally +build the app image locally ``` docker build -t pastebin-backend . ``` -run the container +have a `.env` file at the root of the `/backend` directory and fill it out with +these values +```ini +DB_USER=myuser +DB_PASSWORD=mypassword +DB_NAME=mydeb +DB_SCHEMA=myschema +DB_HOST=db # must match docker-compose file service name ``` -docker run -p 8000:8000 pastebin-backend + +run the app alongside a Postgresql database on your local machine + +```bash +docker compose up --build +``` + +to reset your docker environment + +```bash +docker compose down --volumes ``` -FastAPI app is available on: [http://localhost:8000](http://localhost:8000) +FastAPI app swagger is available on: [http://localhost:8010/docs](http://localhost:8010/docs) ## API - locally diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml new file mode 100644 index 0000000..6bde98e --- /dev/null +++ b/backend/docker-compose.yml @@ -0,0 +1,36 @@ +services: + app: + build: + context: ./ + dockerfile: ./Dockerfile + container_name: fastapi_app + ports: + - "8010:8000" + env_file: + - ./.env + depends_on: + db: + condition: service_healthy + + db: + image: postgres:15 + container_name: postgres_db + restart: always + env_file: + - ./.env + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_NAME} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres_data: