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
9 changes: 3 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
CMD ["pipenv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
27 changes: 22 additions & 5 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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: