Pand-Aid / pandaid-api

backend for Pand-Aid pandemic response app
3 stars 3 forks source link

make convenience scripts in "dev" folder to do common tasks #5

Closed EMCain closed 4 years ago

EMCain commented 4 years ago

A lot of these will be getting into the Docker shell and executing some command.

A current example of this is the file /dev/manage_py.sh - it should be moved to /dev/mac/manage_py.sh (and an equivalent folder should be made for Windows).

This makes it more convenient to do various common tasks, especially those involving getting a Docker shell. So for example, the command in manage_py.sh makes the "manage.py" functions built into Django easier to use by executing them in the Docker container:

docker-compose run --rm web "python manage.py $@"

Some convenience functions we should add:

geophpherie commented 4 years ago

I can kick this one off. Was also thinking of a quick guide to using VSCode to attach to a container / open within a container for similar functionality.

znmeb commented 4 years ago

I can kick this one off. Was also thinking of a quick guide to using VSCode to attach to a container / open within a container for similar functionality.

Good idea - VSCode runs on Linux, Mac and Windows.

bhgrant8 commented 4 years ago

Appears #8 was meant to address this issue? Is all behavior needed addressed? @jbeyer16 @znmeb

znmeb commented 4 years ago

Looks good to me - I just installed VSCode on my laptop (both Windows and Linux)

geophpherie commented 4 years ago

I think it handles at least the Windows/Mac manage_py scripts part. There's also some help provided on accessing inside the Docker container for any other use cases. That's a bit broad, so maybe new issues should be created if specific needs arise. Also I didn't address the:

directly access the DB with PSQL

@znmeb it seems that may be accomplished with how we've used pgAdmin before? Is there any sense in addressing that here or at least opening a new issue if we want to discuss PSQL vs pgAdmin?

znmeb commented 4 years ago

@jbeyer16 I'd let the people who are doing the heavy lifting use the tools that work for them rather than have to maintain more tools. :-) Who actually needs to directly access the database as opposed to using it the way Django does - as a CRUD engine? Ask @maryannet what she needs.

But if you want to access psql inside the container from the host it's a simple docker exec command.

geophpherie commented 4 years ago

Makes sense. Does psql come in the image?

geophpherie commented 4 years ago

It appears it does, just needs to be configured.

root@cce60a69f842:/# psql
psql: FATAL:  role "root" does not exist

I can likely create a script for it then too.

znmeb commented 4 years ago

docker exec -u postgres <container_name> psql should do the trick.

geophpherie commented 4 years ago

That was actually run from within the container. I tried the following too:

jeff@ 🦠 ~/Repos/pandaid-api $ docker exec -u postgres pandaid-api_postgres_1 psql
jeff@ 🦠 ~/Repos/pandaid-api $ docker exec pandaid-api_postgres_1 psql 
psql: FATAL:  role "root" does not exist
jeff@ 🦠 ~/Repos/pandaid-api $ 
znmeb commented 4 years ago

My bad - left off some flags:

$ docker exec -it -u postgres pandaid-api_postgres_1 psql
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.

postgres=# 
geophpherie commented 4 years ago

ah okay that worked.

Here's the equivalent command from within the container itself.

root@598b5a9195bc:/# psql -U postgres
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.

postgres=#

Since it's already a request in this issue, I'll make it into a quick script.

geophpherie commented 4 years ago

Is there any preference to docker commands vs. docker-compose commands? They both do the same thing it seems, just need to be configured.

jeff@ 🦠 ~/Repos/pandaid-api $ docker-compose run --rm postgres psql -h postgres -p 5432 -U postgres
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.

postgres=# exit
jeff@ 🦠 ~/Repos/pandaid-api $ docker exec -it -u postgres pandaid-api_postgres_1 psql   
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.

postgres=# exit
jeff@ 🦠 ~/Repos/pandaid-api $ 
znmeb commented 4 years ago

docker-compose is simpler in the development phase - you just type docker-compose up -d and you've got all the services up and running. It's bundled with the CookieCutter template so I don't see a need to abandon it.

geophpherie commented 4 years ago

Well it seems there is actually a difference. For both these psql commands and the manage.py from before, docker-compose run will spin up a new container, while docker exec will connect to an existing one. I think we actually want the docker exec syntax.

geophpherie commented 4 years ago

docker-compose looks to the service name in the docker-compose.yml and creates it. docker will look to a named container. But you have to make sure the container is running, by first running docker-compose up anyway. I'm still in favor of the docker syntax I think.

geophpherie commented 4 years ago

I think for now I'll make the docker syntax the default for these scripts, but leave the docker-compose in commented out.