# BikeBike
#
# ENV DATABASE_URL string = https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
#
# docker-compose.build:
#
# docker compose up -d
# docker compose run --rm bikebike rake db:setup
# docker compose run --rm bikebike rake db:migrate 
# docker compose run --rm bikebike rake assets:precompile
# docker compose down
# docker compose up -d 
#
# Never do this because new sprockets and manifest.js isn't precompiling to *css, and breaks the container
#  -- docker-compose run bikebike rake bumbleberry:update --
#
# This is why we resort to git lfs, and utilize precompiled css, 
# which is updated as requuired to newest modern browsers with caniuse.js 
#
# exporting database:  pg_dump -c -U bike_bike bike_bike > bike_bike.sql

services:

  redis:
    # container_name: bikebikebike-redis
    image: redis:6.2-alpine 
    ports:
      - "6379"
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    #volumes:
    #  -

  # Run sidekiq as it's own process using the same image that bikbike uses!
  sidekiq:
    image: bikebikebike 
    # container_name: bikebikebike-sidekiq
    command: sidekiq -q production
    environment:
      - REDIS_URL=redis://redis:6379
      - DATABASE_URL=${DATABASE_URL:-postgresql://bike_bike:password@db/bike_bike?encoding=unicode&pool=5}
      - PORT=3000
      - RAILS_ENV=${RAILS_ENV:-production}
      - SMTP_ADDRESS=${SMTP_ADDRESS:-fake-smtp.bikebike.org}
      - SMTP_DOMAIN=${SMTP_DOMAIN:-bikebike.org}
      - SMTP_PORT=${SMTP_PORT:-587}
      - SMTP_USER_NAME=${SMTP_USER_NAME:-info@bikebike.org}
      - SMTP_PASSWORD=${SMTP_PASSWORD:-fake}
      - SMTP_SSL=${SMTP_SSL:-false}
      - ADMIN_EMAIL=${ADMIN_EMAIL:-info@bikebike.org}
      - DEFAULT_URL=${DEFAULT_URL:-bikebike.org}
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  db:
    # container_name: bikebikebike-db
    image: postgres:9.5
    ports:
      - "5432"
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    volumes:
      - bikebikebike_db:/var/lib/postgresql/data
    environment:
     - POSTGRES_PASSWORD=password
     - POSTGRES_USER=bike_bike
     - POSTGRES_DB=bike_bike

  bikebike:
    build: .
    image: bikebikebike
    # container_name: bikebikebike
    networks:
      letsencrypt:
      default: 
    command: /bin/sh -c "rm -f /app/BikeBike/tmp/pids/server.pid  && rails server -b '0.0.0.0'"
    # Add environment values that are not in .env (environment:) below in the bike_bike_advanced_environment file
    # Empty file ok, too, or just comment out this section
    env_file:
      - bike_bike_advanced_environment
    # Add your own environment values in .env, or use the default ones
    environment:
      - PORT=3000
      - RAILS_ENV=${RAILS_ENV:-production}
      - DATABASE_URL=${DATABASE_URL:-postgresql://bike_bike:password@db/bike_bike?encoding=unicode&pool=5}
      - SMTP_ADDRESS=${SMTP_ADDRESS:-fake-smtp.bikebike.org}
      - SMTP_DOMAIN=${SMTP_DOMAIN:-bikebike.org}
      - SMTP_PORT=${SMTP_PORT:-587}
      - SMTP_USER_NAME=${SMTP_USER_NAME:-info@bikebike.org}
      - SMTP_PASSWORD=${SMTP_PASSWORD:-fake}
      - SMTP_SSL=${SMTP_SSL:-false}
      - ADMIN_EMAIL=${ADMIN_EMAIL:-info@bikebike.org}
      - DEFAULT_URL=${DEFAULT_URL:-bikebike.org}
      - REDIS_URL=redis://redis:6379
      - RECAPTCHA_SECRET_KEY=${RECAPTCHA_SECRET_KEY:-123456789}
      - RECAPTCHA_SITE_KEY=${RECAPTCHA_SITE_KEY:-123456789}      
    volumes:
      - bikebikebike:/app/BikeBike
      - bikebikebike_bundle:/usr/local/bundle
      - bikebikebike_uploads:/app/BikeBike/public/uploads
    expose:
      - "3000"
    links:
      - db
    # Make sure to rename container to what is being used 
    labels:
      ofelia.enabled: "true" # in rss2email      
      ofelia.job-exec.bikebikebike-caniuse.schedule: "@every 6h"
      ofelia.job-exec.bikebikebike-caniuse.container: "bikebikebike"
      ofelia.job-exec.bikebikebike-caniuse.command: "/app/BikeBike/caniuse.js"
      ofelia.job-exec.bikebikebike-caniuse.user: "root:root"
      ofelia.job-exec.bikebikebike-browserlist.schedule: "@every 24h"
      ofelia.job-exec.bikebikebike-browserlist.container: "bikebikebike"
      ofelia.job-exec.bikebikebike-browserlist.command: "/root/.local/share/pnpm/pnpm update browserlist@latest"
      ofelia.job-exec.bikebikebike-browserlist.user: "root:root"
    restart: always
    logging:
      driver: "json-file"  
      options:
        max-size: "10m"
        max-file: "3"

# Currently set to false for all volumes for development
volumes:
  bikebikebike_db:
    external: false 
  bikebikebike:
    external: false 
  bikebikebike_bundle:
    external: false 
  bikebikebike_uploads:
    external: false 

# Remove this network if you don't use it
networks:
  letsencrypt:
    external: true
