Skip to content

Commit 4ce4d5d

Browse files
committed
infra: add documentation on managing ecs services
1 parent 8c90416 commit 4ce4d5d

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- [Discord moderation bot](./infra/docs/discord-mods-bot.md)
4747
- [Domain names and DNS](./infra/docs/dns.md)
4848
- [docs.rs](./infra/docs/docs-rs.md)
49+
- [ECS services management](./infra/docs/ecs-services.md)
4950
- [Monitoring](./infra/docs/monitoring.md)
5051
- [rust-bots server](./infra/docs/rust-bots.md)
5152
- [rust-lang/rust CI](./infra/docs/rustc-ci.md)

src/infra/docs/ecs-services.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# ECS services management
2+
3+
Some applications running on the project's infrastructure are hosted in ECS
4+
clusters on our AWS account. This document explains the common maintenance
5+
procedures one should follow when operating them. Most of the actions explained
6+
here [require AWS access][aws-access].
7+
8+
## Inspecting the logs
9+
10+
Logs for applications hosted on ECS are stored in CloudWatch Logs, and can
11+
be inspected in the AWS Console. [Open the console][console-access], go to
12+
CloudWatch Logs and select the log group called `/ecs/<service-name>`. There
13+
are two ways to inspect the logs:
14+
15+
* If you need to look at the application as a whole, you can get an aggregated
16+
view by clicking the "View all log events" button (or, on the classic
17+
interface, "Search Log Group").
18+
19+
* If you need to debug a specific instance of a container, separate log streams
20+
for each running task are available. The streams are named after the
21+
container name and the task ID.
22+
23+
Logs are periodically purged (retention varies based on the specific
24+
application).
25+
26+
## Restarting an application
27+
28+
To restart an application, you can force a new deployment without actually
29+
pushing any new code beforehand. To do so, run this command:
30+
31+
```
32+
aws ecs update-service --cluster rust-ecs-prod --service <service-name> --force-new-deployment
33+
```
34+
35+
## Deploying application changes
36+
37+
Each application stores its own Docker container in a [ECR repository][ecr] in
38+
our AWS account. You can deploy changes both manually and automatically (with
39+
GitHub Actions).
40+
41+
For production applications it's recommended to setup automatic deployment.
42+
43+
### Manual deployments
44+
45+
To manually deploy a local build you first need it to tag your built image
46+
with its ECR name:
47+
48+
```
49+
docker tag <image-tag> 890664054962.dkr.ecr.us-west-1.amazonaws.com/<repository-name>:latest
50+
```
51+
52+
Then you can authenticate with ECR and push it:
53+
54+
```
55+
$(aws ecr get-login --no-include-email --region us-west-1)
56+
docker push 890664054962.dkr.ecr.us-west-1.amazonaws.com/<repository-name>:latest
57+
```
58+
59+
Finally, you need to force a new deployment of the ECS service with:
60+
61+
```
62+
aws ecs update-service --cluster rust-ecs-prod --service <service-name> --force-new-deployment
63+
```
64+
65+
### Automatic deployments with GitHub Actions
66+
67+
The infrastructure team prepared an action for GitHub Actions that automates
68+
deployments from CI. To use it, ask a team member to setup AWS credentials in
69+
your repository, and then add this snippet to your workflow:
70+
71+
72+
```
73+
- name: Build the Docker image
74+
run: docker build -t deploy-image .
75+
76+
- name: Deploy to production
77+
uses: rust-lang/simpleinfra/github-actions/upload-docker-image@master
78+
with:
79+
image: deploy-image
80+
repository: <ecr-repository-name>
81+
region: us-west-1
82+
redeploy_ecs_cluster: rust-ecs-prod
83+
redeploy_ecs_service: <service-name>
84+
aws_access_key_id: "${{ secrets.AWS_ACCESS_KEY_ID }}"
85+
aws_secret_access_key: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
86+
if: github.ref == 'refs/heads/<deploy-branch>'
87+
```
88+
89+
Be sure to replace `<ecr-repository-name>`, `<service-name>` and
90+
`<deploy-branch>` with the correct values for your workflow. Once the workflow
91+
changes are merged in the branch you chose for deploys, any future commits
92+
pushed there will be deployed to the ECS cluster.
93+
94+
[aws-access]: aws-access.md
95+
[console-access]: aws-access.md#using-the-aws-console
96+
[ecr]: https://aws.amazon.com/ecr/

0 commit comments

Comments
 (0)