Freika / dawarich

Self-hosted alternative to Google Location History (Google Maps Timeline)
https://dawarich.app
GNU Affero General Public License v3.0
1.76k stars 28 forks source link

Creating with existing database #88

Open ilijamt opened 2 months ago

ilijamt commented 2 months ago

Describe the bug I wanted to run it with an existing database. But I get an error. Also, DATABASE_NAME is currently ignored even though I have it set to dawarich it still tries to create a new database called dawarich_production or dawarich_development depending on the RAILS_ENV variable.

Version 0.8.0

To Reproduce Here are my env variables

- name: SECRET_KEY_BASE
   value: ib2ea9quei2asdgoorieghieb7asdgasghphiG2ieghae7Goa8oovaix
- name: RAILS_ENV
   value: production
- name: REDIS_URL
   value: redis://db01:6379/41
- name: DATABASE_HOST
   value: db01.example.com
- name: DATABASE_USERNAME
   value: dawarich
- name: DATABASE_PASSWORD
   value: aiGhah3ahYae
- name: DATABASE_NAME
   value: dawarich
- name: APPLICATION_HOST
   value: dawarich
- name: BACKGROUND_PROCESSING_CONCURRENCY
   value: "10"

Expected behavior Be able to use existing database and populate it.

Logs

RubyGems system software updated
Successfully installed bundler-2.5.9
1 gem installed
Creating database dawarich...
PG::InsufficientPrivilege: ERROR:  permission denied to create database
Couldn't create 'dawarich_production' database. Please check your configuration.
bin/rails aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create database (ActiveRecord::StatementInvalid)
tylwright commented 2 months ago

When you say 'existing database,' do you mean that Dawarich was installed previously and was writing to this Postgres instance or are you saying that this is a Postgres instance that you use for other apps and you wish to use it with a clean Dawarich installation?

tnt1232007 commented 2 months ago

I got the exact same issue last time I tried, few days ago.

I am using an existing Postgres instance, that I use for other apps. Created a new user dawarich_user, then a new database dawarich_db owned by that user.

environment:
      RAILS_ENV: development
      DATABASE_HOST: xx.xx.xx.xx
      DATABASE_PORT: 5432
      DATABASE_NAME: dawarich_db
      DATABASE_USERNAME: dawarich_user
      DATABASE_PASSWORD: dawarich_pw
Freika commented 1 month ago

@ilijamt @tnt1232007 Can you share the docker-compose.yml file for your postgres database so I could reproduce it locally? Thank you

tnt1232007 commented 1 month ago

Here's mine, nothing special

version: '3.9'
services:
  postgres:
    container_name: postgres
    image: postgres:16.3
    network_mode: bridge
    restart: unless-stopped
    ports:
      - 5432:5432
    volumes:
      - ./data:/var/lib/postgresql/data
      - ./backup:/var/lib/postgresql/backup
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}

Also the script to create db and user

CREATE USER dawarich_user WITH PASSWORD 'dawarich_pw';
CREATE DATABASE dawarich_db WITH OWNER dawarich_user;
ilijamt commented 1 month ago

Here is my docker compose file. I have a dedicated postgres server that is running on a separate VM that is used for other applications as well. That server also has a running redis server as well. I've replaced the real domain with example.com

version: '3'
networks:
  dawarich:
