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 a Docker compose file #215

Merged
merged 11 commits into from
May 28, 2024
Merged

Add a Docker compose file #215

merged 11 commits into from
May 28, 2024

Conversation

jackleland
Copy link
Contributor

Adds a docker compose file which can be used for easily getting up and running with a local dev environment, addressing #121 (partially) and #194. Moves database migration to the entrypoint script so that a working database is not required at build-time.

Also adds material-pulling into the Dockerfile with controllable behaviour via the MATERIAL_METHOD build-arg, either:

  • "copy" in a local folder, specified by MATERIAL_DIR
  • "pull" the repo described in a local config yaml file, specified by YAML_TEMPLATE
    The pull option is the default, and uses the recently added python script functionality.

Note that the local .material is mounted in at run time, but doesn't seem to get updated with the cron job.

Works as-is but could probably be improved in a few ways:

  1. An additional Dockerfile/option to use yarn dev to cut down on build iteration time (maybe dev-dynamic-compose.yml)
  2. Split the material pulling stuff into a separate image
  3. Get the mounted material directory to be refreshed from by the cronjob
  4. Use the test material repo set up for make a test material repo #189
  5. Implement a production version with NGINX and qdrant

Adds a docker compose file which can be used for easily getting up and
running with a dev environment. Adds material pulling into the
Dockerfile with controllable behaviour via the MATERIAL_METHOD build-arg,
either 'copy' in a local folder or pull the repo described in a local
config yaml file. Also moves database migration to the entrypoint script
so that a working database is not required at build-time.
@mjaquiery
Copy link
Collaborator

@jackleland the multiple different client containers is a really smart and inventive solution. Nice one.

@jackleland
Copy link
Contributor Author

@alasdairwilson I can add a bash script in addition to these changes if you'd prefer people had the option?

@jackleland
Copy link
Contributor Author

It looks like changing files in the .material directory forces the build to not use the cache, so no need for --no-cache. Also the image looks to be about 2.5GB (when pulling as opposed to copying) compared to 2.3 previously.

@alasdairwilson
Copy link
Collaborator

It looks like changing files in the .material directory forces the build to not use the cache, so no need for --no-cache. Also the image looks to be about 2.5GB (when pulling as opposed to copying) compared to 2.3 previously.

Size difference is minimal then, though yeuch at the size of the container in the first place.

The bigger worry for the --no-cache was that if you update the material repo (the github) then it wont run the pull step so the .material folder will be unchanged (and it will cache right past it).

@alasdairwilson
Copy link
Collaborator

Although having said that...perhaps it is fine that you only initially deploy with this and that if we have the cronjob + add the nextjs timeout then your material will update at midnight anyway (could make this more frequent)

@jackleland
Copy link
Contributor Author

Ahh I see your point, there are definitely ways around this via cache busting though. I'll work up an example in a sec

Adds support for cache-busting the git-pull of the material repo,
meaning that the pull section of the dockerfile will not be run
from the cached layer if the CACHE_BUST environment variable is
changed between calls to `docker build` or `docker-compose build`.

So far there seems no way to dynamically set the environment
variable from within the compose file, so a script is included to
do this manually via export, equally a prepended env variable could
be used when calling `docker-compose build` or `... up --build`.
@jackleland
Copy link
Contributor Author

So I've added a cache-bust but there doesn't seem to be a way to set an environment variable dynamically with docker-compose (that I've found anyhow), so I included a bash script to do it automatically i.e. there's still a single command to get from a fresh clone to a running gutenberg.

Also added a 'production' compose file with nginx and qdrant included, but I haven't tested this very thoroughly - at this point it's more a starting point than an actual deployment option.

Let me know thoughts

Copy link
Collaborator

@alasdairwilson alasdairwilson left a comment

Choose a reason for hiding this comment

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

So apologies for hijacking this but I wanted to test it and ended up in a rabbit hole that ended in fixing a few critical issues: the main one being the mount of the external .material meant that it would never actually use any of the pulled material in the container and that the prisma commands were incorrect and the cache busting didn't work quite right.

I think the solution with the 3 material sources in the dockerfile is really clever, I think in retrospect the iffyness of the cachebusting meant we probably should have just gone with a simpler dockerfile and a python requirement on the build stage but I don't think it is enough better to be worth replacing it so I am happy as it is.

Thanks for the contribution 👍

@alasdairwilson alasdairwilson merged commit 32fc834 into main May 28, 2024
4 checks passed
@alasdairwilson alasdairwilson deleted the docker-compose branch May 28, 2024 12:05
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