diff --git a/create_fastapi_project/templates/__init__.py b/create_fastapi_project/templates/__init__.py index 48da552..05b4486 100644 --- a/create_fastapi_project/templates/__init__.py +++ b/create_fastapi_project/templates/__init__.py @@ -39,12 +39,11 @@ def install_template(root: str, template: ITemplate, app_name: str): poetry_path = "" if template == ITemplate.full or template == ITemplate.langchain_basic: - # TODO: CHECK PATHS IN MACOS AND WINDOWS | (os.path.join) - poetry_path = os.path.join(root, "backend", "app") + # TODO: CHECK PATHS IN MACOS AND WINDOWS | (os.path.join) poetry_frontend_path = os.path.join(root, "frontend", "app") else: - poetry_path = os.path.join(root, "app") + poetry_path = os.path.join(root, "backend", "app") has_pyproject = add_configuration_to_pyproject(poetry_path) diff --git a/create_fastapi_project/templates/basic/.env.example b/create_fastapi_project/templates/basic/.env.example index ffaa5c8..09539a4 100644 --- a/create_fastapi_project/templates/basic/.env.example +++ b/create_fastapi_project/templates/basic/.env.example @@ -1,2 +1,9 @@ PROJECT_NAME=app -BACKEND_CORS_ORIGINS=["*"] \ No newline at end of file +BACKEND_CORS_ORIGINS=["*"] + +############################################# +# Caddy variables +############################################# +EXT_ENDPOINT1=127.0.0.1 +LOCAL_1=localhost +LOCAL_2=127.0.0.1 \ No newline at end of file diff --git a/create_fastapi_project/templates/basic/Makefile b/create_fastapi_project/templates/basic/Makefile index a6acc4b..e95a107 100644 --- a/create_fastapi_project/templates/basic/Makefile +++ b/create_fastapi_project/templates/basic/Makefile @@ -30,10 +30,10 @@ help: @echo " Lint code with ruff and try to fix." install: - cd app && poetry install && cd .. + cd backend/app && poetry install && cd .. run-app: - cd app && poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000 && cd .. + cd backend/app && poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000 && cd .. run-dev-build: @@ -52,21 +52,21 @@ stop-prod: docker compose down formatter: - cd app && \ + cd backend/app && \ poetry run black app mypy: - cd app && \ + cd backend/app && \ poetry run mypy . lint: - cd app && \ + cd backend/app && \ poetry run ruff app && poetry run black --check app lint-watch: - cd app && \ + cd backend/app && \ poetry run ruff app --watch lint-fix: - cd app && \ + cd backend/app && \ poetry run ruff app --fix diff --git a/create_fastapi_project/templates/basic/README.md b/create_fastapi_project/templates/basic/README.md index c420953..9605916 100644 --- a/create_fastapi_project/templates/basic/README.md +++ b/create_fastapi_project/templates/basic/README.md @@ -21,6 +21,9 @@ make run-dev make run-prod ``` +Open [http://fastapi.localhost/docs](http://fastapi.localhost/docs) with your browser to see the result. + + - Run the server without docker: First, make sure you have all packages installed: diff --git a/create_fastapi_project/templates/basic/Dockerfile b/create_fastapi_project/templates/basic/backend/Dockerfile similarity index 100% rename from create_fastapi_project/templates/basic/Dockerfile rename to create_fastapi_project/templates/basic/backend/Dockerfile diff --git a/create_fastapi_project/templates/basic/app/README.md b/create_fastapi_project/templates/basic/backend/app/README.md similarity index 100% rename from create_fastapi_project/templates/basic/app/README.md rename to create_fastapi_project/templates/basic/backend/app/README.md diff --git a/create_fastapi_project/templates/basic/app/app/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/api/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/api/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/api/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/api/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/api/v1/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/api/v1/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/api/v1/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/api/v1/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/api/v1/api.py b/create_fastapi_project/templates/basic/backend/app/app/api/v1/api.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/api/v1/api.py rename to create_fastapi_project/templates/basic/backend/app/app/api/v1/api.py diff --git a/create_fastapi_project/templates/basic/app/app/api/v1/endpoints/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/api/v1/endpoints/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/api/v1/endpoints/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/api/v1/endpoints/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/api/v1/endpoints/weather.py b/create_fastapi_project/templates/basic/backend/app/app/api/v1/endpoints/weather.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/api/v1/endpoints/weather.py rename to create_fastapi_project/templates/basic/backend/app/app/api/v1/endpoints/weather.py diff --git a/create_fastapi_project/templates/basic/app/app/core/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/core/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/core/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/core/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/core/config.py b/create_fastapi_project/templates/basic/backend/app/app/core/config.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/core/config.py rename to create_fastapi_project/templates/basic/backend/app/app/core/config.py diff --git a/create_fastapi_project/templates/basic/app/app/main.py b/create_fastapi_project/templates/basic/backend/app/app/main.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/main.py rename to create_fastapi_project/templates/basic/backend/app/app/main.py diff --git a/create_fastapi_project/templates/basic/app/app/schemas/response_schema.py b/create_fastapi_project/templates/basic/backend/app/app/schemas/response_schema.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/schemas/response_schema.py rename to create_fastapi_project/templates/basic/backend/app/app/schemas/response_schema.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/utils/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/exceptions/__init__.py b/create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/exceptions/__init__.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/__init__.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/exceptions/common_exception.py b/create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/common_exception.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/exceptions/common_exception.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/common_exception.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/exceptions/user_exceptions.py b/create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/user_exceptions.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/exceptions/user_exceptions.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/user_exceptions.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/exceptions/user_follow_exceptions.py b/create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/user_follow_exceptions.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/exceptions/user_follow_exceptions.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/exceptions/user_follow_exceptions.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/partial.py b/create_fastapi_project/templates/basic/backend/app/app/utils/partial.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/partial.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/partial.py diff --git a/create_fastapi_project/templates/basic/app/app/utils/uuid6.py b/create_fastapi_project/templates/basic/backend/app/app/utils/uuid6.py similarity index 100% rename from create_fastapi_project/templates/basic/app/app/utils/uuid6.py rename to create_fastapi_project/templates/basic/backend/app/app/utils/uuid6.py diff --git a/create_fastapi_project/templates/basic/app/test/__init__.py b/create_fastapi_project/templates/basic/backend/app/test/__init__.py similarity index 100% rename from create_fastapi_project/templates/basic/app/test/__init__.py rename to create_fastapi_project/templates/basic/backend/app/test/__init__.py diff --git a/create_fastapi_project/templates/basic/caddy/Caddyfile b/create_fastapi_project/templates/basic/caddy/Caddyfile new file mode 100644 index 0000000..53bf247 --- /dev/null +++ b/create_fastapi_project/templates/basic/caddy/Caddyfile @@ -0,0 +1,8 @@ +{ + email custom@domain.com +} + +fastapi.{$EXT_ENDPOINT1}:80, fastapi.{$LOCAL_1}:80, fastapi.{$LOCAL_2}:80 { + reverse_proxy fastapi_server:8000 +} + diff --git a/create_fastapi_project/templates/basic/docker-compose-dev.yml b/create_fastapi_project/templates/basic/docker-compose-dev.yml index 92debc9..fc5117f 100644 --- a/create_fastapi_project/templates/basic/docker-compose-dev.yml +++ b/create_fastapi_project/templates/basic/docker-compose-dev.yml @@ -2,14 +2,33 @@ version: '3.8' services: fastapi_server: - build: . + container_name: ${PROJECT_NAME}_fastapi_server + build: ./backend restart: always command: "sh -c 'uvicorn app.main:app --reload --workers 3 --host 0.0.0.0 --port 8000'" volumes: - - ./app:/code + - ./backend/app:/code expose: - - 8000 - ports: - - 8000:8000 + - 8000 env_file: ".env" + caddy_reverse_proxy: + container_name: ${PROJECT_NAME}_caddy_reverse_proxy + image: caddy:alpine + restart: always + ports: + - 80:80 + - 443:443 + environment: + - EXT_ENDPOINT1=${EXT_ENDPOINT1} + - LOCAL_1=${LOCAL_1} + - LOCAL_2=${LOCAL_2} + volumes: + - ./caddy/Caddyfile:/etc/caddy/Caddyfile + - caddy_data:/data + - caddy_config:/config + +volumes: + caddy_data: + caddy_config: + diff --git a/create_fastapi_project/templates/basic/docker-compose.yml b/create_fastapi_project/templates/basic/docker-compose.yml index b0ad45d..6393f1c 100644 --- a/create_fastapi_project/templates/basic/docker-compose.yml +++ b/create_fastapi_project/templates/basic/docker-compose.yml @@ -2,14 +2,32 @@ version: '3.8' services: fastapi_server: - build: . + container_name: ${PROJECT_NAME}_fastapi_server + build: ./backend restart: always command: "sh -c 'gunicorn -w 3 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000 --preload --log-level=debug --timeout 120'" volumes: - - ./app:/code + - ./backend/app:/code expose: - 8000 - ports: - - 8000:8000 env_file: ".env" + caddy_reverse_proxy: + container_name: ${PROJECT_NAME}_caddy_reverse_proxy + image: caddy:alpine + restart: always + ports: + - 80:80 + - 443:443 + environment: + - EXT_ENDPOINT1=${EXT_ENDPOINT1} + - LOCAL_1=${LOCAL_1} + - LOCAL_2=${LOCAL_2} + volumes: + - ./caddy/Caddyfile:/etc/caddy/Caddyfile + - caddy_data:/data + - caddy_config:/config + +volumes: + caddy_data: + caddy_config: \ No newline at end of file diff --git a/create_fastapi_project/templates/full/docker-compose-dev.yml b/create_fastapi_project/templates/full/docker-compose-dev.yml index d6d9822..c0dfa6b 100644 --- a/create_fastapi_project/templates/full/docker-compose-dev.yml +++ b/create_fastapi_project/templates/full/docker-compose-dev.yml @@ -2,7 +2,7 @@ version: '3.8' services: fastapi_server: - container_name: fastapi_server + container_name: ${PROJECT_NAME}_fastapi_server build: ./backend restart: always command: "sh -c 'alembic upgrade head && uvicorn app.main:app --reload --workers 3 --host 0.0.0.0 --port 8000'" @@ -18,9 +18,9 @@ services: - caddy_reverse_proxy:storage.localhost database: + container_name: ${PROJECT_NAME}_database image: bitnami/postgresql:13.3.0 - restart: always - container_name: database + restart: always env_file: ".env" user: root volumes: @@ -37,15 +37,15 @@ services: - POSTGRES_HOST_AUTH_METHOD= "trust" redis_server: + container_name: ${PROJECT_NAME}_redis_server image: redis:alpine - container_name: redis_server restart: always expose: - 6379 env_file: .env celery_worker: - container_name: celery_worker + container_name: ${PROJECT_NAME}_celery_worker restart: always # platform: linux/arm64/v8 build: ./backend @@ -59,7 +59,7 @@ services: env_file: .env celery_beat: #Good for crontab and schedule tasks - container_name: celery_beat + container_name: ${PROJECT_NAME}_celery_beat restart: always # platform: linux/arm64/v8 build: @@ -76,9 +76,9 @@ services: env_file: .env minio_server: + container_name: ${PROJECT_NAME}_minio_server image: minio/minio:latest restart: always - container_name: minio_server volumes: - ./minio/data:/data expose: @@ -91,7 +91,7 @@ services: command: "server /data --console-address ':9090'" caddy_reverse_proxy: - container_name: caddy_reverse_proxy + container_name: ${PROJECT_NAME}_caddy_reverse_proxy image: caddy:alpine restart: always ports: diff --git a/create_fastapi_project/templates/full/docker-compose-sonarqube.yml b/create_fastapi_project/templates/full/docker-compose-sonarqube.yml index a54a95a..cefb773 100644 --- a/create_fastapi_project/templates/full/docker-compose-sonarqube.yml +++ b/create_fastapi_project/templates/full/docker-compose-sonarqube.yml @@ -2,7 +2,7 @@ version: "3.9" services: sonarqube: - container_name: "sonarqube" + container_name: ${PROJECT_NAME}_sonarqube image: "sonarqube:8.9.10-community" volumes: - ./sonarqube/extensions:/opt/sonarqube/extensions diff --git a/create_fastapi_project/templates/full/docker-compose-test.yml b/create_fastapi_project/templates/full/docker-compose-test.yml index 1010382..90585fa 100644 --- a/create_fastapi_project/templates/full/docker-compose-test.yml +++ b/create_fastapi_project/templates/full/docker-compose-test.yml @@ -2,7 +2,7 @@ version: '3.8' services: fastapi_server: - container_name: fastapi_server + container_name: ${PROJECT_NAME}_fastapi_server build: context: ./backend args: @@ -22,9 +22,9 @@ services: - caddy_reverse_proxy:storage.localhost database: + container_name: ${PROJECT_NAME}_database image: bitnami/postgresql:13.3.0 - restart: always - container_name: database + restart: always env_file: ".env" user: root volumes: @@ -41,15 +41,15 @@ services: - POSTGRES_HOST_AUTH_METHOD= "trust" redis_server: + container_name: ${PROJECT_NAME}_redis_server image: redis:alpine - container_name: redis_server restart: always expose: - 6379 env_file: .env celery_worker: - container_name: celery_worker + container_name: ${PROJECT_NAME}_celery_worker restart: always # platform: linux/arm64/v8 build: @@ -66,7 +66,7 @@ services: env_file: .env celery_beat: #Good for crontab and schedule tasks - container_name: celery_beat + container_name: ${PROJECT_NAME}_celery_beat restart: always # platform: linux/arm64/v8 build: @@ -83,9 +83,9 @@ services: env_file: .env minio_server: + container_name: ${PROJECT_NAME}_minio_server image: minio/minio:latest restart: always - container_name: minio_server volumes: - ./minio/data:/data expose: @@ -98,7 +98,7 @@ services: command: "server /data --console-address ':9090'" caddy_reverse_proxy: - container_name: caddy_reverse_proxy + container_name: ${PROJECT_NAME}_caddy_reverse_proxy image: caddy:alpine restart: always ports: diff --git a/create_fastapi_project/templates/full/docker-compose.yml b/create_fastapi_project/templates/full/docker-compose.yml index f3b5c34..9328d2f 100644 --- a/create_fastapi_project/templates/full/docker-compose.yml +++ b/create_fastapi_project/templates/full/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.8' services: fastapi_server: - container_name: fastapi_server + container_name: ${PROJECT_NAME}_fastapi_server image: jrtec/fastapi-alembic-sqlmodel-async:latest restart: always command: "sh -c 'alembic upgrade head && python app/initial_data.py && gunicorn -w 3 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000 --preload --log-level=debug --timeout 120'" @@ -17,9 +17,9 @@ services: - caddy_reverse_proxy:storage.localhost database: + container_name: ${PROJECT_NAME}_database image: bitnami/postgresql:13.3.0 restart: always - container_name: database env_file: ".env" user: root volumes: @@ -37,7 +37,7 @@ services: redis_server: - container_name: redis_server + container_name: ${PROJECT_NAME}_redis_server image: "redis:alpine" restart: always expose: @@ -46,7 +46,7 @@ services: celery_worker: - container_name: celery_worker + container_name: ${PROJECT_NAME}_celery_worker restart: always # platform: linux/arm64/v8 build: @@ -63,7 +63,7 @@ services: env_file: .env celery_beat: #Good for crontab and schedule tasks - container_name: celery_beat + container_name: ${PROJECT_NAME}_celery_beat restart: always # platform: linux/arm64/v8 build: @@ -81,9 +81,9 @@ services: minio_server: + container_name: ${PROJECT_NAME}_minio_server image: minio/minio:latest restart: always - container_name: minio_server volumes: - ./minio/data:/data expose: @@ -96,7 +96,7 @@ services: command: "server /data --console-address ':9090'" caddy_reverse_proxy: - container_name: caddy_reverse_proxy + container_name: ${PROJECT_NAME}_caddy_reverse_proxy image: caddy:alpine restart: always ports: diff --git a/create_fastapi_project/templates/langchain_basic/Makefile b/create_fastapi_project/templates/langchain_basic/Makefile index a6acc4b..7a2c1b8 100644 --- a/create_fastapi_project/templates/langchain_basic/Makefile +++ b/create_fastapi_project/templates/langchain_basic/Makefile @@ -52,21 +52,21 @@ stop-prod: docker compose down formatter: - cd app && \ + cd backend/app && \ poetry run black app mypy: - cd app && \ + cd backend/app && \ poetry run mypy . lint: - cd app && \ + cd backend/app && \ poetry run ruff app && poetry run black --check app lint-watch: - cd app && \ + cd backend/app && \ poetry run ruff app --watch lint-fix: - cd app && \ + cd backend/app && \ poetry run ruff app --fix diff --git a/create_fastapi_project/templates/langchain_basic/README.md b/create_fastapi_project/templates/langchain_basic/README.md index 50b973f..588fb91 100644 --- a/create_fastapi_project/templates/langchain_basic/README.md +++ b/create_fastapi_project/templates/langchain_basic/README.md @@ -48,6 +48,8 @@ make run-dev make run-prod ``` +Open [http://fastapi.localhost/docs](http://fastapi.localhost/docs) with your browser to see the result. + - Run the server without docker: First, make sure you have all packages installed: @@ -60,7 +62,7 @@ make install make run-app ``` -Open [http://fastapi.localhost/docs](http://fastapi.localhost/docs) with your browser to see the result. +Open [http://localhost:8000/docs](http://localhost:8000/docs) with your browser to see the result. You can start editing the server by modifying `app/main.py`. diff --git a/create_fastapi_project/templates/langchain_basic/docker-compose-dev.yml b/create_fastapi_project/templates/langchain_basic/docker-compose-dev.yml index 057696c..55750d2 100644 --- a/create_fastapi_project/templates/langchain_basic/docker-compose-dev.yml +++ b/create_fastapi_project/templates/langchain_basic/docker-compose-dev.yml @@ -2,7 +2,7 @@ version: "3.8" services: fastapi_server: - container_name: fastapi_server + container_name: ${PROJECT_NAME}_fastapi_server build: ./backend restart: always command: "sh -c 'uvicorn app.main:app --reload --workers 3 --host 0.0.0.0 --port 8000'" @@ -13,7 +13,7 @@ services: env_file: ".env" streamlit_frontend: - container_name: streamlit_frontend + container_name: ${PROJECT_NAME}_streamlit_frontend build: ./frontend restart: always volumes: @@ -24,7 +24,7 @@ services: env_file: ".env" caddy_reverse_proxy: - container_name: caddy_reverse_proxy + container_name: ${PROJECT_NAME}_caddy_reverse_proxy image: caddy:alpine restart: always ports: diff --git a/create_fastapi_project/templates/langchain_basic/docker-compose.yml b/create_fastapi_project/templates/langchain_basic/docker-compose.yml index 39de566..0369c35 100644 --- a/create_fastapi_project/templates/langchain_basic/docker-compose.yml +++ b/create_fastapi_project/templates/langchain_basic/docker-compose.yml @@ -2,6 +2,7 @@ version: "3.8" services: fastapi_server: + container_name: ${PROJECT_NAME}_fastapi_server build: ./backend restart: always command: "sh -c 'gunicorn -w 3 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000 --preload --log-level=debug --timeout 120'" @@ -14,7 +15,7 @@ services: env_file: ".env" streamlit_frontend: - container_name: streamlit_frontend + container_name: ${PROJECT_NAME}_streamlit_frontend build: ./frontend restart: always volumes: @@ -25,7 +26,7 @@ services: env_file: ".env" caddy_reverse_proxy: - container_name: caddy_reverse_proxy + container_name: ${PROJECT_NAME}_caddy_reverse_proxy image: caddy:alpine restart: always ports: diff --git a/pyproject.toml b/pyproject.toml index 09aa1a4..bc5b134 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "create-fastapi-project" -version = "0.2.1" +version = "0.2.2" description = "" authors = ["jonra1993 "] readme = "README.md"