Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker should work out of the box? #214

Closed
wjpjet opened this issue May 18, 2021 · 6 comments
Closed

docker should work out of the box? #214

wjpjet opened this issue May 18, 2021 · 6 comments

Comments

@wjpjet
Copy link

wjpjet commented May 18, 2021

Running docker-compose up gives:

     raise ConnectionError(self._error_message(e))
worker_1    | redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Address not available.`

and running docker-compose exec server ./init_database.sh gives many permission denied errors and:

  File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

I'm surprised even before digging into whats going on that this doesn't run out of the box. Am I missing something here? I'll paste my config:

SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXX
DATABASE_URL=data-dev.sqlite
REDISTOGO_URL=http://localhost:6379
FLASK_CONFIG=development
[email protected]
MAIL_PASSWORD=XXXXXXXXXXXXXXXXXX
[email protected]
ADMIN_PASSWORD=XXXXXXXXXXXXXXXXXXXXXXX
@abhisuri97
Copy link
Contributor

I’ll try to see if I can replicate the docker errors. In the mean time, try launching without the docker compose (basically the first part of the readme).

@abhisuri97
Copy link
Contributor

Okay, could you remove the redistogo_url from your config.env (since that's specified in the docker yml). Also, could you make sure that you have the environment variables for postgres specified in your environment (POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB)? If you're still running into issues, I'd recommend going with the non-docker compose setup.

@wjpjet
Copy link
Author

wjpjet commented May 20, 2021

Hi thanks for getting back to me!

I walked through the steps (I think you're missing a v infront of $ source env/bin/activate in running the app)

It seems to think something is already running on 6379 (even though I kill everything beforehand on that port via sudo fuser -k 6379/tcp Is something trying to start up twice?

honcho start -e config.env -f Local
18:33:17 system   | redis.1 started (pid=20025)
18:33:17 system   | web.1 started (pid=20026)
18:33:17 redis.1  | 20028:C 19 May 18:33:17.910 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18:33:17 redis.1  | 20028:C 19 May 18:33:17.910 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=20028, just started
18:33:17 system   | worker.1 started (pid=20029)
18:33:17 redis.1  | 20028:C 19 May 18:33:17.910 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
18:33:17 redis.1  | 20028:M 19 May 18:33:17.911 * Increased maximum number of open files to 10032 (it was originally set to 1024).
18:33:17 redis.1  | 20028:M 19 May 18:33:17.911 # Creating Server TCP listening socket *:6379: bind: Address already in use
18:33:17 system   | redis.1 stopped (rc=1)
18:33:17 system   | sending SIGTERM to web.1 (pid 20026)
18:33:17 system   | sending SIGTERM to worker.1 (pid 20029)
18:33:17 system   | worker.1 stopped (rc=-15)
18:33:17 system   | web.1 stopped (rc=-15)

docker-compose now gives me a similar error on 8080.

Would you also mind adding to the readme setup how to create the postgres user/pw/db?

PS saw your profile I'm a Lion grad too! BME

@abhisuri97
Copy link
Contributor

Hi, so I think this issue is going to require a fair bit of fixing on my end and I'll get on that (unfortunately I don't expect a "quick fix" since this docker compose file doesn't quite work as expected...though it somehow worked before I merged it in).
I think the best solution in the mean time would be to try and run without docker-compose and see how that works. I'm keeping this issue open until I come up with a fix.

@wjpjet
Copy link
Author

wjpjet commented May 21, 2021

Awesome, let me know if I can help in any way, or if you can provide any clarity into how the postgres admin/pw/connection setup works I can probably help!

First: for the multiple redis issue I discussed earlier it seems that it's possible to have redis running in the background (even after reboot and after a process kill... it just restarts) my solution to get the app running locally was to run: sudo service redis-server stop


So far whats happened for the postgres
I can start the containers but when I navigate to "about" or several other pathways I get a connection error due to credentials:

conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
server_1    | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

I tried no default config, and also setting config.env set to the following:

POSTGRES_USER=admin
POSTGRES_PASSWORD=example
POSTGRES_DB=mydatabase
  • I also tried going into the actual postgres container to see if I could run any scripts (couldn't find any)
  • I tried running the setup command docker-compose exec server ./init_database.sh and I got varying errors, mainly the no password supplied error.
  • I went into the webserver container and manually executed the ./init_database.sh, still didn't work
  • The reason why I want to use docker-compose is that there is an easy way to manage local/prod environments in AWS via docker-compose: https://aws.amazon.com/blogs/containers/deploy-applications-on-amazon-ecs-using-docker-compose/

@abhisuri97
Copy link
Contributor

Okay, so I have a janky solution that isn't exactly the best since it requires you specifying the db user, and pass within the docker-compose file. Anyway, the issue is just that it seems that environment variables need to be specified for POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB. I went ahead and hard coded those into the database URLs in the server and worker sections of the docker compose file like so:

version: '3.4'
services:
  server:
    build:
      context: .
    ports:
      - '5000:5000'
    volumes: 
      - './:/app'
    environment: 
      # set environment variables
      REDISTOGO_URL: http://redis:6379
      DEV_DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase
      TEST_DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase
      DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase
  
  worker:
    build:
      dockerfile: Dockerfile.worker
      context: .
    volumes: 
      - './:/app'
    environment: 
      # set environment variables
      REDISTOGO_URL: http://redis:6379
      DEV_DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase
      TEST_DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase
      DATABASE_URL: postgres://admin:example@postgres:5432/mydatabase

  postgres:
    image: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: example
      POSTGRES_DB: mydatabase
    volumes:
    - db-data:/var/lib/postgresql/data
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  redis:
    image:
      redis:6-alpine

volumes:
  db-data:

Once you do that (and resolve the redis issue), I was able to get things running on a laptop that has docker freshly installed.

Another thing you may run into: when you run docker-compose exec server ./init_database.sh, the script may not have the correct file permissions (you'll get a "permission denied error"). If that's the case, run chmod 755 ./init_database.sh and then run the docker compose exec command. Note, you only need to run this command once to set up the db.

Anyway, let me know if that resolves things. There are also some environment variables you'll need to change such as the MAIL_USERNAME and MAIL_PASSWORD and SECRET_KEY in the Docker files. (though I'd definitely welcome a pull request that allows you to read in a .env file instead).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants