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

"Fix makefile env variables definition" #22246

Merged
merged 4 commits into from
May 16, 2024
Merged

"Fix makefile env variables definition" #22246

merged 4 commits into from
May 16, 2024

Conversation

KevinMind
Copy link
Contributor

@KevinMind KevinMind commented May 14, 2024

Fixes: mozilla/addons#14787

Description

The makefile env variables were not defined correctly, causing issues with the configuration of the containers. This pull request fixes the definition of the makefile env variables to ensure proper configuration.

Context

We have 4 possible values of critical environment variables.

  1. the default value define in the makefile
  2. the value specified in the .env file
  3. the value on the shell running the make command
  4. the argument passed to the make command.

Critical environment variables are exactly those which might produce different behavior if running a command via a make target, or directly.

E.g. we have variables defined in our compose files which should be define on the environment. If docker compose is run via make, values will be managed appropriately, but unless the value is in the .env or specified in the environment running docker compose directly will use a different or no value.

Testing

I've added a CI job to verify that the make create_env_file will produce expected results given all 8 possible combinations of the 4 possible sources

You can also manually test

  1. default value.

Remove .env file

run

make create_env_file

Expect all values to be the value defined in the default parameter via make file.

  1. ..env file

Modify one of the values in the produced in the .env and rerun the command.

Expect the value is persisted from the .env

  1. env on the shell

Keep the .env file, and set the value in the shell before running the command. Re-run and expect the env to take priority.

HOST_UID=env make create_env_file
  1. args on the command

Now adding to this, if you further specify an argument and expect it to take precedence over all values, regardless of if env/file/default are specified.

HOST_UID=env make create_env_file HOST_UID=arg

Expect value to be arg now.

The CI check runs through effectively this set of steps for every variable that is in this critical list.

@KevinMind KevinMind requested a review from eviljeff May 14, 2024 18:45
@KevinMind KevinMind force-pushed the fix-make-vars branch 2 times, most recently from 4559241 to 10a7605 Compare May 14, 2024 21:17
@KevinMind KevinMind marked this pull request as draft May 15, 2024 07:27
@KevinMind KevinMind force-pushed the fix-make-vars branch 2 times, most recently from e6c3479 to ef42735 Compare May 15, 2024 08:17
@KevinMind KevinMind requested a review from diox May 15, 2024 08:22

# Expect image tag is correct
echo $config | grep -q "image: mozilla/addons-server:${{ matrix.expected.version }}"
export SUPERUSER_EMAIL="email"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably reimplement this in python... wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth extracting somewhere (in Python or not) cause there is a lot going on and it's hard to read...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've extracted the exiisting bash test, and the new tests introduced here to a JS make.spec.js

The reason for JS is that the test MUST run on the host, it relies on docker commands and we don't (probably don't want to) install docker in our container. no need for the bloat.

Theoretically I could write it in python, but I felt it easier to run the js tests on the host.

@@ -597,6 +597,14 @@ jobs:
--ignore src/olympia/versions/ \
--ignore src/olympia/zadmin

make_tests:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should run as a separate test because it modifies the environment and .env files... it's theoretically possible to clean up that data after, but probably not worth the inherent risk.

@eviljeff eviljeff removed their request for review May 15, 2024 09:25
@KevinMind KevinMind marked this pull request as ready for review May 15, 2024 09:44
@KevinMind KevinMind force-pushed the fix-make-vars branch 2 times, most recently from cd678a2 to c125046 Compare May 16, 2024 07:33
@@ -1,4 +1,9 @@
x-env-mapping: &env
# https://docs.docker.com/compose/environment-variables/envvars-precedence/
env_file:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an important, but I think good change. This means if there is no .env file, docker compose will just fail. It would prevent someone from running anything via docker compose before running make create_env_file.

There is not really a scenario where you should run docker compose without it, it is critical for configuring the compose project.

happy to hear push back if you think this is too strong enforcement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boo, docker compose version in gha is not compatible with this syntax. Not sure it's worth the effort to upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM. By default env_files are required. so we get the same behavior.

@KevinMind KevinMind marked this pull request as draft May 16, 2024 08:58
@KevinMind KevinMind force-pushed the fix-make-vars branch 4 times, most recently from 78b2169 to 69ad228 Compare May 16, 2024 10:57
@KevinMind KevinMind marked this pull request as ready for review May 16, 2024 10:59
@KevinMind KevinMind merged commit c4f4ba6 into master May 16, 2024
14 checks passed
@KevinMind KevinMind deleted the fix-make-vars branch May 16, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants