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

Add named volume for mounting host files via OLYMPIA_MOUNT #22929

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

KevinMind
Copy link
Contributor

@KevinMind KevinMind commented Dec 9, 2024

Rleates to: mozilla/addons#15066

Description

  • adds OLYMPIA_MOUNT/OLYMPIA_UID setting to inform if host files are mounted
  • merge docker-compose.ci.yml as we now control host mounting via the argument above
  • add test checking host file presence in the container

Context

Follow up to #22912

By introducing a specific argument for the desired mounting strategy we can unify our docker compose files and have a simpler flow for mounting files correctly.

We must use bind mounts when mounting files from the host, named volumes (even with a host mounted device) do not send appropriate inotify events in a timely manner. This sucks and should be fixed in docker but for now it seems safer to use bind mounts

We map arguments OLYMPIA_* to HOST_* in the .env file. This is because the setup.py script does not always accept the user input and we don't want to let an internal command (like docker compose <whatever>) to rely on a potentially invalid value lingering on the environment but instead only read the explicitly set values in the .env. By using different names in that transaction we can guarantee this.

It is possible that we should raise errors in setup.py when invalid values are passed for OLYMPIA_MOUNT but this patch introduces enough changes and we can see if this is an issue and raise it then.

Testing

Prod Mode

To verify expected mount behavior, run each:

make up DOCKER_TARGET=production OLYMPIA_MOUNT=<production|development>
  • expect the .env to have a value HOST_MOUNT equal to the specified value

  • expect the web/worker containers to have an environment variable set to the specified value

  • expect settings.OLYMPIA_MOUNT to equal the specified value

  • If developmemnt is provided

    • Expect the .env to have a value HOST_MOUNT_SOURCE equal to "./"
    • expect docker compose to use a bind mount for the /data/olympia volume
  • if production is provided

    • Expect the .env to have a value HOST_MOUNT_SOURCE equal to "data_olympia_"
    • expect docker compose to use a named volume data_olympia that is not mounted on the host. (changing files on the host should not impact files in the container, no uwsgi reload)

To test this, attach a shell in the containers and inspect the files. Additionally, you can run the check command to verify expectations.

Additionally, verify that volumes are correctly mounted to nginx

  • /data/olympia -> the same files in web/worker
  • /data/olympia/storage -> files in the shared storage bind mount
  • /data/olympia/site-static -> files in the web container

And to worker

  • /data/olympia -> the same files in web/worker
  • /data/olympia/storage -> files in the shared storage bind mount

Important

Worker gets shared storage but not static files. these should be accessed via URL in the worker container if at all

Dev Mode

When running the project in dev mode (DOCKER_TARGET=dev) then the OLYMPIA_MOUNT will always be set to dev, even if specified otherwise.

make up DOCKER_TARGET=production OLYMPIA_MOUNT=<production|development>
  • Run the assertions in Prod mode, but always assuming that OLYMPIA_MOUNT is "development" regardless of docker target

Checklist

  • Add #ISSUENUM at the top of your PR to an existing open issue in the mozilla/addons repository.
  • Successfully verified the change locally.
  • The change is covered by automated tests, or otherwise indicated why doing so is unnecessary/impossible.
  • Add before and after screenshots (Only for changes that impact the UI).
  • Add or update relevant docs reflecting the changes made.

@KevinMind KevinMind force-pushed the addons-15066-mount branch 4 times, most recently from a442f56 to 0371ce4 Compare December 9, 2024 21:41
@KevinMind KevinMind changed the base branch from master to addons-15066-tests December 9, 2024 22:27
@KevinMind KevinMind force-pushed the addons-15066-mount branch 4 times, most recently from 28af358 to 19484d4 Compare December 10, 2024 13:50
@KevinMind KevinMind requested review from a team and diox and removed request for a team December 10, 2024 14:25
Base automatically changed from addons-15066-tests to master December 10, 2024 20:53
@KevinMind KevinMind changed the title Addons-15066-mount Add named volume for mounting host files via OLYMPIA_MOUNT Dec 10, 2024
@diox
Copy link
Member

diox commented Dec 16, 2024

Could you resolve the few conflicts in that PR ?

@KevinMind KevinMind force-pushed the addons-15066-mount branch 5 times, most recently from b30eeed to 1e42984 Compare December 17, 2024 10:29
@KevinMind
Copy link
Contributor Author

KevinMind commented Dec 17, 2024

@diox this is now done, and:

Could you resolve the few conflicts in that PR ?

Turns out this PR was too primitive to land after some of the other PRs landed. The goal was to strip as much out as possible to make it smaller. That doesn't work anymore so I added as little back until it is now working.

  • merged the CI compose file
  • use mapping of OLYMPIA_MOUNT to make the container behave correctly.

Edit: eating my words. we need proper validation on the setup script values.

@KevinMind KevinMind force-pushed the addons-15066-mount branch 4 times, most recently from 047cec0 to 8490d9f Compare December 17, 2024 11:11
@KevinMind KevinMind marked this pull request as draft December 17, 2024 15:22
@KevinMind KevinMind force-pushed the addons-15066-mount branch 9 times, most recently from dd214d3 to 1ab4848 Compare December 18, 2024 08:16
@KevinMind KevinMind requested review from eviljeff and removed request for diox December 18, 2024 08:17
@KevinMind KevinMind marked this pull request as ready for review December 18, 2024 08:17
Copy link
Member

@eviljeff eviljeff left a comment

Choose a reason for hiding this comment

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

🤔

src/olympia/amo/monitors.py Outdated Show resolved Hide resolved
# production: (data_olympia):/data/olympia/storage
# development: (./):/data/olympia/storage
x-olympia-mount: &olympia-mount
${HOST_MOUNT_SOURCE:?}:/data/olympia
Copy link
Member

Choose a reason for hiding this comment

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

should we have a default for HOST_MOUNT_SOURCE here, like the development value. (I guess something like ${HOST_MOUNT_SOURCE:?-./ but I'm not super familiar with the docker-compose syntax).

(same for the next usage of HOST_MOUNT_SOURCE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should not. This syntax :? is actually requiring this value to be set. This value must be defined and a valid value and there are no circumstances where it should be undefined.

docker/nginx/addons.conf Outdated Show resolved Hide resolved
@KevinMind KevinMind requested a review from eviljeff December 18, 2024 14:40
@KevinMind KevinMind force-pushed the addons-15066-mount branch 5 times, most recently from 75eab84 to b1080ba Compare December 18, 2024 16:32
- Removed the deprecated docker-compose.ci.yml file, consolidating configurations into docker-compose.yml.
- Updated environment variable mappings to use OLYMPIA_UID and OLYMPIA_MOUNT for improved clarity and consistency.
- Enhanced entrypoint script to adjust user IDs based on the new environment variables.
- Modified setup.py to determine the appropriate olympia mount based on the target environment.
- Updated GitHub Actions workflows to reflect changes in environment variable usage and remove references to the old compose file.
@KevinMind KevinMind merged commit c06f6b1 into master Dec 18, 2024
36 checks passed
@KevinMind KevinMind deleted the addons-15066-mount branch December 18, 2024 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants