Skip to content

Conversation

@pkarman
Copy link

@pkarman pkarman commented Oct 31, 2025

Purpose

These changes add Docker support to allow for local development consistent with the deployed environment. In theory, this would allow for deployment into alternate cloud platforms.

Changes

  • add documentation to the Makefile
  • add new make targets
  • add Dockerfile and docker-compose.yml
  • remove requirement for GCP application configuration
  • add shim for Google logging when run in debug mode

See also

MyFriendBen/benefits-api#1216

# Start the API
gunicorn -b :"$PORT" policyengine_api.api --timeout 300 --workers 5 --preload &

# Start multiple workers using POSIX-compliant loop
Copy link

Choose a reason for hiding this comment

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

Both the README.md and ./gcp/policyengine_api/start.sh mention worker.py but I found no file with that name in the repo. Are the docs just out of date?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, the docs are out of date. We instead delegate to an external service for what we used to use these workers for.

@MaxGhenis
Copy link
Collaborator

Thank you @pkarman! @anth-volk will take a look when he's back from vacation next week.

@MaxGhenis MaxGhenis requested a review from anth-volk November 5, 2025 23:23
Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this @pkarman and apologies for the delay in review. I left one concern around how the API currently interfaces with an external API service, but otherwise, this would be amazing to have. Have you built/run this locally at all?

# Start the API
gunicorn -b :"$PORT" policyengine_api.api --timeout 300 --workers 5 --preload &

# Start multiple workers using POSIX-compliant loop
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, the docs are out of date. We instead delegate to an external service for what we used to use these workers for.

"GOOGLE_APPLICATION_CREDENTIALS not set; unable to run simulation API."
)

return
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue, unclear impact: We call an external service using this GAC; without it, the app will not return a society-wide simulation result. I'm unclear on how we might handle this; do you have any ideas?

Copy link
Author

@pkarman pkarman Nov 12, 2025

Choose a reason for hiding this comment

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

I believe the issue here is along the lines of "how should the app behave if it is missing an expected configuration?"

Currently the code both logs an error and raises an exception during app start-up time, as the SimulationAPI service checks for the config when it is instantiated. Maybe the config check could be moved to a new setup() method and deferred until the first time run() is called? That way the rest of the API could start without relying on a (possibly non-existent) GAC config.

In my case, I was using the MyFriendBen benefits API against a local instance of the PolicyEngineAPI and I didn't need the full society-wide simulation service at all.

So if the config check were somehow deferred till it was actually needed, that would be ideal from my pov.

Perhaps __init__ could continue to check for the config, and maybe warn instead of error log when missing, but the actual exception could be moved till run() time.

logger = logging.getLogger(__name__)

# shims to make default logger act like google's
levels = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

accolade: Like the shims!

@pkarman
Copy link
Author

pkarman commented Nov 12, 2025

Thank you for your work on this @pkarman and apologies for the delay in review. I left one concern around how the API currently interfaces with an external API service, but otherwise, this would be amazing to have. Have you built/run this locally at all?

Yes, I have run built and run locally, in coordination with this PR for MyFriendBen.

If you approve of my suggestion for deferring the GAC check, I'd be happy to implement that as part of this PR.

@anth-volk
Copy link
Collaborator

Just to check with you @pkarman, my understanding had been that MyFriendBen was using our household API, which already has some Docker functionality, though no Docker compose. This package here is the API we use in production to host our website. Were you looking to move toward using our full API, as well?

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