Wowu / docker-rollout

🚀 Zero Downtime Deployment for Docker Compose
https://github.com/Wowu/docker-rollout
MIT License
2.18k stars 59 forks source link

Support `docker --context` #13

Closed tadamcz closed 8 months ago

tadamcz commented 10 months ago

Could you support the docker --context flag?

It's used like this, to take the example from the Docker docs:

docker --context production container ls

I suppose you'd need to change something around here:

  -*)
    echo "Unknown option: $1"
    exit_with_usage
    ;;
  *)

and here:

# check if compose v2 is available
if docker compose >/dev/null 2>&1; then
  COMPOSE_COMMAND="docker compose"
elif docker-compose >/dev/null 2>&1; then
  COMPOSE_COMMAND="docker-compose"
else
  echo "docker compose or docker-compose is required"
  exit 1
fi

Shell scripting is not at all my strength so I'm hesitant to dive in myself.

Wowu commented 10 months ago

I decided not to implement all possible docker and docker compose flags if they can be provided via an environment variable to keep this tool simple, would this work for your use case?

env DOCKER_CONTEXT=production docker rollout

(See Docker profiles https://github.com/Wowu/docker-rollout/issues/5#issuecomment-1501538614 and remote deployment https://github.com/Wowu/docker-rollout/issues/6#issuecomment-1503198297)

tadamcz commented 10 months ago

Yes this works OK.

I had thought you could just pass arbitrary additional flags to docker and compose as follows.

i.e.

docker --xyz rollout passes xyz to docker

And docker rollout --xyz passes xyz to compose

Wowu commented 10 months ago

Actually, it sounds like a good idea to pass unknown flags, but there's a catch: the script uses docker and docker compose, and those have different flags available. I think environment variables are a nice solution, especially for a bash script tool.

tadamcz commented 10 months ago

Not sure I understand the problem; you could pass them like I described in the last comment? Is there something wrong with my suggestion?

Obviously the decision of how to spend your time is entirely yours. Thanks for the tool :)

Wowu commented 10 months ago

Oh sorry, I didn't get your idea at first. Would be great, but I'm not sure if I'm able to access flags passed to docker commands, because the docker plugin integration is pretty basic. Will check

Wowu commented 8 months ago

It works as I expected, thank you for the suggestion. Arguments before rollout are now passed to docker commands, so --context now works.

Released as https://github.com/Wowu/docker-rollout/releases/tag/v0.6