services:
  dawarich_app:
    image: freikin/dawarich:0.8.6
    container_name: dawarich_app
    volumes:
      - gem_cache:/usr/local/bundle/gems
      - public:/var/app/public
    networks:
      - dawarich
    ports:
      - 3000:3000
    stdin_open: true
    tty: true
    entrypoint: dev-entrypoint.sh
    command: ['bin/dev']
    restart: on-failure
    environment:
      RAILS_ENV: production
      SECRET_KEY_BASE: ib2ea9quei2iechoorieghieb7juugie6choora1ahphiG2ieghae7Goa8oovaix
      REDIS_URL: redis://db01.example.com:6379/41
      DATABASE_HOST: db01.example.com
      DATABASE_USERNAME: dawarich
      DATABASE_PASSWORD: aiGhah3ahYae
      DATABASE_NAME: dawarich
      MIN_MINUTES_SPENT_IN_CITY: 60
      APPLICATION_HOST: dawarich.example.com
      APPLICATION_HOSTS: dawarich.example.com
      TIME_ZONE: Europe/London
      APPLICATION_PROTOCOL: http
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
  dawarich_sidekiq:
    image: freikin/dawarich:0.8.6
    container_name: dawarich_sidekiq
    volumes:
      - gem_cache:/usr/local/bundle/gems
      - public:/var/app/public
    networks:
      - dawarich
    stdin_open: true
    tty: true
    entrypoint: dev-entrypoint.sh
    command: ['sidekiq']
    restart: on-failure
    environment:
      RAILS_ENV: production
      SECRET_KEY_BASE: ib2ea9quei2iechoorieghieb7juugie6choora1ahphiG2ieghae7Goa8oovaix
      REDIS_URL: redis://db01.example.com:6379/41
      DATABASE_HOST: db01.example.com
      DATABASE_USERNAME: dawarich
      DATABASE_PASSWORD: aiGhah3ahYae
      DATABASE_NAME: dawarich
      MIN_MINUTES_SPENT_IN_CITY: 60
      APPLICATION_HOST: dawarich.example.com
      APPLICATION_HOSTS: dawarich.example.com
      TIME_ZONE: Europe/London
      APPLICATION_PROTOCOL: http
      BACKGROUND_PROCESSING_CONCURRENCY: 10
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
    depends_on:
      - dawarich_app

volumes:
  gem_cache:
  shared_data:
  public:

And here is the stack trace from the container

Tasks: TOP => db:create
(See full trace by running task with --trace)
Environment: production
db01.example.com (192.168.178.12:5432) open
Latest version already installed. Done.
Successfully installed bundler-2.5.9
1 gem installed
Creating database dawarich...
PG::InsufficientPrivilege: ERROR:  permission denied to create database
Couldn't create 'dawarich_production' database. Please check your configuration.
bin/rails aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create database (ActiveRecord::StatementInvalid)
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:55:in `exec'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:55:in `block (2 levels) in raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1028:in `block in with_raw_connection'
/var/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:54:in `block in raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1143:in `log'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:53:in `raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:521:in `internal_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:131:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:25:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:46:in `create_database'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/postgresql_database_tasks.rb:23:in `create'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:117:in `create'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:171:in `block in create_current'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:562:in `block (2 levels) in each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:559:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:559:in `block in each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:558:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:558:in `each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:171:in `create_current'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/railties/databases.rake:46:in `block (2 levels) in <main>'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:156:in `invoke_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:73:in `block in invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:149:in `with_argv'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:69:in `invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands.rb:18:in `<main>'
/var/app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'

Caused by:
PG::InsufficientPrivilege: ERROR:  permission denied to create database (PG::InsufficientPrivilege)
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:55:in `exec'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:55:in `block (2 levels) in raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1028:in `block in with_raw_connection'
/var/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1000:in `with_raw_connection'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:54:in `block in raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:1143:in `log'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:53:in `raw_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:521:in `internal_execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:131:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:25:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:46:in `create_database'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/postgresql_database_tasks.rb:23:in `create'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:117:in `create'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:171:in `block in create_current'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:562:in `block (2 levels) in each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:559:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:559:in `block in each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:558:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:558:in `each_current_configuration'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/tasks/database_tasks.rb:171:in `create_current'
/var/app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/railties/databases.rake:46:in `block (2 levels) in <main>'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:156:in `invoke_rake'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:73:in `block in invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:149:in `with_argv'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/command.rb:69:in `invoke'
/var/app/vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands.rb:18:in `<main>'
/var/app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
Tasks: TOP => db:create
(See full trace by running task with --trace)
ilijamt commented 1 month ago

