diff --git a/.cruft.json b/.cruft.json index aa72572..a350527 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { - "template": "https://github.com/kjaymiller/cookiecutter-relecloud/", - "commit": "62bc1afd3ca0eb0daf28a7c829761198033a08a6", + "template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator", + "commit": "621af12f962b64b1f3458b83fa1af0898d565d80", "checkout": null, "context": { "cookiecutter": { @@ -11,7 +11,7 @@ "project_host": "aca", "web_port": "8000", "__repo_name": "azure-fastapi-cosmos-postgres-aca", - "__src_folder_name": "azure_fastapi_cosmos_postgres_aca", + "__src_folder_name": "azure-fastapi-cosmos-postgres-aca", "__project_short_description": "Create a relecloud demo application with fastapi and cosmos-postgres", "_copy_without_render": [ ".github/workflows/azure-dev.yml", @@ -26,7 +26,7 @@ "lstrip_blocks": true, "trim_blocks": true }, - "_template": "https://github.com/kjaymiller/cookiecutter-relecloud/" + "_template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator" } }, "directory": null diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ecd2e4e..dc6fb7c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose { - "name": "azure_fastapi_cosmos_postgres_aca", + "name": "azure-fastapi-cosmos-postgres-aca", // Update the 'dockerComposeFile' list if you have more compose files or use different names. // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. @@ -32,7 +32,8 @@ "files.exclude": { ".coverage": true, ".pytest_cache": true, - "__pycache__": true + "__pycache__": true, + ".ruff_cache": true }, "[python]": { "editor.formatOnSave": true, diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index 3013f96..f825973 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -103,5 +103,5 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m pip install -r requirements-dev.txt - python3 -m playwright install --with-deps + python3 -m playwright install chromium --with-deps python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a35fabb..fd6a60c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,37 +14,56 @@ jobs: strategy: fail-fast: false matrix: - os: ["ubuntu-20.04"] + os: ["ubuntu-latest", "macos-latest", "macos-latest-xlarge", "windows-latest"] python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - services: - db: - image: postgres:14 - env: - POSTGRES_PASSWORD: postgres - ports: - - 5432:5432 - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + exclude: + - os: macos-latest-xlarge + python_version: 3.8 + - os: macos-latest-xlarge + python_version: 3.9 + - os: macos-latest-xlarge + python_version: "3.10" steps: - - uses: actions/checkout@v3 - - name: Setup python - uses: actions/setup-python@v2 - with: + - name: Checkout + uses: actions/checkout@v3 + - name: Check for MacOS Runner + if: matrix.os == 'macos-latest-xlarge' + run: brew install postgresql@14 + - name: Setup postgres + uses: ikalnytskyi/action-setup-postgres@v4 + - name: Setup python + uses: actions/setup-python@v2 + with: - python-version: ${{ matrix.python_version }} - architecture: x64 - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r requirements-dev.txt - playwright install --with-deps - python3 -m pip install -e src - - name: Seed data and run Pytest tests - run: | - python3 src/fastapi_app/seed_data.py - python3 -m pytest - env: - POSTGRES_HOST: localhost - POSTGRES_USERNAME: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DATABASE: postgres + python-version: ${{ matrix.python_version }} + architecture: x64 + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements-dev.txt + playwright install chromium --with-deps + python3 -m pip install -e src + - name: Seed data + run: | + python3 src/fastapi_app/seed_data.py + env: + POSTGRES_HOST: localhost + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DATABASE: postgres + - name: Run tests Windows + if: runner.os == 'windows' + run: python3 -m pytest --ignore=src/tests/local/test_gunicorn.py + env: + POSTGRES_HOST: localhost + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DATABASE: postgres + - name: Run tests + if: runner.os != 'windows' + run: python3 -m pytest + env: + POSTGRES_HOST: localhost + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DATABASE: postgres \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index f1aa0c4..cd7c512 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,15 @@ "fastapi_app:app", "--reload" ], + }, + { + "name": "Python: Debug Tests", + "type": "python", + "request": "launch", + "program": "${file}", + "purpose": ["debug-test"], + "console": "integratedTerminal", + "env": {"PYTEST_ADDOPTS": "--no-cov"} } ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 0909470..f4d0a32 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ +--- +page_type: sample +languages: +- azdeveloper +- python +- bicep +- html +- css +- scss +products: +- azure +- azure-container-apps +- azure-postgresql +- azure-cosmos-db +urlFragment: azure-fastapi-cosmos-postgres-aca +name: Deploy FastAPI Application with PostgreSQL on Azure Container Apps (Python) +description: This project deploys a web application for a space travel agency using FastAPI with Python, and is set up for easy deployment with the Azure Developer CLI. +--- + + # Deploy FastAPI Application with PostgreSQL via Azure Container Apps This project deploys a web application for a space travel agency using FastAPI. The application can be deployed to Azure with Azure Container Apps using the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview). @@ -55,7 +75,7 @@ python3 -m uvicorn fastapi_app:app --reload --port=8000 ```sh python3 -m pip install -r requirements-dev.txt - python3 -m playwright install --with-deps + python3 -m playwright install chromium --with-deps ``` 3. Run the tests: diff --git a/pyproject.toml b/pyproject.toml index 4d262c0..1e0a350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,3 +9,6 @@ known-first-party = ["fastapi_app"] [tool.pytest.ini_options] addopts = "-ra -vv" + +[tool.coverage.report] +show_missing = true diff --git a/requirements-dev.txt b/requirements-dev.txt index c2c4369..6784c50 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,6 +8,9 @@ pip-tools pytest ephemeral-port-reserve pytest-playwright +coverage +pytest-cov +axe-playwright-python # Linters ruff diff --git a/src/fastapi_app/models.py b/src/fastapi_app/models.py index da3b655..201a705 100644 --- a/src/fastapi_app/models.py +++ b/src/fastapi_app/models.py @@ -16,7 +16,7 @@ if POSTGRES_SSL: sql_url = f"{sql_url}?sslmode={POSTGRES_SSL}" -engine = create_engine(sql_url, echo=True) +engine = create_engine(sql_url) def create_db_and_tables(): diff --git a/src/static/manifest.json b/src/static/manifest.json new file mode 100644 index 0000000..6abc49c --- /dev/null +++ b/src/static/manifest.json @@ -0,0 +1,30 @@ +{ + "name": "ReleCloud Space Tourism", + "short_name": "ReleCloud", + "start_url": ".", + "display": "standalone", + "background_color": "#fff", + "description": "ReleCloud Space Tourism", + "icons": [ + { + "src": "/static/res/img/favicon.ico", + "sizes": "32x32", + "type": "image/x-icon" + }, + { + "src": "/static/res/img/favicon-120-precomposed.png", + "sizes": "120x120", + "type": "image/png" + }, + { + "src": "/static/res/img/favicon-152-precomposed.png", + "sizes": "152x152", + "type": "image/png" + }, + { + "src": "/static/res/img/favicon-192.png", + "sizes": "192x192", + "type": "image/png" + } + ] +} diff --git a/src/templates/base.html b/src/templates/base.html index 20bda0f..cfe04a2 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -4,21 +4,26 @@ {% if prod %} {% endif %} - + - + - + - + - + - +
Fill out the form below to request information about our cruises