topkecleon / otouto

A Lua-based Telegram bot with plugins.
http://otou.to
GNU Affero General Public License v3.0
173 stars 112 forks source link

Add Docker support #103

Closed JacobAMason closed 6 years ago

JacobAMason commented 6 years ago

I added a small Dockerfile that will grab the necessary dependencies to run the bot. I also turned the api key and admin id in config.lua into environment variables so they could be passed into the docker container at startup.

Example: docker run -e OTOUTO_BOT_API_KEY="apikeyhere" -e ADMIN_ID="idhere" jacobamason/otouto

bb010g commented 6 years ago

If we're going to do Docker, I'd rather do a more minimal image that pulls in luarocks and does an install with that. Xenial is needlessly heavy.

JacobAMason commented 6 years ago

The Xenial Docker image is pretty small (111Mb). The dependencies themselves are what's taking up most of the space. I picked Ubuntu as the base because of a warning I read here that said Ubuntu was already tested. I can try to make this a multistage build and lose some of the build-time dependencies.

bb010g commented 6 years ago

I may try my hand at this in around an hour with a more minimal image if you want to give multi-stage a shot.

JacobAMason commented 6 years ago

New image size is 124M

bb010g commented 6 years ago

Aaaand that's pretty much what I was going to try for. Can't think of what I'd add besides making luarocks build-time dependencies (e.g. GCC) be uninstalled when done and using --no-cache add, as documented here.

JacobAMason commented 6 years ago

Ha, I thought about doing that so I guess I will. Thanks for the link

JacobAMason commented 6 years ago

Saved a whole megabyte, lel

bb010g commented 6 years ago

Only a single MB? That's disappointing. Going to bed for now, but I'll try out some more hard stuff tomorrow. This feels like it should be able to get a lot smaller. Aside from the concerns about package deletion, this looks like a solid Alpine image though.

JacobAMason commented 6 years ago

Ehh, those development libraries are probably just small header files. I think the rest of the space is in whatever rocks are installed--and I know nothing about lua, so I'm no help there, sorry.

bb010g commented 6 years ago

Sorry, one last thing: could you combine the run commands into one chain? After that, LGTM.

JacobAMason commented 6 years ago

Ahh, that was the key to making it smaller: only 8.13MB now. I guess Docker saves those intermediate stages in the final image? Hum.

bb010g commented 6 years ago

Cool. Could you use apk --no-cache add --virtual build-deps … && … && apk del build-deps and squash your commits? (There's not much point to having each of these steps in the final history.)

JacobAMason commented 6 years ago

Whenever you merge in GitHub, it will give you the option to squash and merge, that way you can name the merge whatever you want.

bb010g commented 6 years ago

Sorry, forgot that was a new feature.

JacobAMason commented 6 years ago

Woot. Thanks