Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync deploy-to-heroku with main #118

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a310f4f
Bump pylint from 2.13.7 to 2.13.9 (#114)
dependabot[bot] May 17, 2022
f1fa47f
Bump types-requests from 2.27.22 to 2.27.25 (#113)
dependabot[bot] May 17, 2022
ba44b31
Merge f1fa47f9ecb5d7bd7f6fc222613f68096eb231a0 into sync-deploy-to-he…
github-actions[bot] May 17, 2022
9f5662f
Bump atoti from 0.6.5 to 0.6.6 (#121)
dependabot[bot] May 24, 2022
91beee6
Merge 9f5662f7d7f90a199b0394820d6960335f38ae93 into sync-deploy-to-he…
github-actions[bot] May 24, 2022
74cfd0e
Add link to docs.atoti.io (#99)
tibdex May 24, 2022
9fe16af
Merge 74cfd0eb277c8e561b05af1ba92696c2b77faced into sync-deploy-to-he…
github-actions[bot] May 24, 2022
eb66ed0
Bump pydantic from 1.9.0 to 1.9.1 (#120)
dependabot[bot] Jun 21, 2022
43dc424
Merge eb66ed08259412c7f9e7e8e728b7e46004f06cf8 into sync-deploy-to-he…
github-actions[bot] Jun 21, 2022
3b5da59
Bump pandas-stubs from 1.2.0.58 to 1.2.0.61 (#124)
dependabot[bot] Jun 21, 2022
5c3108e
Merge 3b5da593f4e531d091c64f151c8359a6feddd1e1 into sync-deploy-to-he…
github-actions[bot] Jun 21, 2022
08ca771
Bump types-requests from 2.27.25 to 2.28.2 (#132)
dependabot[bot] Jul 20, 2022
ec1f272
Merge 08ca771e2e11e9cf1da4f0146d20bef5a36ca12b into sync-deploy-to-he…
github-actions[bot] Jul 20, 2022
cc20293
Upgrade dependencies (#136)
tibdex Sep 6, 2022
4b7c16f
Merge cc20293647b69f408d8e38ace25769c0f6ed5b12 into sync-deploy-to-he…
github-actions[bot] Sep 6, 2022
ab81c56
Upgrade atoti and other dependencies (#146)
tibdex Oct 20, 2022
2158d8a
Merge ab81c56d0d1c2f4db1047cf93006de2d69e9278b into sync-deploy-to-he…
github-actions[bot] Oct 20, 2022
1c6a4e5
Update GitHub Actions (#148)
tibdex Oct 20, 2022
fa84b73
Merge 1c6a4e51f11cefd6be806f80afc1e5ae27addbba into sync-deploy-to-he…
github-actions[bot] Oct 20, 2022
2199579
Update to Atoti 0.7.4 and Python 3.10 (#170)
tibdex Mar 21, 2023
be03a46
Merge 2199579e8c403ea56b5d6255b52a9fd4c82298a1 into sync-deploy-to-he…
github-actions[bot] Mar 21, 2023
66c28f9
Upgrade dependencies (#178)
tibdex Apr 4, 2023
4a42091
Merge 66c28f9a942d5c38569a85cf306f964f428a014f into sync-deploy-to-he…
github-actions[bot] Apr 4, 2023
bb5a36e
Update to Atoti 0.8.0 (#196)
tibdex Jun 6, 2023
93d0f02
Merge bb5a36ed60d168f6c3bc88fabe35bbd788bb8e97 into sync-deploy-to-he…
github-actions[bot] Jun 6, 2023
85279b9
Fix data issue (#197)
tibdex Jun 26, 2023
4186d47
Merge 85279b9bfaee6e7679e50e3a9d807b2b33687104 into sync-deploy-to-he…
github-actions[bot] Jun 26, 2023
5af7272
Fix error raised when refreshing the data (#206)
tibdex Jun 27, 2023
d537c88
Merge 5af7272d7a5bbded7fa263b586a914b370ee645f into sync-deploy-to-he…
github-actions[bot] Jun 27, 2023
5d2e5fc
Update dependencies (#215)
tibdex Jul 13, 2023
496ad14
Merge 5d2e5fceb0d4635826859f006c7715c399d8fbf9 into sync-deploy-to-he…
github-actions[bot] Jul 13, 2023
9e682ef
Shorten data types access (#219)
tibdex Jul 24, 2023
79e5c79
Merge 9e682efe3451095e6ac794cfbc937ea30f11603b into sync-deploy-to-he…
github-actions[bot] Jul 24, 2023
2056078
Update to Atoti 0.8.3 (#225)
tibdex Aug 4, 2023
5e15aa6
Merge 2056078e9c5d23b797017b451248fef8f5ce42d5 into sync-deploy-to-he…
github-actions[bot] Aug 4, 2023
a93757a
Update dependencies (#252)
tibdex Jan 5, 2024
c98bbbf
Merge a93757a4ab06937c8d84c8df432676a3190a5631 into sync-deploy-to-he…
github-actions[bot] Jan 5, 2024
b774b7b
Update to Atoti Python API 0.8.9 (#264)
tibdex Feb 14, 2024
b68727b
Merge b774b7b8df8dcab1dc2800e1efe55bc25ae9dfac into sync-deploy-to-he…
github-actions[bot] Feb 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/actions/install-dependencies/action.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Setup the repository
description: Set up Python, install Poetry and the dependencies
runs:
using: "composite"
steps:
- run: pipx install poetry==1.7.1
shell: bash
- uses: actions/setup-python@v5
with:
cache: poetry
python-version: "3.9.18"
- run: poetry install
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/sync-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
sync:
name: Sync branches
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
if: >
!github.event.deleted
steps:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ on:
jobs:
test:
name: Test
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/install-dependencies
- run: poetry run app format --check
- run: poetry run app sort-imports --check
- run: poetry run app lint
- run: poetry run app typecheck
- run: poetry run app test
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: poetry check --lock
- run: poetry run ruff format --check
- run: poetry run ruff check
- run: poetry run mypy
- run: poetry run pytest
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
__pycache__/
.docker/
.mypy_cache/
.pytest_cache/
.venv/
content/
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.python",
"tamasfe.even-better-toml"
],
"unwantedRecommendations": []
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnType": true
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"python.analysis.autoImportCompletions": true,
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

## Scope

This project is not intended to become a showcase of all atoti's features.
This project is not intended to become a showcase of all Atoti's features.
It should have just enough structure to show how to start a project on sound and modular foundations, not more.
https://docs.atoti.io/ is the right place to discover and learn what atoti can do.
https://docs.atoti.io is the right place to discover and learn what Atoti can do.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# syntax=docker/dockerfile:1.2
FROM python:3.9.12-slim AS builder

RUN --mount=type=cache,target=/root/.cache pip install poetry==1.1.12
RUN poetry config virtualenvs.create false
# `--platform=linux/am64` is required to build this image on macOS with Apple Silicon until https://github.com/activeviam/jdk4py/issues/73 is done.
FROM --platform=linux/amd64 python:3.9.18-slim AS builder

RUN pip install poetry==1.7.1

COPY poetry.lock pyproject.toml ./

RUN --mount=type=cache,target=/root/.cache poetry install --no-ansi --no-dev --no-interaction --no-root
RUN POETRY_VIRTUALENVS_CREATE=false poetry install --no-cache --no-root --only main --sync

FROM python:3.9.12-slim AS runner
FROM --platform=linux/amd64 python:3.9.18-slim AS runner

ENV ATOTI_DISABLE_TELEMETRY=true
ENV ATOTI_HIDE_EULA_MESSAGE=true
ENV PORT=80

Expand Down
40 changes: 10 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# atoti Project Template
# Atoti Project Template

This template can be used to start atoti projects where the goal is to go into production rather than prototyping in a notebook.
This template can be used to start Atoti projects where the goal is to [go into production rather than prototyping in a notebook](https://docs.atoti.io/latest/deployment/going_from_a_notebook_to_an_app.html).

On top of the `atoti` package, it comes with:

- Dependency management with [Poetry](https://python-poetry.org/)
- Settings management with [pydantic](https://pydantic-docs.helpmanual.io/usage/settings/)
- Testing with [pytest](https://docs.pytest.org/)
- Type checking with [mypy](http://mypy-lang.org/)
- Formatting with [Black](https://black.readthedocs.io/) and [isort](https://pycqa.github.io/isort/)
- Linting with [Pylint](https://www.pylint.org/)
- Dependency management with [Poetry](https://python-poetry.org)
- Config management with [Pydantic Settings](https://docs.pydantic.dev/2.6/concepts/pydantic_settings)
- Testing with [pytest](https://docs.pytest.org)
- Type checking with [mypy](http://mypy-lang.org)
- Formatting and linting with [Ruff](https://docs.astral.sh/ruff)
- Continuous testing with [GitHub Actions](https://github.com/features/actions)

## Usage
Expand All @@ -25,36 +24,17 @@ On top of the `atoti` package, it comes with:

### Commands

To get a list of the commands that can be executed to interact with the project, run:
To start the app:

```bash
poetry run app --help
poetry run python -m main
```

A few examples:

- Start the app:

```bash
poetry run app start
```

- Launch the tests:

```bash
poetry run app test
```

- Reformat the code:

```bash
poetry run app format
```
Other useful commands can be found in [`test.yml`](.github/workflows/test.yml).

## Variants

This repository has the following long-lived branches showcasing different aspects:

- [`atoti-plus`](https://github.com/atoti/project-template/tree/atoti-plus) for upgrading to Atoti+.
- [`deploy-to-aws`](https://github.com/atoti/project-template/tree/deploy-to-aws) for deploying on AWS ECS.
- [`deploy-to-heroku`](https://github.com/atoti/project-template/tree/deploy-to-heroku) for a one-click deploy to Heroku.
4 changes: 3 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .app import *
from __future__ import annotations

from .config import *
from .constants import *
from .start_app import *
10 changes: 5 additions & 5 deletions app/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import App, Config
from __future__ import annotations

config = Config()
from . import Config, start_app

with App(config=config) as app:
print(f"Session listening on port {app.session.port}")
app.session.wait()
with start_app(config=Config()) as session:
print(f"Session listening on port {session.port}") # noqa: T201
session.wait()
47 changes: 0 additions & 47 deletions app/app.py

This file was deleted.

62 changes: 37 additions & 25 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,66 @@
# ruff: noqa: UP007
# Pydantic evaluates type annotations at runtime which does not support `|`.

from __future__ import annotations

from datetime import timedelta
from pathlib import Path
from typing import Any, Optional, Union
from typing import Annotated, Optional, Union

from pydantic import (
BaseSettings,
AliasChoices,
DirectoryPath,
Field,
FilePath,
HttpUrl,
PostgresDsn,
validator,
TypeAdapter,
field_validator,
)
from pydantic_settings import BaseSettings, SettingsConfigDict

from .util import normalize_postgres_dsn_for_atoti_sql


class Config(BaseSettings):
"""Hold all the configuration properties of the app, not only the ones related to atoti.
"""Hold all the configuration properties of the app, not only the ones related to Atoti.

See https://pydantic-docs.helpmanual.io/usage/settings/.
"""

model_config = SettingsConfigDict(frozen=True)

data_refresh_period: Optional[timedelta] = timedelta(minutes=1)

# The $PORT environment variable is used by most PaaS to indicate the port the app server should bind to.
port: int = 9090

reverse_geocoding_path: Union[HttpUrl, FilePath] = Field(
default="https://api-adresse.data.gouv.fr/reverse/csv/"
)
requests_timeout: timedelta = timedelta(seconds=30)

user_content_storage: Optional[Union[PostgresDsn, Path]] = Field(
default=Path("content"),
# $DATABASE_URL is used by some PaaS such to designate the URL of the app's primary database.
# For instance: https://devcenter.heroku.com/articles/heroku-postgresql#designating-a-primary-database.
env="database_url",
)
reverse_geocoding_path: Union[HttpUrl, FilePath] = TypeAdapter(
HttpUrl
).validate_python("https://api-adresse.data.gouv.fr/reverse/csv/")

user_content_storage: Annotated[
Optional[Union[PostgresDsn, Path]],
Field(
# $DATABASE_URL is used by some PaaS such to designate the URL of the app's primary database.
# For instance: https://devcenter.heroku.com/articles/heroku-postgresql#designating-a-primary-database.
validation_alias=AliasChoices("user_content_storage", "database_url")
),
] = Path("content")

velib_data_base_path: Union[HttpUrl, DirectoryPath] = Field(
default="https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole"
velib_data_base_path: Union[HttpUrl, DirectoryPath] = TypeAdapter(
HttpUrl
).validate_python(
"https://velib-metropole-opendata.smovengo.cloud/opendata/Velib_Metropole"
)

@validator("user_content_storage")
@field_validator("user_content_storage")
@classmethod
def normalize_postgresql_dsn(cls, value: Union[PostgresDsn, Any]) -> Any:
return (
normalize_postgres_dsn_for_atoti_sql(value)
if isinstance(value, PostgresDsn)
else value
)

class Config:
allow_mutation = False
def normalize_postgres_dsn(cls, value: object) -> object:
try:
postgres_dsn: PostgresDsn = TypeAdapter(PostgresDsn).validate_python(value)
return normalize_postgres_dsn_for_atoti_sql(postgres_dsn)
except ValueError:
return value
2 changes: 2 additions & 0 deletions app/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from enum import Enum


Expand Down
Loading