Skip to content

Commit 4272619

Browse files
authored
✨ Add Copier, migrate from Cookiecutter, in a way that supports using the project as is, forking or cloning it (#612)
* 🔧 Add first Copier config * 🔧 Add custom copier answers file * 🔨 Add Copier script to update .env after generating/copying * 🙈 Update .gitignores from Copier updates * 🔧 Update .env, restructure in order of relevance * 🔧 Remove Copier config for SMTP port, if necessary, it can be overwritten in .env * ♻️ Refactor Copier files, make them less visible * 🔧 Update Copier config * 🔥 Remove Cookiecutter files
1 parent 0cc802e commit 4272619

9 files changed

+167
-97
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
.vscode
2-
.mypy_cache
3-
poetry.lock

cookiecutter.json

-44
This file was deleted.

src/.copier/.copier-answers.yml.jinja

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ _copier_answers|to_json -}}

src/.copier/update_dotenv.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pathlib import Path
2+
import json
3+
4+
# Update the .env file with the answers from the .copier-answers.yml file
5+
# without using Jinja2 templates in the .env file, this way the code works as is
6+
# without needing Copier, but if Copier is used, the .env file will be updated
7+
root_path = Path(__file__).parent.parent
8+
answers_path = Path(__file__).parent / ".copier-answers.yml"
9+
answers = json.loads(answers_path.read_text())
10+
env_path = root_path / ".env"
11+
env_content = env_path.read_text()
12+
lines = []
13+
for line in env_content.splitlines():
14+
for key, value in answers.items():
15+
upper_key = key.upper()
16+
if line.startswith(f"{upper_key}="):
17+
new_line = line.replace(line, f"{upper_key}={value}")
18+
lines.append(new_line)
19+
break
20+
else:
21+
lines.append(line)
22+
env_path.write_text("\n".join(lines))

src/.env

+22-20
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@
22
DOMAIN=localhost
33
# DOMAIN=localhost.tiangolo.com
44

5-
STACK_NAME=full-stack-fastapi-postgresql
6-
7-
TRAEFIK_PUBLIC_NETWORK=traefik-public
8-
TRAEFIK_TAG=traefik
9-
TRAEFIK_PUBLIC_TAG=traefik-public
5+
PROJECT_NAME="FastAPI Project"
106

11-
# Configure these with your own Docker registry images
12-
DOCKER_IMAGE_BACKEND=backend
13-
DOCKER_IMAGE_CELERYWORKER=celery
14-
DOCKER_IMAGE_FRONTEND=frontend
15-
DOCKER_IMAGE_NEW_FRONTEND=new-frontend
7+
STACK_NAME=fastapi-project
168

179
# Backend
1810
BACKEND_CORS_ORIGINS="[\"http://localhost\", \"http://localhost:4200\", \"http://localhost:3000\", \"http://localhost:8080\", \"https://localhost\", \"https://localhost:4200\", \"https://localhost:3000\", \"https://localhost:8080\", \"http://local.dockertoolbox.tiangolo.com\", \"http://localhost.tiangolo.com\"]"
19-
PROJECT_NAME="FastAPI Project"
2011
SECRET_KEY=changethis
2112
FIRST_SUPERUSER=[email protected]
2213
FIRST_SUPERUSER_PASSWORD=changethis
23-
SMTP_TLS=True
24-
SMTP_PORT=587
2514
SMTP_HOST=
2615
SMTP_USER=
2716
SMTP_PASSWORD=
2817
EMAILS_FROM_EMAIL=[email protected]
18+
SMTP_TLS=True
19+
SMTP_PORT=587
2920

3021
USERS_OPEN_REGISTRATION=False
3122

32-
SENTRY_DSN=
33-
34-
# Flower
35-
FLOWER_BASIC_AUTH=
36-
3723
# Postgres
3824
POSTGRES_SERVER=db
3925
POSTGRES_USER=postgres
40-
POSTGRES_PASSWORD=changethis
4126
POSTGRES_DB=app
27+
POSTGRES_PASSWORD=changethis
4228

