-
Notifications
You must be signed in to change notification settings - Fork 231
feat(dev): speed up and add a live dashboard to local stack startup #20688
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
Open
vbudhram
wants to merge
1
commit into
main
Choose a base branch
from
faster-stack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,52 @@ | |
| DIR=$(dirname "$0") | ||
| cd "$DIR/../.." | ||
|
|
||
| # Make sure there is a common docker network fxa, so containers can | ||
| # communicate with one another if needed | ||
| _dev/pm2/create-docker-net.sh fxa | ||
| pm2 start _dev/pm2/infrastructure.config.js | ||
| # Fail fast with an actionable message if Docker isn't running. Without this a | ||
| # down daemon surfaces as a cryptic 'docker network' error here, or worse, as a | ||
| # 240s readiness timeout further downstream. | ||
| if ! docker info >/dev/null 2>&1; then | ||
| echo "❌ Docker is not running. Start Docker Desktop (or your Docker daemon) and retry." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # On an interactive TTY (the same gate the start dashboard uses), replace pm2's | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't have to add this, but watching all the pm2 and nx builds go by just seemed excessive. Now there is a simple live dashboard as the services come up. You can still see logs with |
||
| # verbose daemon/launch output and status table with a compact summary. CI, | ||
| # piped runs, and FXA_START_PLAIN=1 keep the full output, byte-identical. | ||
| QUIET=false | ||
| if [ -t 1 ] && [ -z "${FXA_START_PLAIN:-}" ]; then | ||
| QUIET=true | ||
| fi | ||
|
|
||
| mkdir -p artifacts | ||
|
|
||
| if [ "$QUIET" = true ]; then | ||
| echo "Starting infrastructure…" | ||
| if _dev/pm2/create-docker-net.sh fxa >/dev/null 2>&1; then | ||
| echo " ✅ docker network fxa" | ||
| else | ||
| echo " ❌ docker network setup failed (re-run with FXA_START_PLAIN=1 to see why)." >&2 | ||
| exit 1 | ||
| fi | ||
| if ! pm2 start _dev/pm2/infrastructure.config.js >artifacts/pm2-infra.log 2>&1; then | ||
| echo " ❌ infrastructure failed to start. Last lines of artifacts/pm2-infra.log:" >&2 | ||
| tail -40 artifacts/pm2-infra.log >&2 | ||
| exit 1 | ||
| fi | ||
| infra_names=$(grep -oE "name: '[^']+'" _dev/pm2/infrastructure.config.js | cut -d"'" -f2 | tr '\n' ' ') | ||
| echo " ✅ infrastructure started: ${infra_names}" | ||
| else | ||
| # Make sure there is a common docker network fxa, so containers can | ||
| # communicate with one another if needed | ||
| _dev/pm2/create-docker-net.sh fxa | ||
| pm2 start _dev/pm2/infrastructure.config.js | ||
| fi | ||
|
|
||
| echo "waiting for containers to start" | ||
|
|
||
| _scripts/check-url.sh localhost:4100/health | ||
| _scripts/check-url.sh localhost:9299/api/config | ||
| _scripts/check-url.sh localhost:4100/health 200 "goaws (SNS)" | ||
| _scripts/check-url.sh localhost:9299/api/config 200 "firebase emulator" | ||
| _scripts/check-mysql.sh | ||
| _scripts/check-redis.sh | ||
|
|
||
| echo "waiting for DB patches" | ||
| _scripts/check-db-patcher.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Wait for the redis container to accept connections before app services boot, | ||
| # so a cold start doesn't produce a burst of ioredis connection errors. | ||
| # Non-fatal: ioredis reconnects on its own, so a slow redis only delays steady | ||
| # state rather than failing the stack. | ||
|
|
||
| # Authenticate when REDIS_PASSWORD is set (redis.sh starts redis with | ||
| # --requirepass); otherwise an authed redis replies NOAUTH and we'd wait the | ||
| # full timeout and warn falsely. | ||
| AUTH_ARGS=() | ||
| if [ -n "${REDIS_PASSWORD:-}" ]; then | ||
| AUTH_ARGS=(--no-auth-warning -a "$REDIS_PASSWORD") | ||
| fi | ||
|
|
||
| RETRY=30 | ||
| echo -e "\nChecking for redis..." | ||
| for i in $(seq 1 "$RETRY"); do | ||
| REPLY=$(docker exec redis-server redis-cli "${AUTH_ARGS[@]}" ping 2>/dev/null) | ||
| if echo "$REPLY" | grep -q PONG; then | ||
| echo "✅ redis responded in ${i}s" | ||
| exit 0 | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| echo "⚠️ redis did not respond after ${RETRY}s; continuing (services will retry)." | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,31 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| echo "Checking for response from: $1" | ||
| # Poll an HTTP endpoint until it responds, used to gate startup on service | ||
| # readiness. Args: $1=host/path (no scheme), $2=expected status (default 200), | ||
| # $3=human label (default $1). Emits a periodic heartbeat so a slow service is | ||
| # never mistaken for a hung one, and prints an actionable hint on timeout. | ||
|
|
||
| TARGET="$1" | ||
| EXPECTED="${2:-200}" | ||
| LABEL="${3:-$1}" | ||
|
|
||
| RETRY=240 | ||
| for i in $(eval echo "{1..$RETRY}"); do | ||
| if [ "$(curl -s -o /dev/null --silent -w "%{http_code}" http://$1)" == "${2:-200}" ]; then | ||
| echo "$1 responded in $SECONDS seconds" | ||
| echo "⏳ Waiting for ${LABEL} (http://${TARGET}, expect HTTP ${EXPECTED})..." | ||
|
|
||
| for i in $(seq 1 "$RETRY"); do | ||
| if [ "$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 "http://$TARGET")" == "$EXPECTED" ]; then | ||
| echo "✅ ${LABEL} responded in ${SECONDS}s" | ||
| exit 0 | ||
| else | ||
| if [ "$i" -lt $RETRY ]; then | ||
| sleep 1 | ||
| fi | ||
| fi | ||
| # Heartbeat every 15s so the developer sees progress during long boots. | ||
| if [ $((i % 15)) -eq 0 ]; then | ||
| echo " …still waiting on ${LABEL} (${SECONDS}s, attempt ${i}/${RETRY})" | ||
| fi | ||
| if [ "$i" -lt "$RETRY" ]; then | ||
| sleep 1 | ||
| fi | ||
| done | ||
| echo "Giving up after $SECONDS seconds. Failed to get response from: $1" | ||
|
|
||
| echo "❌ Gave up on ${LABEL} after ${SECONDS}s (http://${TARGET})." | ||
| echo " Hint: inspect 'pm2 status' and 'pm2 logs' for the service on this port." | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| # `yarn start mza`: pre-launch checks, infrastructure, the fast-build services | ||
| # (build-fast skips tsc), then a sync restart, and finally the total stack | ||
| # startup time. Kept as a script (rather than an inline nps chain) so the timing | ||
| # is readable. set -e stops before the "ready" line if any step fails, so the | ||
| # time is only reported on a clean startup. | ||
|
|
||
| start=$(date +%s) | ||
| DIR=$(dirname "$0") | ||
| cd "$DIR/.." | ||
|
|
||
| PROJECTS="$1" | ||
|
|
||
| _scripts/check-pre-launch.sh | ||
| _dev/pm2/start.sh | ||
| FXA_BUILD_TARGET=build-fast _scripts/pm2-all.sh start "$PROJECTS" | ||
|
|
||
| # sync depends on the services; restart it now that they are up. | ||
| pm2 restart sync | ||
|
|
||
| total=$(($(date +%s) - start)) | ||
| echo "" | ||
| echo "✅ Stack ready in ${total}s. Run 'yarn stop' to stop all the servers." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was failing for me in CI and reordering fixed it. Seems like we should use the nvmrc in FxA reitehr way.