From c2184a5ecf936b85a57be9643ebfe5e6f7e15323 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 21 Jan 2025 15:36:44 -0600 Subject: [PATCH] Add Hatchbox Exports Env Vars With asdf as a Devops TIL --- README.md | 3 +- devops/hatchbox-exports-env-vars-with-asdf.md | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 devops/hatchbox-exports-env-vars-with-asdf.md diff --git a/README.md b/README.md index c8c0d02..05e346e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1569 TILs and counting..._ +_1570 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -200,6 +200,7 @@ See some of the other learning resources I work on: - [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md) - [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md) - [Determine The IP Address Of A Domain](devops/determine-the-ip-address-of-a-domain.md) +- [Hatchbox Exports Env Vars With asdf](devops/hatchbox-exports-env-vars-with-asdf.md) - [Path Of The Packets](devops/path-of-the-packets.md) - [Push Non-master Branch To Heroku](devops/push-non-master-branch-to-heroku.md) - [Reload The nginx Configuration](devops/reload-the-nginx-configuration.md) diff --git a/devops/hatchbox-exports-env-vars-with-asdf.md b/devops/hatchbox-exports-env-vars-with-asdf.md new file mode 100644 index 0000000..338cec4 --- /dev/null +++ b/devops/hatchbox-exports-env-vars-with-asdf.md @@ -0,0 +1,44 @@ +# Hatchbox Exports Env Vars With asdf + +When you add env vars through the [Hatchbox](https://hatchbox.io/) UI, they get +exported to the environment of the asdf-shimmed processes. This is handled by +the [`asdf-vars` plugin](https://github.com/excid3/asdf-vars). That plugin +looks for `.asdf-vars` in the current chain of directories. + +I can see there are many `.asdf-vars` files: + +```bash +$ find . -name ".asdf-vars" -type f +./.asdf-vars +./my-app/.asdf-vars +./my-app/releases/20250120195106/.asdf-vars +./my-app/releases/20250121041054/.asdf-vars +``` + +And it is the one in my app's directory that contains the env vars that I set +in the UI. + +```bash +$ cat my-app/.asdf-vars +BUNDLE_WITHOUT=development:test +DATABASE_URL=postgresql://user_123:123456789012345@10.0.1.1/my_app_db +PORT=9000 +RACK_ENV=production +RAILS_ENV=production +RAILS_LOG_TO_STDOUT=true +RAILS_MASTER_KEY=abc123 +SECRET_KEY_BASE=abc123efg456 +``` + +When I run a shimmed process like `ruby`, those env vars are loaded into the +process's environment. + +```bash +$ cd my-app/current +$ which ruby +/home/deploy/.asdf/shims/ruby +$ ruby -e "puts ENV['DATABASE_URL']" +postgresql://user_123:123456789012345@10.0.1.1/my_app_db +``` + +[source](https://www.visualmode.dev/hatchbox-manages-env-vars-with-asdf)