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

feat: Dockerize DP 🐳 #22

Merged
merged 5 commits into from
Oct 7, 2024
Merged

feat: Dockerize DP 🐳 #22

merged 5 commits into from
Oct 7, 2024

Conversation

kaynetik
Copy link
Contributor

@kaynetik kaynetik commented Oct 4, 2024

TODOs:

  • Centralize all build efforts (probably docker/build)
    • Enable makefile
  • Verify entry point script with valid configs
  • Create GHA release pipeline

Commits

  • feat: GHA Build & Release 🚀
  • feat: Introduce pre-commit hook
  • refactor: Improve entrypoint 🐳
  • feat: Established an entrypoint script for DP runner
  • feat: Run DP with Docker

Motivation

(Write your motivation here)

Explanation of Changes

(Write your explanation here)

Testing

(Write your test plan here)

Related PRs and Issues

This commit introduces a dockerized workflow for data proxy.
This commit primarily focuses on enabling conditional logic for
initialization via `bun start run <COND>`.
@kaynetik kaynetik self-assigned this Oct 4, 2024
- Implement dynamic configuration handling in entrypoint script
- Add support for three startup scenarios:
  1. Both config.json and private key available
  2. Only config.json available
  3. Neither config.json nor private key available
- Introduce automatic `bun start init` execution when needed
- Improve error handling and logging in the entrypoint script
@kaynetik kaynetik marked this pull request as ready for review October 7, 2024 11:39
@kaynetik kaynetik requested a review from Thomasvdam October 7, 2024 11:39
Copy link
Member

@mariocao mariocao left a comment

Choose a reason for hiding this comment

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

Looks good to me, maybe add some docker instructions in the readme, but we can open an issue for that and do it later. Your call.

@kaynetik
Copy link
Contributor Author

kaynetik commented Oct 7, 2024

I'll update the docs in the separate PR, won't forget it ;)
My intention right now is to purely focus on deploying DP asap.

@kaynetik kaynetik merged commit 0041f80 into main Oct 7, 2024
2 checks passed
@kaynetik kaynetik deleted the kaynetik/docker branch October 7, 2024 11:53
Copy link
Member

Choose a reason for hiding this comment

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

Unless we standardise on something as a team I would expect these files to be ignored. In the explorer we use https://commitlint.js.org/guides/local-setup.html and Husky to manage git hooks, but given that a more diverse group works in this repo we should probably discuss it first :P

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 didn't notice Husky was used. pre-commit wouldn't force anyone, nor would it be active locally before you call pre-commit install.

Where is the adequate spot to initiate this discussion? @Thomasvdam

Copy link
Member

Choose a reason for hiding this comment

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

Probably in the engineering Slack channel, or opening a PR that introduces the tool.

The reason I commented on this file is that if we want to commit this file (and this workflow) we should also document it in the repo, otherwise it's just clutter.

Comment on lines +46 to +49
# Neither config.json nor private key is provided
echo "Running with --disable-proof"
run_bun_command start init
RUN_CMD="start run --disable-proof"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense: --disable-proof should only skip validating whether the incoming request has the correct proof, it doesn't deal with the private key or config at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If neither of the two is provided, then my assumption was that we intend to run this in "debug" mode.

Otherwise, if we initiate bun start run when those two aren't provided and -dp isn't enabled the tool will call exit 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would you like me to address third scenario, or do we have 3rd and 4th that I missed?

Copy link
Member

Choose a reason for hiding this comment

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

The data-proxy can not run when there is no config or no private key (file). --disable-proof only disables the request verification, so it should be a completely separate option.

I think the scenarios should be covered by the binary itself where it will error if it is unable to find a config and/or private key (file).

If someone wants to run it in debug mode they should pass the --disable-proof flag manually.

Copy link
Member

Choose a reason for hiding this comment

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

yes, passing it manually makes sense, maybe we could have an container env variable like FLAGS or so..

Comment on lines +36 to +44
if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then
# Both config.json and private key are provided
echo "Running with config and private key"
RUN_CMD="start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json"
elif [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = false ]; then
# Only config.json is provided
echo "Running with config only"
run_bun_command start init
RUN_CMD="start run --config /app/config.json"
Copy link
Member

Choose a reason for hiding this comment

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

I think the binary takes care of these checks, is there a reason to also do it in the entrypoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that I know how to execute the binary.

e.g.

if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then => bun start init not required

Also, if I don't know which ones were provided do we really wanna guarantee graceful handling of non-existent files. Or this scenario => we call bun start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json" but file app/data-proxy-private-key.json" doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure what the best approach would be here... 🤔

I'm partial to letting the binary take care of everything as this reduces the maintenance burden on our end since the container doesn't really need to know anything.

If I want to initialise I should do docker run <IMAGE_NAME> init and pass a volume so I can persist the config and generated key.
For registration I can then do docker run <IMAGE_NAME> register <PAYOUT_ADDRESS> <AMOUNT> and click the link from the output to complete the registration.
And to run it just do docker run <IMAGE_NAME> run.

I guess that get a little messy with compose though, don't know how to do that in an elegant fashion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My primary goal here was to dockerize in the best way possible that would enable first and foremost a functioning deployment.

Having a manual step in the deployment to devnetv4 would increase friction a lot.

Can we discuss these points on a call?

Comment on lines +20 to +23
# If private key file does not exist, check if the private key is provided via environment variable
echo "Private key provided via environment variable"
echo "$SEDA_DATA_PROXY_PRIVATE_KEY" >/app/data-proxy-private-key.json
PK_EXISTS=true
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will work, as the key file is a JSON file with both the public and private key. I'd imagine most people would only supply the private key as an environment variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then how do we use $SEDA_DATA_PROXY_PRIVATE_KEY?

Copy link
Member

Choose a reason for hiding this comment

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

If the env var is set the data-proxy uses that to construct the private/public key pair and won't even attempt to read the key file.

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.

🔧 Add docker container support
3 participants