Skip to content

Commit

Permalink
feat(envrc): Loading and timing (#16458)
Browse files Browse the repository at this point in the history
* feat(scripts): Auto-set cluster from aws login information

* Add .envrc.kube for auto-cluster selection

* Rename .envrc.podman

* Add timing function

* Better timekeeping

* Cleanup

* Clearer intent, less piping

* Corrected timekeeping

* Revert .env* to main

* Rename .envrc.podman

* Ignore all .env.*

* Source-if-exist kube and podman

* No-oneliner

* Refactor to only use required tools (kubectl)

* Only return in podman

* Use sed instead of grep -P

* No -P

* Timed .envrc

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
AndesKrrrrrrrrrrr and kodiakhq[bot] authored Oct 22, 2024
1 parent 9c1d3f1 commit 11b480a
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#!/bin/bash

source_env .env.secret
declare -A TIME_KEEP
# t <target> - get elapsed time in milliseconds since first invocation (with nanosecond precision)
t() {
if [[ -v TIME_KEEP[$1] ]]; then
D="$(date +%N)"
echo "$(((${D##0} - ${TIME_KEEP[$1]##0}) / 1000000))"
else
TIME_KEEP[$1]=$(date +%N)
fi
}
set -euo pipefail
t root

# global

export NODE_OPTIONS="--max-old-space-size=8192"

# MacOS specific

export REDIS_CLUSTER_IP=0.0.0.0

# developer custom direnv config

source_env_if_exists .envrc.private
if [[ "${IS_DEVCONTAINER:-}" == true ]]; then
source_env_if_exists .devcontainer/.envrc.private
fi

# Podman compatibility
# NOTE: Exits direnv if user is using docker.
source_env_if_exists .envrc.podman

source_env_if_exists .envrc.kube
# Developer custom direnv config
for envrc in .envrc.* $(if [[ "${IS_DEVCONTAINER:-}" == true ]]; then echo .devcontainer/.envrc.private; fi); do
t "${envrc}"
source_env_if_exists "$envrc"
T_TOTAL=$(t "${envrc}")
if ((T_TOTAL > 100)); then
echo -e "\033[93mSetting '$envrc' took ${T_TOTAL}ms\033[0m"
fi
done

echo "Loading .envrc took $(t root)ms"

0 comments on commit 11b480a

Please sign in to comment.