Skip to content

Commit 4a897ce

Browse files
allow setting configuration using env variables (#600)
## Overview Previously configuration options must be set in the local environment file (`birdhouse/env.local` by default). This change allows configuration options to be set as environment variables which would take precedence over those set in the local environment file. For example, you can now set the `BIRDHOUSE_FQDN` variable when starting the stack like so: ```sh BIRDHOUSE_FQDN=myhost.example.com bin/birdhouse compose up -d # OR export BIRDHOUSE_FQDN=myhost.example.com bin/birdhouse compose up -d ``` This change has the following advantages: - flexibility: the user has more options for how they can customize their deployment - good dev-ops: this change further aligns birdhouse with the [12 factor app principles](https://12factor.net/), specifically the [Config](https://12factor.net/config) principle which recommends that configuration options be settable as environment variables. - security: sensitive settings (credentials, secrets) can be set as environment variables, ensuring that they are not easily visible in the plain text local environment file. - consistency: users can store non-sensitive settings in the local environment file and share that file freely without worrying that sensitive setting will be leaked. Note that this includes some necessary changes to the tests that are unrelated to this change directly. The tests explicitly set `BIRDHOUSE_BACKWARD_COMPATIBLE_ALLOWED=False` as an environment variable in order to get around the fact that it is set to True by default when running scripts not through a supported interface. For tests that want to explicitly set `BIRDHOUSE_BACKWARD_COMPATIBLE_ALLOWED=True` we now have to set that as an environment variable (not in env.local) since environment variables now take precedence over settings in env.local. ## Changes **Non-breaking changes** - Adds new configuration strategy - test refactoring **Breaking changes** - None ## Related Issue / Discussion ## Additional Information ## CI Operations <!-- The test suite can be run using a different DACCS config with ``birdhouse_daccs_configs_branch: branch_name`` in the PR description. To globally skip the test suite regardless of the commit message use ``birdhouse_skip_ci`` set to ``true`` in the PR description. Using ``[<cmd>]`` (with the brackets) where ``<cmd> = skip ci`` in the commit message will override ``birdhouse_skip_ci`` from the PR description. Such commit command can be used to override the PR description behavior for a specific commit update. However, a commit message cannot 'force run' a PR which the description turns off the CI. To run the CI, the PR should instead be updated with a ``true`` value, and a running message can be posted in following PR comments to trigger tests once again. --> birdhouse_daccs_configs_branch: master birdhouse_skip_ci: false
2 parents 3e00782 + 820739b commit 4a897ce

File tree

10 files changed

+176
-85
lines changed

10 files changed

+176
-85
lines changed

.bumpversion.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.bumpversion]
2-
current_version = "2.18.7"
2+
current_version = "2.18.8"
33
commit = true
44
tag = false
55
tag_name = "{new_version}"

CHANGES.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,40 @@
1717

