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 dev docker-compose file to manage supporting services #525

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

sadiqkhoja
Copy link
Contributor

@sadiqkhoja sadiqkhoja commented Oct 20, 2023

Changes

  • Added a new docker-compose file for development. It is supposed to be executed in conjunction with the main docker-compose.yml. This new file adds profiles attribute to control which services are needed for the development workflow. Additionally, network_mode is set to host driver so that bidirectional communication is possible. Bottleneck for bridge mode is Enketo which for some reason does not honor /etc/hosts for localhost, I was able to make it work with code modification on the fly, which looked dirty to me. One caveat for host mode: this is not available for "Docker Desktop for Mac", works great with OrbStack
  • Added dev config templates for nginx, enketo and service(central) services. These dev templates have hardcoded localhost endpoints

Two objectives I've kept in my mind to achieve this 1) Not to touch main docker-compose.yml that might cause unintended consequences 2) Not to modify application source code

What has been done to verify that this works as intended?

Verified locally. It would be great if all can try this and see if this is helpful.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Although I have modified enketo startup scripts, changes are contained in dev specific conditional block

Does this change require updates to documentation? If so, please file an issue here and include the link below.

None

Before submitting this PR, please make sure you have:

  • verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

@sadiqkhoja sadiqkhoja marked this pull request as draft October 20, 2023 19:55
@sadiqkhoja sadiqkhoja marked this pull request as ready for review October 20, 2023 20:05
@matthew-white matthew-white changed the base branch from master to next October 24, 2023 19:33
@spwoodcock
Copy link
Member

Is work still ongoing on this PR?

I have just set up my own dev environment to work on central-backend and central-frontend & documented the process.
As a result, I have a slightly modified dev setup, also with a docker-compose.dev.yml.

I plan to submit my documentation for review, but should I also commit the dev setup changes?

@sadiqkhoja
Copy link
Contributor Author

Hi @spwoodcock, I will be working again on this PR next week, particularly removing duplicate *.json.dev.template from the individual services.

Can you please share your setup, is it a different approach? Maybe we can combine both.

@spwoodcock
Copy link
Member

Certainly!

I made a PR in our repo to more easily show the changes: https://github.com/hotosm/odkcentral/pull/1/files

My main goal was to make setting up a dev environment as easy as possible, with files mounted in the container for hot reload (on the backend). I planned to do the same for the frontend, running the dev server with hot reloading, but we may need to update vue-cli-service and node forman to vite.

I extended from the existing docker-compose.yml, so had to make a mock enketo service so nginx would start up correctly (as I only wanted to develop for central-backend and central-frontend).

Hope this helps - I'm more than happy to contribute to this PR if needed.

@sadiqkhoja sadiqkhoja force-pushed the docker-for-local-dev branch 4 times, most recently from 73d14ba to 5f75938 Compare February 12, 2024 23:37
Makefile Outdated Show resolved Hide resolved
postgres-upgrade.dockerfile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
#!/bin/bash -eu
set -o pipefail

flag_upgradeCompletedOk="$PGDATA/../.postgres14-upgrade-successful"
flag_upgradeCompletedOk=$(readlink -f -m "$PGDATA/../.postgres14-upgrade-successful")
Copy link
Contributor Author

@sadiqkhoja sadiqkhoja Nov 4, 2024

Choose a reason for hiding this comment

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

data directory is not there when running for the first time without postgres upgrade. Another approach is to create the data directory if it's absent via make upgrade-successful

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens currently when the "data" directory is missing?

* Added Makefile for quick start and stop
* Modified start-enketo.sh for dev with hardcode secrets, single redis config
* Modified start-postgres.sh to listen postgres14-upgrade even if data directory is absent
* Added instruction in README.md
@sadiqkhoja sadiqkhoja changed the base branch from master to next November 4, 2024 20:46
-e 's/6380/6379/g' \
-e 's/${SECRET}/s0m3v3rys3cr3tk3y/g' \
-e 's/${LESS_SECRET}/this $3cr3t key is crackable/g' \
-e 's/${API_KEY}/enketorules/g' "$CONFIG_PATH.template"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason these env vars can't be handled in docker-compose.dev.yml?

@alxndrsn
Copy link
Contributor

alxndrsn commented Nov 7, 2024

Anything to make this easier v welcome 👏

I've run make dev; what do I do now?

@lognaturel
Copy link
Member

@sadiqkhoja is away for the next couple weeks so I'll try to answer questions as best I can!

I've run make dev; what do I do now?

I believe the current intended usage is that you would then run frontend and backend locally and they would have access to Enketo, pyxform, etc.

@lognaturel lognaturel changed the title Docker for local dev Add dev docker-compose file to manage supporting services Nov 7, 2024
# Sets profiles for each service depending on whether that
# service is required for development of that particular application
# For Central be/fe development, we need postgres14, pyxform, enketo, redis_main
# For Enketo development, we need postgres14, service, nginx, redis_main
Copy link
Member

Choose a reason for hiding this comment

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

Remove stale comment.

@lognaturel
Copy link
Member

I believe the idea is that the supporting services are more complex to get up and running. The involve knowledge Central dev doesn't require and some have lots of dependencies to manage. The goal is to have a way to get them up and running that is as close to the production configuration as possible and that doesn't risk getting out of date.

You can see a different angle from @spwoodcock which targets also containerizing frontend and backend for dev: https://github.com/hotosm/odkcentral/pull/1/files#diff-97db29a7915320e63d41d38a0440360a87055ee8ed03757aa263116dbbb4aabe

That approach gets to what @moise10r is after with getodk/central-frontend#1048

If we go in that direction, we should make sure there is an answer for hot reloading and debugging. We should also make sure the maintenance burden/risk of it getting out of sync is worth it.

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.

4 participants