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

Make app resilient to Fly.io IAD region failures #543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Sets current production
export APP_PROD_INSTANCE=changelog-2024-01-12

# Required for op to know which account to use
export OP_ACCOUNT=changelog.1password.com

Expand Down
32 changes: 16 additions & 16 deletions INFRASTRUCTURE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![shields.io](https://img.shields.io/badge/Last%20updated%20on-Sep.%202%2C%202024-success?style=for-the-badge)](https://shipit.show/80)
[![shields.io](https://img.shields.io/badge/Last%20updated%20on-Feb.%2022%2C%202025-success?style=for-the-badge)](https://shipit.show/80)

This diagram shows the current changelog.com setup:

Expand All @@ -21,33 +21,29 @@ graph TD
registry(( fab:fa-github ghcr.io )):::link
click registry "https://github.com/orgs/thechangelog/packages"

chat(( fab:fa-slack Slack )):::link
click chat "https://changelog.slack.com/archives/C03SA8VE2"
chat(( fab:fa-z Zulip )):::link
click chat "https://changelog.zulipchat.com/#narrow/channel/455097-kaizen/topic/Code.20deploys"

repo -.-> |.github/workflows/ship_it.yml| cicd
cicd --> |magefiles/magefiles.go| automation

cicd --> |success #dev| chat
cicd --> |success #kaizen code| chat
end

repo -.- |fly.io/changelog-2024-01-12| app

registry --> |ghcr.io/changelog/changelog-prod| app
runner --> |flyctl deploy| app

repo -.- |fly.io/dagger-engine-2024-03-28| dagger010

repo -.- |fly.io/pghero-2024-03-27| pghero

%% PaaS - https://fly.io/dashboard/changelog
subgraph Fly.io
proxy{fa:fa-globe Proxy}
proxy ==> |https| app

dagger010([ fa:fa-project-diagram Dagger Engine v0.10 2024-03-28 ]):::link
click dagger010 "https://fly.io/apps/dagger-engine-2024-03-28"

app(( fab:fa-phoenix-framework App changelog-2024-01-12.fly.dev )):::link

app(( fab:fa-phoenix-framework IAD & EWR changelog-2024-01-12.fly.dev )):::link
style app fill:#488969;
click app "https://fly.io/apps/changelog-2024-01-12"

Expand All @@ -57,7 +53,6 @@ graph TD
grafana[ fa:fa-columns Grafana fly-metrics.net ]:::link
click grafana "https://fly-metrics.net"
grafana -.- |metrics| app
grafana -.- |metrics| dagger010
grafana -.- |metrics| pghero
end

Expand Down Expand Up @@ -141,7 +136,7 @@ graph TD
```

> [!TIP]
> [Continue live editing this Mermaid diagram](https://mermaid.live/edit#pako:eNqVWHlv2zYU_yqEihUtEEk-4nPrhqzp0qHYFsw7gMXDQEnPkhaJ1EgqiRfnu-9R1EE5VrvmD0em3v1-76AfnZBH4KydL74giVKFXPv-jjNF70HyHLyQ574EKsJky2JBi4T8crllBP_CjEp5CTuSpeyWSCX4LaxfzFbBZLk4M1_d-zRSyXpaPHxpeMwnqnqLSslLghJASXMqy8AouErV-zIwh_pPQMEfH8mOBusddeNUJWVAVAJhQlkMGY_99kmbS56e1uu1NqoTEWZpeFsJIluncdNIqjwclrZ1tsySk4bRjY-maEvCVIQZuCHy3tZGk4tQpZwRl2yStCDfK7Ld_jlgjZb1udb4tJIv_XsubncZv5e-REV_pcrb55m2tdHRPdFS8Zxqtpvtto0iz1AsuaRxDIJccbK5_ED8IVM7EZ9tcJDxwM-pVCDwXwy7NAPZPXkx70dYQJwiePavXh0lPE5C4aWcvH49mF3DedpELmLZt7Og4S2aIY8ynFDV6ZYZEpFN9TmoWLNYSjv_K26TNqyf9A4dfzuabi6Wv72bHHuNyHQ992ty8IzRpzN8qFDTxyNxNdvp2B6s1J3CRscvyzAEKcmLCO4OlUuGClhkl25jKDnssj2mo_PWnYwm5-5o7I4nqLUo-lx1aipVdSb9E5BxC8Eji12UjCE-KzZUGKqMRFB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jFSVZMejM4RZFWfpAzRLaZS-HKKV-KmWJRfvfurrfTGcznBijJpiWI52ao6XScujd-idr6ObYEmPwdrhGYofXCcK2skvjUgAaJz6nuJr48_hjEH7cfLxeH_7_6_xDuRaTMVyfTuVKhD084f6W9O8PF7dgpD2Lnfqa8Hw0t2rf4rZQCtYf5mHEbvUv70R9R9UuVefa0NvfNt5m3BEjv7xt9gB6J615rz81cluZlTsvtQEGvZroWEmx8vBzoONLgzRLVR02bh-18ArKmLznDA7oQnAeWz1GK5Bl6iUNZ7896D6uL4jd0Z-8QDBCBno2HvwEr6h9eGlPlMD-hr7w58ZXkbD9PUNjOa9hjHsQTqkYrKjZO1q1tZ2k5p3u2ruMCvA-jSywVbfdNkdhS2WlytBYiCwydMYGxQ4g-oKQisQQehcktTDA_Pd3TmPAS8NuQeFHzlKMBLaqE2-_B4W3u43C-5S9PFJVymYaZvQAwo0FL4v6i_fvas4Q273oDHd_9OWtnS04cRvAQacAZ7EkvxZ6Vl2-0nX8NkYrJi-oXJXaVXPxBZr7w_F4PBj5NZ-0W4ElCzuf6X0N3bHC0gXaPiHm6F_RWVj8AqUJowUF58rJQeC-FDkr51F_2Dp4XdbltcLHiIq9duwJ6fRusTmw0FkpUcKVUxZYp7BOKcIhbw4Lyn7n3H51Vo_OvbNyR1NvvFxM57PhcDoYLebLK-fgrCYzb7lcDvHfYDwdTcazpyvnoRIw9Aaz6XIwHkzH8-FospxOrhwcN-jHj-YvV9UfsK4cBFecOJjuTMLT342nIgg)

Let's dig into how all the above pieces fit together.

Expand Down Expand Up @@ -174,9 +169,10 @@ Fastly (cdn.changelog.com)
Cloudflare R2 (changelog.place)
````

The production instance of our application is running on Fly.io. All
https://changelog.com requests are served via Fastly. Each Fastly request gets
proxied to our application instance via the Fly.io Proxy.
The production instance of our application is running on Fly.io, as 2 instances
spread across 2 regions: IAD & EWR. All https://changelog.com requests are
served via Fastly. Each Fastly request gets proxied to our application instance
via the Fly.io Proxy.

```
Fastly (changelog.com)
Expand Down Expand Up @@ -281,7 +277,7 @@ you very much!
2. Copy the existing app instance config, e.g. `cp -r fly.io/changelog-{2023-12-17,2024-01-12}`
3. Run all following commands in the app directory, e.g. `cd fly.io/changelog-2024-01-12`
4. Update the app name in e.g. `fly.toml` to match the newly created app
5. From within the app directory, set a few secrets required by the app to work correctly while testing
5. Set the few secrets required by the app to work correctly before promoting to live

flyctl secrets set --stage \
OP_SERVICE_ACCOUNT_TOKEN="$(op read op://changelog/op/credential --account changelog.1password.com --cache)" \
Expand All @@ -292,6 +288,10 @@ you very much!

flyctl deploy --vm-size performance-4x --image <LATEST_IMAGE_SHA>

7. Ensure that the app is scaled across multiple regions & is resilient to a single region failure:

just prod-region-resilient


## How to branch the production db instance?

Expand Down
35 changes: 35 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ upgrade component:
build-runtime-image:
cd magefiles && go run main.go -w ../ image:runtime

# Run the CI part exactly as GitHub Actions runs it
[group('contributor')]
ci:
cd magefiles && go run main.go -w ../ ci

# Add Oban Pro hex repository
[group('team')]
add-oban-pro-hex-repo:
Expand Down Expand Up @@ -149,6 +154,7 @@ npm:
@which npm >/dev/null \
|| (echo "{{ _REDB }}{{ _WHITE }}NPM is not installed.{{ _RESET }} To fix this, run: {{ _GREENB }}just install{{ _RESET }}" && exit 127)

[private]
_NEON_DB_BRANCH := env_var("USER") + "-" + datetime("%Y-%m-%d")

# Create a new branch off the prod db
Expand Down Expand Up @@ -199,6 +205,7 @@ changelog_test: postgres-up (postgres-db "changelog_test")
test: changelog_test
mix test

[private]
_CHANGELOG_DEV_DB := env_var("CHANGELOG_DEV_DB")

[private]
Expand Down Expand Up @@ -236,6 +243,16 @@ contribute: install
just test
just dev

[private]
_APP_PROD_INSTANCE := env("APP_PROD_INSTANCE")

# Make production deployment resilient to a single region failure
[group('team')]
prod-region-resilient:
echo "💡 https://status.changelog.com/incident/513790"
cd fly.io/{{ _APP_PROD_INSTANCE }} \
&& flyctl scale count 2 --max-per-region 1 --region iad,ewr

[private]
actions-runner:
docker run --interactive --tty \
Expand Down Expand Up @@ -268,23 +285,41 @@ tag-kaizen version episode discussion commit:

# https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/

[private]
_BOLD := "$(tput bold)"
[private]
_RESET := "$(tput sgr0)"
[private]
_BLACK := "$(tput bold)$(tput setaf 0)"
[private]
_RED := "$(tput bold)$(tput setaf 1)"
[private]
_GREEN := "$(tput bold)$(tput setaf 2)"
[private]
_YELLOW := "$(tput bold)$(tput setaf 3)"
[private]
_BLUE := "$(tput bold)$(tput setaf 4)"
[private]
_MAGENTA := "$(tput bold)$(tput setaf 5)"
[private]
_CYAN := "$(tput bold)$(tput setaf 6)"
[private]
_WHITE := "$(tput bold)$(tput setaf 7)"
[private]
_BLACKB := "$(tput bold)$(tput setab 0)"
[private]
_REDB := "$(tput setab 1)$(tput setaf 0)"
[private]
_GREENB := "$(tput setab 2)$(tput setaf 0)"
[private]
_YELLOWB := "$(tput setab 3)$(tput setaf 0)"
[private]
_BLUEB := "$(tput setab 4)$(tput setaf 0)"
[private]
_MAGENTAB := "$(tput setab 5)$(tput setaf 0)"
[private]
_CYANB := "$(tput setab 6)$(tput setaf 0)"
[private]
_WHITEB := "$(tput setab 7)$(tput setaf 0)"

# just actions-runner
Expand Down
Loading