-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rafsaf/fastapi-users-support
Fastapi users support
- Loading branch information
Showing
88 changed files
with
3,104 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
.vscode | ||
.vscode | ||
.venv | ||
venv | ||
.venv1 | ||
.venv2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"project_name": "Base Project" | ||
} | ||
"project_name": "Base Project", | ||
"use_fastapi_users": false | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,44 @@ | ||
""" | ||
Copy template choosen from TEMPLATES to main folder. | ||
Copy content from env template (autogenerated passwords etc) | ||
to .env which is gitignored, then remove template env file as it is redundant | ||
to .env which is gitignored, then remove template env file as it is redundant. | ||
""" | ||
|
||
from pathlib import Path | ||
from shutil import copytree, rmtree | ||
|
||
PROJECT_NAME = "{{ cookiecutter.project_name }}" | ||
USE_FASTAPI_USERS = "{{ cookiecutter.use_fastapi_users }}" | ||
TEMPLATES = ["template_fastapi_users", "template_minimal"] | ||
|
||
|
||
def copy_choosen_template_to_main_dir(used_template: str): | ||
if used_template not in TEMPLATES: | ||
raise ValueError(f"{used_template} not in {TEMPLATES}") | ||
|
||
copytree(used_template, "./", dirs_exist_ok=True) | ||
|
||
for template in TEMPLATES: | ||
rmtree(Path(template)) | ||
|
||
|
||
def create_env_file_and_remove_env_template(): | ||
env_template_file = Path(".env.template") | ||
env_file = Path(".env") | ||
|
||
env_file.write_text(env_template_file.read_text()) | ||
env_template_file.unlink() | ||
|
||
|
||
env_template_file = Path("./.env.template") | ||
env_file = Path("./.env") | ||
if __name__ == "__main__": | ||
truthy = ["T", "t", "true", "True", 1] | ||
falsy = ["F", "f", "false", "False", 0] | ||
if USE_FASTAPI_USERS in truthy: | ||
used_template = "template_fastapi_users" | ||
elif USE_FASTAPI_USERS in falsy: | ||
used_template = "template_minimal" | ||
else: | ||
raise ValueError(f"use_fastapi_users param must be in {truthy + falsy}") | ||
|
||
env_file.write_text(env_template_file.read_text()) | ||
env_template_file.unlink() | ||
copy_choosen_template_to_main_dir(used_template=used_template) | ||
create_env_file_and_remove_env_template() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Creates fastapi_users template project in root folder with default values | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from cookiecutter.main import cookiecutter | ||
|
||
ROOT_FOLDER = Path(__file__).parent.parent | ||
|
||
|
||
def main(): | ||
cookiecutter( | ||
template=str(ROOT_FOLDER), | ||
no_input=True, | ||
extra_context={ | ||
"project_name": "fastapi_users_project", | ||
"use_fastapi_users": True, | ||
}, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
{{cookiecutter.project_name}}/template_fastapi_users/.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SECRET_KEY="DVnFmhwvjEhJZpuhndxjhlezxQPJmBIIkMDEmFREWQADPcUnrG" | ||
ENVIRONMENT="DEV" | ||
ACCESS_TOKEN_EXPIRE_MINUTES="11520" | ||
BACKEND_CORS_ORIGINS="http://localhost:3000,http://localhost:8001" | ||
|
||
DEFAULT_DATABASE_HOSTNAME="localhost" | ||
DEFAULT_DATABASE_USER="rDGJeEDqAz" | ||
DEFAULT_DATABASE_PASSWORD="XsPQhCoEfOQZueDjsILetLDUvbvSxAMnrVtgVZpmdcSssUgbvs" | ||
DEFAULT_DATABASE_PORT="5387" | ||
DEFAULT_DATABASE_DB="default_db" | ||
|
||
TEST_DATABASE_HOSTNAME="localhost" | ||
TEST_DATABASE_USER="test" | ||
TEST_DATABASE_PASSWORD="ywRCUjJijmQoBmWxIfLldOoITPzajPSNvTvHyugQoSqGwNcvQE" | ||
TEST_DATABASE_PORT="37270" | ||
TEST_DATABASE_DB="test_db" | ||
|
||
FIRST_SUPERUSER_EMAIL="[email protected]" | ||
FIRST_SUPERUSER_PASSWORD="OdLknKQJMUwuhpAVHvRC" |
19 changes: 19 additions & 0 deletions
19
{{cookiecutter.project_name}}/template_fastapi_users/.env.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SECRET_KEY="{{ random_ascii_string(50) }}" | ||
ENVIRONMENT="DEV" | ||
ACCESS_TOKEN_EXPIRE_MINUTES="11520" | ||
BACKEND_CORS_ORIGINS="http://localhost:3000,http://localhost:8001" | ||
|
||
DEFAULT_DATABASE_HOSTNAME="localhost" | ||
DEFAULT_DATABASE_USER="{{ random_ascii_string(10) }}" | ||
DEFAULT_DATABASE_PASSWORD="{{ random_ascii_string(50) }}" | ||
DEFAULT_DATABASE_PORT="{{ range(4000, 7000) | random }}" | ||
DEFAULT_DATABASE_DB="default_db" | ||
|
||
TEST_DATABASE_HOSTNAME="localhost" | ||
TEST_DATABASE_USER="test" | ||
TEST_DATABASE_PASSWORD="{{ random_ascii_string(50) }}" | ||
TEST_DATABASE_PORT="{{ range(30000, 40000) | random }}" | ||
TEST_DATABASE_DB="test_db" | ||
|
||
FIRST_SUPERUSER_EMAIL="[email protected]" | ||
FIRST_SUPERUSER_PASSWORD="{{ random_ascii_string(20) }}" |
File renamed without changes.
File renamed without changes.
27 changes: 15 additions & 12 deletions
27
{{cookiecutter.project_name}}/Dockerfile → ..._name}}/template_fastapi_users/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
# See https://unit.nginx.org/installation/#docker-images | ||
|
||
FROM nginx/unit:1.25.0-python3.9 | ||
FROM nginx/unit:1.26.1-python3.9 | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# Nginx unit config and init.sh will be consumed at container startup. | ||
COPY ./app/init.sh /docker-entrypoint.d/init.sh | ||
COPY ./nginx-unit-config.json /docker-entrypoint.d/config.json | ||
RUN chmod +x /docker-entrypoint.d/init.sh | ||
RUN apt update && apt install -y python3-pip | ||
|
||
# Build folder for our app, only stuff that matters copied. | ||
RUN mkdir build | ||
WORKDIR /build | ||
|
||
COPY ./app ./app | ||
COPY ./alembic ./alembic | ||
COPY ./alembic.ini . | ||
# Update, install requirements and then cleanup. | ||
COPY ./requirements.txt . | ||
|
||
# Update, install requirements and then cleanup. | ||
RUN apt update && apt install -y python3-pip \ | ||
&& pip3 install -r requirements.txt \ | ||
RUN pip3 install -r requirements.txt \ | ||
&& apt remove -y python3-pip \ | ||
&& apt autoremove --purge -y \ | ||
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list | ||
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list | ||
|
||
# Copy the rest of app | ||
COPY ./app ./app | ||
COPY ./alembic ./alembic | ||
COPY ./alembic.ini . | ||
|
||
# Nginx unit config and init.sh will be consumed at container startup. | ||
COPY ./app/init.sh /docker-entrypoint.d/init.sh | ||
COPY ./nginx-unit-config.json /docker-entrypoint.d/config.json | ||
RUN chmod a+x /docker-entrypoint.d/init.sh |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.