mirror of
https://github.com/philip306/countapi.git
synced 2024-06-15 10:55:23 +03:00
asuh
This commit is contained in:
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.git
|
||||||
|
.dockerignore
|
||||||
17
Dockerfile
17
Dockerfile
@@ -1,5 +1,14 @@
|
|||||||
FROM python:3.7
|
FROM ubuntu
|
||||||
RUN pip install fastapi uvicorn
|
|
||||||
EXPOSE 80
|
COPY requirements.txt /
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python3.6 python3-pip
|
||||||
|
|
||||||
|
RUN pip3 install -r /requirements.txt
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
COPY ./app /app
|
COPY ./app /app
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -1,3 +1,80 @@
|
|||||||
# CountAPI
|
# CountAPI
|
||||||
|
|
||||||
This project is a clone of the functionality available at https://countapi.xyz/ implemented with FastAPI and Redis
|
This project is a clone of the functionality available at https://countapi.xyz/ implemented with Python using [FastAPI](https://fastapi.tiangolo.com/) and [Redis](https://redis.io/). If you find this useful, consider donating to [Mlomb](https://countapi.xyz/#donate), the creator of countapi.xyz
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Thanks to FastAPI there is swagger/OpenAPI doc endpoints included automatically and after deployment will be available at /docs and /redoc
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
First clone the repo locally
|
||||||
|
|
||||||
|
``` git clone https://github.com/philip306/countapi.git ```
|
||||||
|
|
||||||
|
Install the prerequisites:
|
||||||
|
|
||||||
|
```pip install -r /requirements.txt```
|
||||||
|
|
||||||
|
Update config.py to point to your redis host/ip
|
||||||
|
|
||||||
|
```redishost: str = 'redis'```
|
||||||
|
|
||||||
|
Start Uvicorn:
|
||||||
|
|
||||||
|
```uvicorn app.main:app --port 8000```
|
||||||
|
|
||||||
|
Navigate to http://127.0.0.1:8000 in a browser
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
First clone the repo locally
|
||||||
|
|
||||||
|
``` git clone https://github.com/philip306/countapi.git ```
|
||||||
|
|
||||||
|
Update config.py to point to your redis host/ip
|
||||||
|
|
||||||
|
```redishost: str = 'redis'```
|
||||||
|
|
||||||
|
From within the count api directory build the docker image
|
||||||
|
|
||||||
|
```docker build -t countapi:0.1 .```
|
||||||
|
|
||||||
|
Run the image you just created
|
||||||
|
|
||||||
|
```docker run -p 8000:8000 --detach --name countapi countapi:0.1```
|
||||||
|
|
||||||
|
Navigate to http://127.0.0.1:8000 in a browser
|
||||||
|
|
||||||
|
### Docker Compose
|
||||||
|
|
||||||
|
Using ```docker-compose``` will using the deployment outlined in docker-compose.yml which will deploy a second container with a standard redis image
|
||||||
|
|
||||||
|
First clone the repo locally
|
||||||
|
|
||||||
|
``` git clone https://github.com/philip306/countapi.git ```
|
||||||
|
|
||||||
|
Update config.py to point to your redis host/ip
|
||||||
|
|
||||||
|
```redishost: str = 'redis'```
|
||||||
|
|
||||||
|
From within the count api directory build the docker image
|
||||||
|
|
||||||
|
```docker build -t countapi:0.1 .```
|
||||||
|
|
||||||
|
Launch two separate containers with a redis image and a countapi image you just created
|
||||||
|
|
||||||
|
```docker-compose up```
|
||||||
|
|
||||||
|
Navigate to http://127.0.0.1:8000 in a browser
|
||||||
|
|
||||||
|
### AWS Lambda and Elasticache
|
||||||
|
|
||||||
|
_Coming soon_
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```pytest``` will execute the tests outlined in tests/test_main.py. Currently very low coverage.
|
||||||
|
|
||||||
|
## Known Issues
|
||||||
|
Currently there is no TTL set on the keys, so the key will exist indefinitely. You can clean them up manually if needed with redis-cli> flushdb
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from pydantic import BaseSettings
|
|||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
app_name: str = "CountAPI"
|
app_name: str = "CountAPI"
|
||||||
ttlsetting: int = 100000
|
ttlsetting: int = 100000
|
||||||
redishost: str = '192.168.25.12'
|
redishost: str = 'redis'
|
||||||
port: int = 6379
|
port: int = 6379
|
||||||
db: int = 0
|
db: int = 0
|
||||||
redispass: str = ""
|
redispass: str = ""
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from fastapi import FastAPI, HTTPException
|
|||||||
import redis
|
import redis
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from conf.config import settings
|
from app.conf.config import settings
|
||||||
|
|
||||||
pool = redis.ConnectionPool(host=settings.redishost, port=settings.port, db=settings.db)
|
pool = redis.ConnectionPool(host=settings.redishost, port=settings.port, db=settings.db)
|
||||||
r = redis.Redis(connection_pool=pool)
|
r = redis.Redis(connection_pool=pool)
|
||||||
@@ -10,7 +10,7 @@ app = FastAPI()
|
|||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
return {"msg": "Hello World"}
|
return {"msg": "CountAPI is up!"}
|
||||||
|
|
||||||
@app.get("/get/{key}")
|
@app.get("/get/{key}")
|
||||||
async def getkey(key: str):
|
async def getkey(key: str):
|
||||||
|
|||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
volumes:
|
||||||
|
- .:/countapi
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
|
redis:
|
||||||
|
image: redis
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
fastapi==0.60.1
|
fastapi==0.60.1
|
||||||
redis==3.5.3
|
redis==3.5.3
|
||||||
requests==2.24.0
|
requests==2.24.0
|
||||||
|
uvicorn==0.11.6
|
||||||
Reference in New Issue
Block a user