volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Docker support #211

Closed doejon closed 6 years ago

doejon commented 7 years ago

Hi, guys! Is there any chance to support sqlboiler with databases running in docker containers? So far, sqlboiler does call commands like "dropdb", "createdb", ... which are not available since docker doesn't 'expose' them. Wouldn't it be possible to not use these commands at all and run "DROP DATABASE IF EXISTS " instead?

Is there any other way to run sqlboiler with a postges-docker-instance?

Cheers

aarondl commented 7 years ago

The solution here is simply to ensure that you've got the psql tools etc. inside your testing image. It's not that docker doesn't expose them, it's that you either don't have them or they're not getting configured correctly when they're called. Which one is it?

doejon commented 7 years ago

Your solution implies that you'd need got sqlboiler running in the same docker image than postgres. I usually use the default postgres-images and setup my infrastructure by linking containers. Let's say, application A is running in a tiny little Alpine image, accessing postgres db using port 5432. Application A's docker container won't know about psql tools since it's running in a separate container. The same for development: I'd usually run postgres from a docker container locally. Though running sqlboiler then won't work since psql tools are not available on the host (which I'd love to keep clean).

aarondl commented 7 years ago

Somehow I missed this comment, super sorry about not replying sooner.

So you say that I assume that sqlboiler and postgres are running inside the same docker container but that's not the case.

I understand that your alpine image might not have the psql tools in them, but realize that you don't have to have the postgres running where the psql tools exist. Those tools are client tools and are typically packaged separately (distro dependent) and so I was wondering if it was possible to simply install them in the alpine image, you don't have to run postgres there, you just have to have the tools installed.

In Ubuntu for example it's packaged such that postgresql -> postgresql-9.5 -> postgresql-client -> postgresql-client-9.5 which does not have any dependencies that would involve the server component.

So to me the solution is still just to install the client tools wherever sqlboiler is running, and your server can still run wherever you want. Is there a problem with this approach I'm not seeing?

jadbox commented 6 years ago

Alternatively, maybe add pg tools to your alpine container?

aarondl commented 6 years ago

This is stale, and the solution presented seems acceptable to me.