Skip to content

Commit

Permalink
Finishing touch
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex committed Sep 17, 2024
1 parent bc2c128 commit dd73ece
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- update-to-0.9.0

permissions:
id-token: write
Expand All @@ -19,8 +18,8 @@ jobs:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ vars.AWS_DEPLOYMENT_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ vars.AWS_DEPLOYMENT_ROLE }}
- uses: aws-actions/amazon-ecr-login@v2
id: log-into-ecr
- name: Build, tag, and push Docker image to Amazon ECR
Expand All @@ -30,18 +29,18 @@ jobs:
run: |
docker build --tag $TAG .
docker push $TAG
echo "image=$TAG" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Inline variables in the task definition
run: sed -i -e 's/AWS_ACCOUNT_ID/${{ secrets.AWS_ACCOUNT_ID }}/g' -e 's/AWS_DATABASE_URL_SECRET_NAME/${{ vars.AWS_DATABASE_URL_SECRET_NAME }}/g' -e 's/AWS_EXECUTION_ROLE/${{ vars.AWS_EXECUTION_ROLE }}/g' -e 's/AWS_REGION/${{ vars.AWS_REGION }}/g' task-definition.json
- uses: aws-actions/amazon-ecs-render-task-definition@v1
id: render-task-definition
with:
task-definition: task-definition.json
container-name: atoti-session
image: ${{ steps.build-tag-and-push-docker-image.outputs.image }}
image: ${{ steps.build-tag-and-push-docker-image.outputs.tag }}
task-definition: task-definition.json
- uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.render-task-definition.outputs.task-definition }}
service: atoti-project-template
cluster: atoti-project-template
service: atoti-project-template
task-definition: ${{ steps.render-task-definition.outputs.task-definition }}
wait-for-service-stability: true
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"python.analysis.autoImportCompletions": true,
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
"python.testing.unittestEnabled": false,
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///Users/tibdex/repositories/project-template/.github/workflows/deploy.yml"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This template can be used to start Atoti projects where the goal is to [go into
On top of the `atoti` package, it comes with:

- Dependency management with [uv](https://docs.astral.sh/uv)
- Config management with [Pydantic Settings](https://docs.pydantic.dev/2.6/concepts/pydantic_settings)
- Config management with [Pydantic](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)
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ dependencies = [
]

[tool.mypy]
# Remove once https://github.com/python/mypy/issues/10428 is fixed.
files = "app,tests"
files = "app,tests" # Remove once https://github.com/python/mypy/issues/10428 is fixed.
strict = true
warn_redundant_casts = true
warn_unused_configs = true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app import Config, start_app

_TESTS_DIRECTORY = Path(__file__).parent
_TESTS_DATA_PATH = _TESTS_DIRECTORY / "data"
_TESTS_RESOURCES_DIRECTORY = _TESTS_DIRECTORY / "__resources__"
_PROJECT_DIRECTORY = _TESTS_DIRECTORY.parent


Expand All @@ -20,10 +20,10 @@ def project_name_fixture() -> str:
def config_fixture() -> Config:
return Config(
data_refresh_period=None,
reverse_geocoding_path=_TESTS_DATA_PATH / "station_location.csv",
reverse_geocoding_path=_TESTS_RESOURCES_DIRECTORY / "station_location.csv",
port=0,
user_content_storage=None,
velib_data_base_path=_TESTS_DATA_PATH,
velib_data_base_path=_TESTS_RESOURCES_DIRECTORY,
)


Expand Down
9 changes: 9 additions & 0 deletions tests/docker/_run_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from collections.abc import Mapping, Sequence
from subprocess import STDOUT, CalledProcessError, check_output


def run_command(args: Sequence[str], /, *, env: Mapping[str, str] | None = None) -> str:
try:
return check_output(args, env=env, stderr=STDOUT, text=True) # noqa: S603
except CalledProcessError as error:
raise RuntimeError(f"Command `{error.cmd}` failed:\n{error.output}") from error
21 changes: 6 additions & 15 deletions tests/docker/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
from collections.abc import Generator, Mapping, Sequence
from collections.abc import Generator
from datetime import timedelta
from pathlib import Path
from shutil import which
from subprocess import STDOUT, CalledProcessError, check_output
from uuid import uuid4

import atoti as tt
import docker
import pytest

from ._docker_container import docker_container as _docker_container
from ._docker_container import docker_container
from ._run_command import run_command
from ._timeout import Timeout


def _run_command(
args: Sequence[str], /, *, env: Mapping[str, str] | None = None
) -> str:
try:
return check_output(args, env=env, stderr=STDOUT, text=True) # noqa: S603
except CalledProcessError as error:
raise RuntimeError(f"Command `{error.cmd}` failed:\n{error.output}") from error


@pytest.fixture(name="docker_bin", scope="session")
def docker_bin_fixture() -> Path:
docker_bin = which("docker")
Expand All @@ -43,12 +34,12 @@ def docker_image_name_fixture(
# BuildKit is enabled by default for all users on Docker Desktop.
# See https://docs.docker.com/build/buildkit/#getting-started.
is_buildkit_already_enabled = (
"docker desktop" in _run_command([str(docker_bin), "version"]).lower()
"docker desktop" in run_command([str(docker_bin), "version"]).lower()
)

# BuildKit is not supported by Docker's Python SDK so `docker_client.images.build` cannot be used.
# See https://github.com/docker/docker-py/issues/2230.
output = _run_command(
output = run_command(
[str(docker_bin), "build", "--tag", tag, "."],
env=None if is_buildkit_already_enabled else {"DOCKER_BUILDKIT": "1"},
)
Expand All @@ -63,7 +54,7 @@ def session_inside_docker_container_fixture(
) -> Generator[tt.Session, None, None]:
timeout = Timeout(timedelta(minutes=1))

with _docker_container(docker_image_name, client=docker_client) as container:
with docker_container(docker_image_name, client=docker_client) as container:
logs = container.logs(stream=True)

while "Session listening on port" not in next(logs).decode():
Expand Down

0 comments on commit dd73ece

Please sign in to comment.