1818
[//]: # (list changes here, using '-' for each new entry, remove this when items are added)
1919

20+
[2.18.8](https://github.com/bird-house/birdhouse-deploy/tree/2.18.8) (2025-10-30)
21+
------------------------------------------------------------------------------------------------------------------
22+
23+
## Changes
24+
25+
- Allow configuration options to be set as environment variables
26+
27+
Previously configuration options must be set in the local environment file (`birdhouse/env.local` by default).
28+
This change allows configuration options to be set as environment variables which would take precedence over those
29+
set in the local environment file.
30+
31+
For example, you can now set the `BIRDHOUSE_FQDN` variable when starting the stack like so:
32+
33+
```sh
34+
BIRDHOUSE_FQDN=myhost.example.com bin/birdhouse compose up -d
35+
36+
# OR
37+
38+
export BIRDHOUSE_FQDN=myhost.example.com
39+
bin/birdhouse compose up -d
40+
```
41+
42+
This change has the following advantages:
43+
44+
- flexibility: the user has more options for how they can customize their deployment
45+
- good dev-ops: this change further aligns birdhouse with the [12 factor app principles](https://12factor.net/),
46+
specifically the [Config](https://12factor.net/config) principle which recommends that configuration
47+
options be settable as environment variables.
48+
- security: sensitive settings (credentials, secrets) can be set as environment variables, ensuring that they are
49+
not easily visible in the plain text local environment file.
50+
- consistency: users can store non-sensitive settings in the local environment file and share that file freely without
51+
worrying that sensitive setting will be leaked.
52+
53+
2054
[2.18.7](https://github.com/bird-house/birdhouse-deploy/tree/2.18.7) (2025-10-17)
2155
------------------------------------------------------------------------------------------------------------------
2256

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ override BIRDHOUSE_MAKE_DIR := $(shell realpath -P $$(dirname $(BIRDHOUSE_MAKE_C
88
# Generic variables
99
override SHELL := bash
1010
override APP_NAME := birdhouse-deploy
11-
override APP_VERSION := 2.18.7
11+
override APP_VERSION := 2.18.8
1212

1313
# utility to remove comments after value of an option variable
1414
override clean_opt = $(shell echo "$(1)" | $(_SED) -r -e "s/[ '$'\t'']+$$//g")

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ for a full-fledged production platform.
1818
* - citation
1919
- | |citation|
2020

21-
.. |commits-since| image:: https://img.shields.io/github/commits-since/bird-house/birdhouse-deploy/2.18.7.svg
21+
.. |commits-since| image:: https://img.shields.io/github/commits-since/bird-house/birdhouse-deploy/2.18.8.svg
2222
:alt: Commits since latest release
23-
:target: https://github.com/bird-house/birdhouse-deploy/compare/2.18.7...master
23+
:target: https://github.com/bird-house/birdhouse-deploy/compare/2.18.8...master
2424

25-
.. |latest-version| image:: https://img.shields.io/badge/tag-2.18.7-blue.svg?style=flat
25+
.. |latest-version| image:: https://img.shields.io/badge/tag-2.18.8-blue.svg?style=flat
2626
:alt: Latest Tag
27-
:target: https://github.com/bird-house/birdhouse-deploy/tree/2.18.7
27+
:target: https://github.com/bird-house/birdhouse-deploy/tree/2.18.8
2828

2929
.. |readthedocs| image:: https://readthedocs.org/projects/birdhouse-deploy/badge/?version=latest
3030
:alt: ReadTheDocs Build Status (latest version)

RELEASE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.18.7 2025-10-17T16:11:17Z
1+
2.18.8 2025-10-30T19:03:01Z

birdhouse/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ This will source the ``env.local`` file, apply the appropriate variable substitu
106106
".template", and run ``docker-compose`` with all the command line arguments after the ``compose`` argument.
107107
See `env.local.example <env.local.example>`_ (:download:`download </birdhouse/env.local.example>`) for more details on what can go into the ``env.local`` file.
108108

109+
Most variables that can be set in the local environment file (``env.local`` by default) can also be specified as environment variables when running ``bin/birdhouse``
110+
commands. Environment variables will take precedence over those specified in the ``env.local`` file.
111+
109112
If the file `env.local` is somewhere else, symlink it here, next to `docker-compose.yml <docker-compose.yml>`_ (:download:`download </birdhouse/docker-compose.yml>`) because many scripts assume this location.
110113
If autodeploy scheduler job is enabled, the folder containing the `env.local` file needs to be added to `BIRDHOUSE_AUTODEPLOY_EXTRA_REPOS`.
111114

birdhouse/components/canarie-api/docker_configuration.py.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ SERVICES = {
108108
# NOTE:
109109
# Below version and release time auto-managed by 'make VERSION=x.y.z bump'.
110110
# Do NOT modify it manually. See 'Tagging policy' in 'birdhouse/README.rst'.
111-
'version': '2.18.7',
112-
'releaseTime': '2025-10-17T16:11:17Z',
111+
'version': '2.18.8',
112+
'releaseTime': '2025-10-30T19:03:01Z',
113113
'institution': '${BIRDHOUSE_INSTITUTION}',
114114
'researchSubject': '${BIRDHOUSE_SUBJECT}',
115115
'supportEmail': '${BIRDHOUSE_SUPPORT_EMAIL}',
@@ -141,8 +141,8 @@ PLATFORMS = {
141141
# NOTE:
142142
# Below version and release time auto-managed by 'make VERSION=x.y.z bump'.
143143
# Do NOT modify it manually. See 'Tagging policy' in 'birdhouse/README.rst'.
144-
'version': '2.18.7',
145-
'releaseTime': '2025-10-17T16:11:17Z',
144+
'version': '2.18.8',
145+
'releaseTime': '2025-10-30T19:03:01Z',
146146
'institution': '${BIRDHOUSE_INSTITUTION}',
147147
'researchSubject': '${BIRDHOUSE_SUBJECT}',
148148
'supportEmail': '${BIRDHOUSE_SUPPORT_EMAIL}',

birdhouse/read-configs.include.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,36 @@ set_backwards_compatible_as_default() {
459459
fi
460460
}
461461

462+
# Record all currently exported environment variables and store them in the __BIRDHOUSE_PROCESS_ENV
463+
# variable. Calling reset_process_env later will re-export all these variables, setting them back to their
464+
# original value. See reset_process_env for an example.
465+
stage_process_env() {
466+
__BIRDHOUSE_PROCESS_ENV="$(export -p)"
467+
}
468+
469+
# Re-export and set all environment variables that were exported when stage_process_env was last called. This
470+
# effectively resets these variables to the values that they had when stage_process_env was last called.
471+
#
472+
# Note that this will not unset variables that were not exported when stage_process_env was last called.
473+
#
474+
# For example:
475+
#
476+
# export X=10
477+
# stage_process_env
478+
# echo $X # prints 10
479+
# X=11
480+
# export Y=12
481+
# echo $X # prints 11
482+
# reset_process_env
483+
# echo $X # prints 10
484+
# echo $Y # prints 12
485+
reset_process_env() {
486+
eval "${__BIRDHOUSE_PROCESS_ENV}"
487+
}
462488

463489
### Similar code between read_configs() and read_basic_configs_only().
464490
_read_basic_configs_pre() {
491+
stage_process_env
465492
set_backwards_compatible_as_default
466493
discover_compose_dir
467494
discover_env_local
@@ -470,8 +497,9 @@ _read_basic_configs_pre() {
470497

471498

472499
_read_basic_configs_post() {
473-
read_env_local # again to override components default.env, need discover_env_local
474-
set_old_backwards_compatible_variables # after read_env_local to use updated value and not default value
500+
read_env_local # override default env (for a second time if called from read_configs), needs discover_env_local to run first
501+
reset_process_env # override local env and default env with variables declared in the calling process' environment, needs stage_process_env to run first
502+
set_old_backwards_compatible_variables # after read_env_local to use updated value and not default value for backwards compatible variables
475503
process_backwards_compatible_variables
476504
check_default_vars
477505
process_delayed_eval
@@ -485,7 +513,8 @@ read_configs() {
485513
_read_basic_configs_pre
486514

487515
### This section is different than read_basic_configs_only() below, the rest should be IDENTICAL.
488-
read_env_local # for BIRDHOUSE_EXTRA_CONF_DIRS and BIRDHOUSE_DEFAULT_CONF_DIRS, need discover_env_local
516+
read_env_local # for BIRDHOUSE_EXTRA_CONF_DIRS and BIRDHOUSE_DEFAULT_CONF_DIRS, needs discover_env_local to run first
517+
reset_process_env # use BIRDHOUSE_EXTRA_CONF_DIRS and BIRDHOUSE_DEFAULT_CONF_DIRS if they're declared in the calling process' environment, needs stage_process_env to run first
489518
process_backwards_compatible_variables pre-components
490519
read_components_default_env # uses BIRDHOUSE_EXTRA_CONF_DIRS and BIRDHOUSE_DEFAULT_CONF_DIRS, sets ALL_CONF_DIRS
491520
### END This section is different than read_basic_configs_only() below, the rest should be IDENTICAL.

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
# built documents.
7070
#
7171
# The short X.Y version.
72-
version = '2.18.7'
72+
version = '2.18.8'
7373
# The full version, including alpha/beta/rc tags.
74-
release = '2.18.7'
74+
release = '2.18.8'
7575

7676
# The language for content autogenerated by Sphinx. Refer to documentation
7777
# for a list of supported languages.

0 commit comments

Comments
 (0)