themotte / rDrama

This code runs https://www.themotte.org. Forked from https://github.com/Aevann1/rDrama
GNU Affero General Public License v3.0
25 stars 31 forks source link

fix docker-compose so that there is no hang on startup after migrations/tests #555

Open justcool393 opened 1 year ago

justcool393 commented 1 year ago

back in november i mentioned that there was a weird edge case where i'd try and run a migration and then afterward then the containers are unable to boot.

the solution at the time that I came up with was "delete everything"

image

and rebuild the entire system from the ground up. which isn't ideal. anyway remembering that it was after running a migration i had a hunch that it was somehow in operation mode and sure enough docker ps showed

           Name                         Command                State     Ports
------------------------------------------------------------------------------
themotte-rdrama_postgres_1   docker-entrypoint.sh postgres    Exit 0
themotte-rdrama_redis_1      docker-entrypoint.sh redis ...   Exit 0
themotte-rdrama_site_1       /bin/sh -c sleep infinity        Exit 137

how sad! it was sleeping forever so of course it wasn't working. anyway i found this bug on the bug tracker

https://github.com/docker/compose/issues/7262

so my proposal is this

change docker-compose.yml to be

version: '2.3'

services:
  production:
    build:
      context: .
      target: release
    volumes:
      - "./:/service"
    env_file: bootstrap/site_env
    environment:
      - DATABASE_URL=postgresql://postgres@postgres:5432
      - REDIS_URL=redis://redis
      - ENFORCE_PRODUCTION=True
    links:
      - "redis"
      - "postgres"
    ports:
      - "80:80"
    depends_on:
      - redis
      - postgres

  dev:
    build:
      context: .
      target: dev
    volumes:
      - "./:/service"
    env_file: bootstrap/site_env
    environment:
      - DATABASE_URL=postgresql://postgres@postgres:5432
      - REDIS_URL=redis://redis
      - ENFORCE_PRODUCTION=False
    links:
      - "redis"
      - "postgres"
    ports:
      - "80:80"
    depends_on:
      - redis
      - postgres

  operation:
    build:
      target: operation

  redis:
    image: redis
    ports:
      - "6379:6379"

  postgres:
    image: postgres:12.3
    # command: ["postgres", "-c", "log_statement=all"]
    # uncomment this if u wanna output all SQL queries to the console
    volumes:
      - "./bootstrap/original-schema.sql:/docker-entrypoint-initdb.d/00-schema.sql"
      - "./bootstrap/original-seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql"
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "5432:5432"

and have the startup command be docker-compose up dev. this also has the benefit of letting people easily test the production configuration and running operation mode easily as well. thoughts?

zorbathut commented 1 year ago

I'm not a huge fan of the duplicated syntax in these :V but it does seem reasonable in general, honestly. Hmm - that's the only volume it has? I guess user icons are just stored in the directory tree when running in test mode?

I assume there's no clever way to guarantee that only one of those runs at a time?