Method for running ad-hoc containers #729
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In some scenarios a command needs to be run in a docker-container on a server. One use-case is to run database migrations when upgrading Mastodon (See "Update steps" on release notes)
I suggest adding a method that can deploy a new container specifically to run the given command. Something equivalent to running
docker-compose run --rm some_app <some command>which starts up a new container with the same configuration as some other container, runs the command in that container and then shuts down and removes the container again.Nice @benjaminlyng, do you have a proposal UI/UX for
abra?abra app run ...has some different considerations thandocker-composein terms of CLI arguments. I'd appreciate if you could take a look and see if you can figure out a design. The implementation is probably not that bad, the design is always the harded 🙃 How would you like it to work?Right, it's already a little confusing that
abra app commandis different fromabra app runso adding another similar option might not be preferable. But if I understand correctlyabra app rundoes the same asdocker compose exec. Personally I would keep the CLI as close to docker composes as possible, but thats just because that's what i know. If you renamedabra app runtoabra app execyou could match docker composes cli by adding this functionality withabra app run. Changing the behaviour of a CLI-method is obviously quite dangerous, I know, but I think it will be easier for people who are used to docker compose.We can easily do sub-command aliases which won't break other peoples scripts and be backwards compatible. I'm not that concerned with matching
docker-composeUI/UX myself. got a draft of how the CLI arguments / flags could work?Personally I'm -0 on switching to
run→execand introducingrunfor this; the Docker commands have seemed confusing to many people I've worked with (arguably they're the wrong way around, for one thing), and I expect folks will rarely need the command being proposed here.That said, I also don't have a great alternative suggestion 😖 Does swarm even support running one-shot containers?
One ratchet workaround in the meantime is that we can define
cmdcommands to be used with--localwhich could run containers on the specified (usually remote) swarm usingDOCKER_HOST😈I can't find any info on how to do it in docker swarm. And I'm not sure whether its on purpose. Perhaps it is an antipattern, it's just how mastodon suggests doing migrations during upgrades. But that's for docker-compose so it might be more suitable for development. I'm not sure.
Lets not rename commands for this.
As far as I can tell using the
--localflag specifies to run a command in an ad-hoc container locally - right? I think that's why I assumed running it without--localwould spawn a new container in the swarm.Another thing I'm confused by is the difference between using
abra app run <domain> app tootctl(which doesn't work, it lacks some environment variables) and runningtootctlfromabra app cmd <domain> app shell.@benjaminlyng
abra app cmduses bash functions in aabra.shunder the hood and exposes the correct environment variables. See the recipe for more:Right, I just assumed the environment variables would be present when I entered the container with the
runcommand. But that requires extra setup which is handled in theshellfunction.Perhaps there is no need for ad-hoc containers anyway. For mastodon the use-case with database migrations is written into the entrypoint, so there's no need to start new containers. And I thought it would be best to run tootctl from new containers to avoid stopping any processes internally, but it doesn't to cause any issues. I've added a new command to make it easier to use the tootctl CLI. Perhaps that's actually the only interface I was missing.
coop-cloud/mastodon#31 (comment)
I think
cmd --localdoesn't launch a container, it just directly runs the shell script usingbash/sh`, for what it's worth.Yes, this is because Mastodon doesn't know how to load secrets from files (required for Docker secrets); maybe we could open an issue upstream (so that Gagron can tell us no lol). I looked into this recently for another Ruby on Rails project, and I haven't been able to find any kind of standard way of doing this so unfortunately I don't yet have a good suggestion how to implement it natively.
I don't have enough of an understanding of Rails migrations, or how Mastodon uses them (I think the concept of "pre deploy" / "post deploy" migrations is something they invented? Maybe?) to say if this could cause problems. I can just say it hasn't for me so far! 🙃