Skip to content

Commit 6bdb1af

Browse files
authored
Merge pull request #2 from alephmelo/apply-cookiecutter-format
Apply cookiecutter format
2 parents 0d0ad1e + 26eb7f3 commit 6bdb1af

18 files changed

+78
-33
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,42 @@ The `envs` folder contains the files so you can use different settings depending
1919
- `HOST`=`0.0.0.0`
2020
- `APP_MODULE`=`<module>.<module>:<fastapi-app-name>`
2121
- `WORKERS_PER_CORE`=`1`
22+
23+
## Usage
24+
### Download
25+
```
26+
$ cookiecutter https://github.com/alephmelo/fast-api-docker-template.git
27+
```
28+
29+
### Build
30+
This will build both `dev` and `prod` images.
31+
```bash
32+
$ make build
33+
```
34+
35+
### Up
36+
```bash
37+
$ make up-dev
38+
[...]
39+
dev_1 | INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
40+
dev_1 | INFO: Started reloader process [1] using statreload
41+
dev_1 | INFO: Started server process [7]
42+
dev_1 | INFO: Waiting for application startup.
43+
dev_1 | INFO: Application startup complete.
44+
```
45+
46+
## Deployment
47+
Just push your built image to whatever cloud provider or manually start the service. It's tagged locally as `<app_namme>/<app_name>:latest-prod`.
48+
49+
Example:
50+
```
51+
$ make up-prod
52+
docker run -p 80:80 <app_namme>/<app_name>:latest-prod
53+
INFO: Started server process [1]
54+
INFO: Waiting for application startup.
55+
INFO: Application startup complete.
56+
INFO: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
57+
```
58+
59+
## Release History
60+
- 0.1.0 - Initial version.

cookiecutter.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"app_name": "helloworld",
3+
"main_file_name": "app",
4+
"python_version": "3.8"
5+
}

docker-compose.yml

-26
This file was deleted.
File renamed without changes.
File renamed without changes.

Dockerfile {{cookiecutter.app_name}}/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM python:3.8 as base
1+
FROM python:{{cookiecutter.python_version}} as base
22

3-
WORKDIR /home/workingtitle
3+
WORKDIR /home/{{cookiecutter.app_name}}
44

55
COPY requirements.txt requirements.txt
66

@@ -20,7 +20,7 @@ COPY . .
2020

2121
ARG PORT=80
2222
ARG HOST=0.0.0.0
23-
ARG APP_MODULE=workingtitle.workingtitle:app
23+
ARG APP_MODULE={{cookiecutter.app_name}}.{{cookiecutter.main_file_name}}:app
2424
ARG WORKERS_PER_CORE=1
2525

2626
ENV MODE=production
File renamed without changes.

Makefile {{cookiecutter.app_name}}/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ up-dev:
1313
docker-compose up dev
1414

1515
up-prod:
16-
docker run -p 80:80 workingtitle/workingtitle:latest-prod
16+
docker run -p 80:80 {{cookiecutter.app_name}}/{{cookiecutter.app_name}}:latest-prod
1717

1818
bash:
1919
docker-compose run --entrypoint=bash dev
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.8"
2+
3+
services:
4+
dev:
5+
image: {{cookiecutter.app_name}}/{{cookiecutter.app_name}}:latest-dev
6+
working_dir: /home/{{cookiecutter.app_name}}
7+
entrypoint: uvicorn {{cookiecutter.app_name}}.{{cookiecutter.main_file_name}}:app --reload --host 0.0.0.0
8+
build:
9+
target: development
10+
context: .
11+
dockerfile: Dockerfile
12+
ports:
13+
- 8000:8000
14+
volumes:
15+
- .:/home/{{cookiecutter.app_name}}
16+
17+
environment:
18+
- MODE=development
19+
20+
prod:
21+
image: {{cookiecutter.app_name}}/{{cookiecutter.app_name}}:latest-prod
22+
working_dir: /production/{{cookiecutter.app_name}}
23+
build:
24+
target: production
25+
context: .
26+
dockerfile: Dockerfile
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from os import getenv
22
from pydantic import BaseSettings
33

4+
45
class Settings(BaseSettings):
5-
app_name: str = "Awesome API"
6+
app_name: str = "{{cookiecutter.app_name}}"
67
mode: str
78
dbpath: str
89

910
class Config:
10-
env_file = f"workingtitle/envs/{getenv('MODE')}.env"
11+
env_file = f"{{cookiecutter.app_name}}/envs/{getenv('MODE')}.env"

workingtitle/workingtitle.py {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/{{cookiecutter.main_file_name}}.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from fastapi import FastAPI
2-
from workingtitle.utils.settings import Settings
2+
from {{cookiecutter.app_name}}.utils.settings import Settings
33

44

55
app = FastAPI()

0 commit comments

Comments
 (0)