4329
# PgAdmin
44-
PGADMIN_LISTEN_PORT=5050
4530
PGADMIN_DEFAULT_EMAIL=[email protected]
4631
PGADMIN_DEFAULT_PASSWORD=changethis
32+
PGADMIN_LISTEN_PORT=5050
33+
34+
SENTRY_DSN=
35+
36+
# Flower
37+
FLOWER_BASIC_AUTH=
38+
39+
# Traefik
40+
TRAEFIK_PUBLIC_NETWORK=traefik-public
41+
TRAEFIK_TAG=traefik
42+
TRAEFIK_PUBLIC_TAG=traefik-public
43+
44+
# Configure these with your own Docker registry images
45+
DOCKER_IMAGE_BACKEND=backend
46+
DOCKER_IMAGE_CELERYWORKER=celery
47+
DOCKER_IMAGE_FRONTEND=frontend
48+
DOCKER_IMAGE_NEW_FRONTEND=new-frontend

src/backend/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ app.egg-info
44
.mypy_cache
55
.coverage
66
htmlcov
7+
poetry.lock
8+
.cache
9+
.venv

src/backend/app/tests/.gitignore

-1
This file was deleted.

src/cookiecutter-config-file.yml

-30
This file was deleted.

src/copier.yml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
domain:
2+
type: str
3+
help: |
4+
Which domain name to use for the project, by default,
5+
localhost, but you should change it later (in .env)
6+
default: localhost
7+
8+
project_name:
9+
type: str
10+
help: The name of the project, shown to API users (in .env)
11+
default: FastAPI Project
12+
13+
stack_name:
14+
type: str
15+
help: The name of the stack used for Docker Compose labels (no spaces) (in .env)
16+
default: fastapi-project
17+
18+
secret_key:
19+
type: str
20+
help: |
21+
'The secret key for the project, used for security,
22+
stored in .env, you can generate one with:
23+
python -c "import secrets; print(secrets.token_urlsafe(32))"'
24+
default: changethis
25+
26+
first_superuser:
27+
type: str
28+
help: The email of the first superuser (in .env)
29+
30+
31+
first_superuser_password:
32+
type: str
33+
help: The password of the first superuser (in .env)
34+
default: changethis
35+
36+
smtp_host:
37+
type: str
38+
help: The SMTP server host to send emails, you can set it later in .env
39+
default: ""
40+
41+
smtp_user:
42+
type: str
43+
help: The SMTP server user to send emails, you can set it later in .env
44+
default: ""
45+
46+
smtp_password:
47+
type: str
48+
help: The SMTP server password to send emails, you can set it later in .env
49+
default: ""
50+
51+
emails_from_email:
52+
type: str
53+
help: The email account to send emails from, you can set it later in .env
54+
55+
56+
postgres_password:
57+
type: str
58+
help: |
59+
'The password for the PostgreSQL database, stored in .env,
60+
you can generate one with:
61+
python -c "import secrets; print(secrets.token_urlsafe(32))"'
62+
default: changethis
63+
64+
pgadmin_default_email:
65+
type: str
66+
help: The default user email for pgAdmin, you can set it later in .env
67+
68+
69+
pgadmin_default_password:
70+
type: str
71+
help: The default user password for pgAdmin, stored in .env
72+
default: changethis
73+
74+
sentry_dsn:
75+
type: str
76+
help: The DSN for Sentry, if you are using it, you can set it later in .env
77+
default: ""
78+
79+
_exclude:
80+
# Global
81+
- .vscode
82+
- .mypy_cache
83+
- poetry.lock
84+
# Python
85+
- __pycache__
86+
- app.egg-info
87+
- "*.pyc"
88+
- .mypy_cache
89+
- .coverage
90+
- htmlcov
91+
- poetry.lock
92+
- .cache
93+
- .venv
94+
# Frontend
95+
# Logs
96+
- logs
97+
- "*.log"
98+
- npm-debug.log*
99+
- yarn-debug.log*
100+
- yarn-error.log*
101+
- pnpm-debug.log*
102+
- lerna-debug.log*
103+
- node_modules
104+
- dist
105+
- dist-ssr
106+
- "*.local"
107+
# Editor directories and files
108+
- .idea
109+
- .DS_Store
110+
- "*.suo"
111+
- "*.ntvs*"
112+
- "*.njsproj"
113+
- "*.sln"
114+
- "*.sw?"
115+
116+
_answers_file: .copier/.copier-answers.yml
117+
118+
_tasks:
119+
- "python .copier/update_dotenv.py"

0 commit comments

Comments
 (0)