Skip to content
Open
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
4 changes: 4 additions & 0 deletions fastapi/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
docker-compose.yml
start.sh
stop.sh
16 changes: 16 additions & 0 deletions fastapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.7.2

ADD ./ /fastapi

WORKDIR fastapi

RUN pip3 install -r /fastapi/requirements.txt

WORKDIR /fastapi

EXPOSE 8080

ENTRYPOINT ["/fastapi/conf/docker-entrypoint.sh"]

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"]

29 changes: 29 additions & 0 deletions fastapi/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import asyncpg
import os

import uvicorn
from fastapi import FastAPI

app = FastAPI()


@app.on_event("startup")
async def register_db():
app.db = await asyncpg.create_pool(dsn=os.environ['DATABASE_URL'])


@app.on_event("shutdown")
async def cleanup():
await app.db.close()


@app.get('/db')
async def handle_db():
async with app.db.acquire() as connection:
result = await connection.fetchval("SELECT html FROM render_cache_pagehtml WHERE url='startmatter.com'")
return result



if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)
4 changes: 4 additions & 0 deletions fastapi/conf/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
sleep 5s
exec "$@"
22 changes: 22 additions & 0 deletions fastapi/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
postgres:
restart: always
build: .././database/
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=render
- POSTGRES_USER=render
- POSTGRES_DB=render

fastapi:
restart: always
build: .
ports:
- "8080:8080"
depends_on:
- postgres
environment:
- DATABASE_URL=postgres://render:render@postgres:5432/render

3 changes: 3 additions & 0 deletions fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
asyncpg
fastapi
uvicorn
2 changes: 2 additions & 0 deletions fastapi/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker-compose build
docker-compose up -d
2 changes: 2 additions & 0 deletions fastapi/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker-compose stop
docker-compose down