ODM2 / CZ-Manager

CZ Manager (formerly ODM2 Admin) is an application for site level data management of environmental observations using Observation Data Model 2 (ODM2) for documentation and a detailed walkthrough see:
http://odm2.github.io/CZ-Manager
MIT License
9 stars 12 forks source link

Django2 and Docker #197

Closed miguelcleon closed 6 years ago

miguelcleon commented 6 years ago

@lsetiawan I made two minor changes to the dockerfile and I'm trying to run the build on dockerhub but I'm not really sure what I'm doing. https://hub.docker.com/r/odm2/odm2-admin/builds/

lsetiawan commented 6 years ago

@miguelcleon I just saw this. My apologies. I won't be able to work on this today, but I'll take a look tomorrow what's going on. Thanks. Does it work locally when you try to build the Docker image?

miguelcleon commented 6 years ago

@lsetiawan ok, sounds good thanks. No I haven't gotten to work. I'm trying to run it on a VM and I ran out of space on it and it is taking a long time to expand the drive. I changed the host name sent to postgresql in the latest commit to this PR. that seems to be the latest error.

miguelcleon commented 6 years ago

Now I get a different error in the docker log:

psql: could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?
Postgres is unavailable - sleeping
lsetiawan commented 6 years ago

After looking at the code, I remember what I did. I separated the database from the actual application and use docker-compose to spin things up. See https://github.com/ODM2/ODM2-Admin/tree/master/docker/docker-deploy

This auto build the image. I guess the application docker file needs to be tweaked to be a stand alone rather than trying to attach to the non-existent database, which causes the error.

miguelcleon commented 6 years ago

@lsetiawan so how was it attaching to the database before? I'm not understanding what broke. Thanks

lsetiawan commented 6 years ago

Before it installs and spins up postgresql in the background.

lsetiawan commented 6 years ago

Have you tried doing docker-compose up?

miguelcleon commented 6 years ago

@lsetiawan oh these settings files need to be updated https://github.com/ODM2/ODM2-Admin/blob/master/docker/docker-deploy/settings/

lsetiawan commented 6 years ago

@lsetiawan oh these settings files need to be updated https://github.com/ODM2/ODM2-Admin/blob/master/docker/docker-deploy/settings/

Yes indeed.

miguelcleon commented 6 years ago

forgot to change the name of this last commit

miguelcleon commented 6 years ago

It seems like docker-compose should work but I keep getting:

odm2admindb | ERROR:  database "odm2" already exists
odm2admindb | STATEMENT:  CREATE DATABASE odm2;

maybe if I comment out https://github.com/ODM2/ODM2-Admin/blob/master/docker/odm2admin/wait-for-postgres.sh#L15

lsetiawan commented 6 years ago

maybe if I comment out https://github.com/ODM2/ODM2-Admin/blob/master/docker/odm2admin/wait-for-postgres.sh#L15

That should work, but it's weird how "odm2" database already exist. hmm...

miguelcleon commented 6 years ago

nope that didn't help

miguelcleon commented 6 years ago

I needed to change the git clone branch in the dockerfile but now I get:

odm2admindb | FATAL: database "odm2" does not exist odm2adminapp | psql: FATAL: database "odm2" does not exist odm2admindb | FATAL: database "odm2" does not exist

so that CREATE DATABASE odm2; needs to run the first time only in wait-for-postgres.sh

miguelcleon commented 6 years ago

maybe it should not stop on error, like this I guess:

psql -v ON_ERROR_STOP=0 --host "$host" --username "postgres" -c "CREATE DATABASE odm2;"

lsetiawan commented 6 years ago

@miguelcleon What's the status of this?

miguelcleon commented 6 years ago

@lsetiawan seems like it works if I comment out: psql -v ON_ERROR_STOP=1 --host "$host" --username "postgres" -c "CREATE DATABASE odm2;" from here: https://github.com/ODM2/ODM2-Admin/blob/master/docker/odm2admin/wait-for-postgres.sh#L15

but only in the local copy; if I comment it out in github then I get a no odm2 error:


odm2admindb | FATAL: database "odm2" does not exist
odm2adminapp | psql: FATAL: database "odm2" does not exist
odm2admindb | FATAL: database "odm2" does not exist

So this should only run the first time; maybe move it to the dockerfile?

miguelcleon commented 6 years ago

I think it works now. Building dockerhub repo based on miguelcleon fork https://hub.docker.com/r/miguelcleon/odm2-admin/builds/

miguelcleon commented 6 years ago

success! @lsetiawan maybe you could try running the docker container? https://hub.docker.com/r/miguelcleon/odm2-admin/ pinging @emiliom

miguelcleon commented 6 years ago

@lsetiawan did you get a chance to try this?

lsetiawan commented 6 years ago

Am I still composing up or simply run the docker image?

miguelcleon commented 6 years ago

Try both. I had different issues in actually running the app in a web browser that I'm confused about.

lsetiawan commented 6 years ago

I am having sql problem when creating the database using docker-compose:

odm2adminapp | psql:/odm2adminDB.sql:30: ERROR:  schema "admin" already exists
odm2admindb | ERROR:  schema "admin" already exists
odm2admindb | STATEMENT:  CREATE SCHEMA admin;

and getting

psql: could not translate host name "db" to address: Name or service not known
Postgres is unavailable - sleeping
psql: could not translate host name "db" to address: Name or service not known
Postgres is unavailable - sleeping

because the application doesn't map to db. I think might have to put a Database option to the docker image.

miguelcleon commented 6 years ago

Are you using the django2 branch?

lsetiawan commented 6 years ago

Yepp. And used your docker image.

miguelcleon commented 6 years ago

Ok I guess we might have to put a Database option to the docker image

miguelcleon commented 6 years ago

@lsetiawan so how do we add the database option to the docker image? I've played around with this but have not had success.

lsetiawan commented 6 years ago

@miguelcleon I suggest using Docker ENV This sets the system environment variables for docker. So when running the images, you can do docker run -e DBHOST=123.23.123.12 -e DBUSER=someone -e DBPASSWORD=blahblah ...

Then id the development.py settings python file, should be able to read from os.environ with those credentials and host.