If someone is interested here are the k8s manifests.

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dawarich-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dawarich-app
  template:
    metadata:
      labels:
        app: dawarich-app
    spec:
      containers:
      - name: dawarich-app
        image: freikin/dawarich:latest
        ports:
        - containerPort: 3000
        volumeMounts:
        - name: gem-cache
          mountPath: /usr/local/bundle/gems
        - name: public
          mountPath: /var/app/public
        env:
        - name: SECRET_KEY_BASE
          value: ib2ea9quei2iechoorieghieb7juugie6choora1ahphiG2ieghae7Goa8oovaix
        - name: RAILS_ENV
          value: production
        - name: REDIS_URL
          value: redis://db01.example.com:6379/41
        - name: DATABASE_HOST
          value: db01.example.com
        - name: DATABASE_USERNAME
          value: dawarich
        - name: DATABASE_PASSWORD
          value: aiGhah3ahYae
        - name: DATABASE_NAME
          value: dawarich
        - name: MIN_MINUTES_SPENT_IN_CITY
          value: "60"
        - name: APPLICATION_HOST
          value: dawarich.example.com
        - name: TIME_ZONE
          value: Europe/Amsterdam
        command: ['sh', '-c', 'dev-entrypoint.sh && bin/dev']
      volumes:
      - name: gem-cache
        persistentVolumeClaim:
          claimName: gem-cache
      - name: public
        persistentVolumeClaim:
          claimName: public
---
apiVersion: v1
kind: Service
metadata:
  name: dawarich-app
spec:
  selector:
    app: dawarich-app
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dawarich-sidekiq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dawarich-sidekiq
  template:
    metadata:
      labels:
        app: dawarich-sidekiq
    spec:
      containers:
      - name: dawarich-sidekiq
        image: freikin/dawarich:latest
        volumeMounts:
        - name: gem-cache
          mountPath: /usr/local/bundle/gems
          readOnly: true
        - name: public
          mountPath: /var/app/public
          readOnly: true
        env:
        - name: SECRET_KEY_BASE
          value: ib2ea9quei2iechoorieghieb7juugie6choora1ahphiG2ieghae7Goa8oovaix
        - name: RAILS_ENV
          value: production
        - name: REDIS_URL
          value: redis://db01.example.com:6379/41
        - name: DATABASE_HOST
          value: db01.example.com
        - name: DATABASE_USERNAME
          value: dawarich
        - name: DATABASE_PASSWORD
          value: aiGhah3ahYae
        - name: DATABASE_NAME
          value: dawarich
        - name: APPLICATION_HOST
          value: dawarich.example.com
        - name: BACKGROUND_PROCESSING_CONCURRENCY
          value: "10"
        command: ['sh', '-c', 'dev-entrypoint.sh && sidekiq']
      volumes:
      - name: gem-cache
        persistentVolumeClaim:
          claimName: gem-cache
      - name: public
        persistentVolumeClaim:
          claimName: public
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/tls-acme: "true"
    gethomepage.dev/enabled: "true"
    gethomepage.dev/description: "Self-hosted alternative to Google Location History (Google Maps Timeline)"
    gethomepage.dev/group: Home
    gethomepage.dev/icon: https://raw.githubusercontent.com/excalidraw/excalidraw/master/public/android-chrome-512x512.png
    gethomepage.dev/name: Dawarich
  name: dawarich
  namespace: dawarich
spec:
  ingressClassName: nginx
  rules:
  - host: dawarich.example.com
    http:
      paths:
      - backend:
          service:
            name: dawarich-app
            port:
              number: 3000
        path: /
        pathType: Prefix
  tls:
  - hosts:
    - dawarich.example.com
    secretName: dawarich.example.com-tls
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: dawarich
resources:
  - namespace.yaml
  - pvc.yaml
  - deployment-dawarich-app.yaml
  - deployment-dawarich-sidekiq.yaml

images:
 - name: freikin/dawarich
   newTag: 0.8.0
---
apiVersion: v1
kind: Namespace
metadata:
  name: dawarich
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gem-cache
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: public
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
jimrushPersonal commented 1 month ago

Note, I think at least one file (dev-docker-entrypoint.sh) has a hard coded port number. I discovered this when trying to connect to an external database with just changes to the docker file.

tylwright commented 1 month ago

@tnt1232007 - What if you grant privs to the user?

GRANT ALL PRIVILEGES ON DATABASE dawarich_db TO dawarich_user;
Plydow commented 2 weeks ago

Hello,

While attempting to follow @ilijamt's approach, I tested @tylwright's suggestion and observed the results of the migrations on my instance. It turns out that, at a minimum, the migrations do not respect the DATABASE_NAME environment variable for the database name. The migrations try to create two databases, dawarich_development and dawarich_test, and with the minimal permissions I have granted to the user, this operation is denied.

I have two questions: Is it absolutely necessary to have both databases? And can we ensure that the migrations use the provided database name?