-
Make sure you have an AWS user with
SuperPowerUsers
group -
Configure your AWS credentials:
Get your
Access key ID
andSecret access key
inIAM
section of AWS Console and save them on your machine underaiarena
profile:- go to https://315513665747.signin.aws.amazon.com/console
- in the IAM find your user, go to
Security credentials
and create an access key if you don't have one - use the credentials to configure AWS:
$ aws configure --profile aiarena AWS Access Key ID [None]: ****** AWS Secret Access Key [None]: ****** Default region name [None]: eu-central-1 Default output format [None]:
We're running the application code inside of Fargate containers, so to deploy a new version to prod, we need to build a new Docker image, and then update the Fargate containers to use it.
Here's how the deployment process works:
- Chagnes are pushed to the
main
branch - GitHub Actions starts running tests/linters and in parallel runs
run.py prepare-images
, which builds an image and pushes it to Elastic Container Registry with a tag likebuild-111-amd64
- If all tests/linters passed,
run.py ecs
runs next:- It makes a
latest
alias to the image that we built earlier - Then, it runs
manage.py migrate
- Finally, it triggers a rolling update to all the Fargate containers, that will use the
latest
image
- It makes a
- As a final step,
run.py monitor-ecs
runs. It watches the rolling update, and makes sure all the services are replaced, and running. This step can fail if the containers are failing to start for some reason.
Pre-requisites:
- Install local development tools and configure your AWS credentials, as described above;
- Install AWS Session Manager plugin.
After that you should be able to use the python3 run.py production-one-off-task
command.
It will spin up a new task with no production traffic routed to it, and with custom CPU and memory values.
By default, the task will be killed in 24 hours to make sure it's not consuming money after it's finished. You can use the --lifetime-hours
flag to override this behaviour if you need to run something really long.
Also, by default, the task is killed early if you disconnect from the ssh session. Use the --dont-kill-on-disconnect
flag to disable this behaviour, if you want it running in the background.
Pre-requisites:
- Install local development tools and configure your AWS credentials, as described above;
- Install AWS Session Manager plugin.
After that you should be able to use the python3 run.py production-attach-to-task
command. It will help you find an existing production container, and connect you to it.
You can also specify a task ID with --task-id <task id here>
flag, if you already have one (for example, if you created a one-off task).
This is the way we do Infrastructure-as-Code. All the AWS resources we have are in index-default.yaml
template file. Make some changes to it, and then generate a CloudFormation template based on it:
python3 run.py cloudformation
The template would be saved to cloudformation-default.yaml
in the project root
directory. Next, use this template to update the stack in CloudFormation
section of AWS Console:
- Select
aiarena
and clickUpdate
- Choose
Replace current template
- Choose
Upload a template file
, and select thecloudformation-default.yaml
file that you generated in the previous step. Then click next. - Update the variables if you want to, then click next until you get to the last screen.
- On the last screen please wait for the
Change set preview
to be generated, it can take a minute. Take a look at the preview, and make sure it makes sense. - Click
Submit
and watch the infrastructure change