WietseWind / docker-rippled

Run XRP Ledger (rippled) node in a Docker container
https://hub.docker.com/r/xrpllabsofficial/xrpld
MIT License
60 stars 34 forks source link

Add support for standalone mode from environment variables #16

Closed JST5000 closed 1 year ago

JST5000 commented 1 year ago

I'd like to use this as part of xrpl.js and xrpl-py's integration tests, but currently am unable to because we need to start the container in standalone mode and GitHub actions' services feature doesn't support passing in args to a container directly.

Previously we forked this repo, but that led to the problem of falling out of date with the latest rippled changes. (This is the setup on xrpl.js for reference)

So, since GitHub actions allows flags to be passed in, my proposed fix is to add an option to pass in the environment variable STANDALONE_MODE which starts the container in standalone mode.

(I'm open to other better ways to go about this. This seemed like the simplest change to me.)

WietseWind commented 1 year ago

@JST5000 @justinr1234 Makes perfect sense, happy to merge this. But thinking ahead: wouldn't it make more sense to pass en entire "rippled env" string to the args? To make it universal for any arg to be passed, now and in the future?

justinr1234 commented 1 year ago

@JST5000 @justinr1234 Makes perfect sense, happy to merge this. But thinking ahead: wouldn't it make more sense to pass en entire "rippled env" string to the args? To make it universal for any arg to be passed, now and in the future?

Yeah makes the most sense. Great idea! 🙏🏻

WietseWind commented 1 year ago

Update coming in, both environment variables & arguments are passed now, and confirmed during boot;

E.g.:

docker run \
  -e test123=345 \
  -it --name xrpld -p $PORT:80 \
  -v $(pwd)/../config:/config/ \
  xrpllabsofficial/xrpld:latest \
  -aaa=bbb \
  -c=ddd

Will now print (during boot):

echo "Args:"
echo "    >> [$@]"
echo ""
echo "Env:"
printenv
echo ""

Output:

Args:
    >> [-aaa=bbb -c=ddd]

Env:
HOSTNAME=049e5569c379
PWD=/
HOME=/root
test123=345
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/printenv
WietseWind commented 1 year ago

Fixed, pushed, published @ Docker Hub.

justinr1234 commented 1 year ago

Fixed, pushed, published @ Docker Hub.

Absolute legend 👏👌🙌

dangell7 commented 1 year ago

Just to chime in, I handled it like this... Where you set the target. But it seems like most want the ability to send in any env/arg so this might not work as well.

FROM base AS production
RUN echo "PRODUCTION RIPPLED"
ENTRYPOINT [ "/entrypoint.sh" ]

FROM base AS standalone
RUN echo "STANDALONE RIPPLED"
ENTRYPOINT [ "/entrypoint.sh",  "--start", "-a" ]
WietseWind commented 1 year ago

@JST5000 @dangell7 @justinr1234

New version published to Docker Hub, it allows for all three methods:

  1. Env. var passthrough
  2. Argument passthrough
  3. Arguments passed through the ENV_ARGS environment variable

So this now works:

docker run -it --rm -p $PORT:80 -e "ENV_ARGS=--start -a" -v $(pwd)/config:/config/ xrpllabsofficial/xrpld:latest

While unlikely to be used this way, even passing a combination of ENV_ARGS and cli passed args work.

JST5000 commented 1 year ago

@JST5000 @dangell7 @justinr1234

New version published to Docker Hub, it allows for all three methods:

  1. Env. var passthrough
  2. Argument passthrough
  3. Arguments passed through the ENV_ARGS environment variable

So this now works:

docker run -it --rm -p $PORT:80 -e "ENV_ARGS=--start -a" -v $(pwd)/config:/config/ xrpllabsofficial/xrpld:latest

While unlikely to be used this way, even passing a combination of ENV_ARGS and cli passed args work.

Thanks! This should help us speed up our testing a lot :)

JST5000 commented 1 year ago

@WietseWind I think the new version of this code may not have been deployed to Docker Hub. (Maybe the old version was re-deployed by accident?)

When I run the command you shared, the entrypoint.sh still looks like the old entrypoint (so ENV_ARGS doesn't work)

Exact command I ran for reference: docker run -it --rm -p $PORT:80 -e "ENV_ARGS=--start -a" -v $(pwd)/config:/config/ xrpllabsofficial/xrpld:latest

Screenshot of cat entrypoint.sh inside the docker container along with the name of the container.

image

(Relatedly, I made a PR to update the README instructions where they were off by a little bit, but even after that I'm still seeing the above behavior: https://github.com/WietseWind/docker-rippled/pull/17)

WietseWind commented 1 year ago

It has been deployed, did you clean the local Docker image cache? Read: did you remove the local image before re-creating the container?

JST5000 commented 1 year ago

Ah, yep. docker rmi ... fixed it - sorry about that :) (I thought that removing the containers was the same as removing the image)