diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1bb2869 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,49 @@ +name: Deploy + +on: + push: + branches: + - deploy-to-aws + +permissions: + id-token: write + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + name: Deploy + environment: deploy-to-aws + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup + - uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/atoti-project-template-deployment + aws-region: ${{ secrets.AWS_REGION }} + - uses: aws-actions/amazon-ecr-login@v1 + id: login-ecr + - name: Build, tag, and push Docker image to Amazon ECR + id: build-tag-and-push-docker-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: atoti-project-template + IMAGE_TAG: ${{ github.sha }} + run: | + poetry run app build-docker $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + - name: Inline variables in the task definition + run: sed -i -e 's/AWS_ACCOUNT_ID/${{ secrets.AWS_ACCOUNT_ID }}/g' -e 's/AWS_REGION/${{ secrets.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 }} + - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.render-task-definition.outputs.task-definition }} + service: atoti-project-template + cluster: atoti-project-template + wait-for-service-stability: true diff --git a/README.md b/README.md index c0f3e20..5043ec6 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,7 @@ # 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](https://docs.atoti.io/latest/deployment/going_from_a_notebook_to_an_app.html). +Switch to the [default branch](https://github.com/atoti/project-template#readme) to learn how to use this template. -On top of the `atoti` package, it comes with: +## Deploy to AWS -- Dependency management with [Poetry](https://python-poetry.org) -- Settings management with [Pydantic](https://docs.pydantic.dev/2.5/concepts/pydantic_settings) -- Testing with [pytest](https://docs.pytest.org) -- Type checking with [mypy](http://mypy-lang.org) -- Formatting and linting with [Ruff](https://beta.ruff.rs) -- Continuous testing with [GitHub Actions](https://github.com/features/actions) - -## Usage - -### Installation - -- [Install `poetry`](https://python-poetry.org/docs/#installation) -- Install the dependencies: - - ```bash - poetry install - ``` - -### Commands - -To get a list of the commands that can be executed to interact with the project, run: - -```bash -poetry run app --help -``` - -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 - ``` - -## Variants - -This repository has the following long-lived branches showcasing different aspects: - -- [`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. +This branch shows [the modifications](https://github.com/atoti/project-template/compare/deploy-to-aws) required to deploy a project to Amazon ECS. diff --git a/task-definition.json b/task-definition.json new file mode 100644 index 0000000..d013ad4 --- /dev/null +++ b/task-definition.json @@ -0,0 +1,35 @@ +{ + "executionRoleArn": "atoti-project-template-role", + "containerDefinitions": [ + { + "name": "atoti-session", + "essential": true, + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/atoti-project-template", + "awslogs-region": "AWS_REGION", + "awslogs-stream-prefix": "ecs" + } + }, + "portMappings": [ + { + "hostPort": 80, + "protocol": "tcp", + "containerPort": 80 + } + ], + "secrets": [ + { + "name": "DATABASE_URL", + "valueFrom": "arn:aws:secretsmanager:AWS_REGION:AWS_ACCOUNT_ID:secret:atoti-project-template/database-dsn-ZS3pzB" + } + ] + } + ], + "family": "atoti-project-template", + "cpu": "1024", + "memory": "2048", + "requiresCompatibilities": ["FARGATE"], + "networkMode": "awsvpc" +}