Skip to content

Commit

Permalink
update local env to use docker
Browse files Browse the repository at this point in the history
  • Loading branch information
acidtib committed May 1, 2023
1 parent 7740f2e commit e7da6e8
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 39 deletions.
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
WEB_CONCURRENCY=2

RAILS_ENV=development

DATABASE_URL=postgres://rails:[email protected]:5433/magma_chat_development

REDIS_URL=redis://:[email protected]:6380/0

MARQO_URL=https://marqo_url/


GOOGLE_CLIENT_ID=.......
GOOGLE_CLIENT_SECRET=.......

OPENAI_ACCESS_TOKEN=.......
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# ignore dots
.env
.env.development
.env.local
.DS_Store
.docker

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ COPY . .
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=1 ./bin/rails assets:precompile
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y gnupg2 libpq-dev && \
apt-get install --no-install-recommends -y libpq-dev && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ gem "bootsnap", require: false

gem "action-cable-redis-backport", "~> 1"
gem "cable_ready", "~> 5.0.0"
gem "dotenv", "~> 2.8"
gem "faker"
gem "instant18n", "~> 0.3.0"
gem "httparty"
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ DEPENDENCIES
cable_ready (~> 5.0.0)
capybara
debug
dotenv (~> 2.8)
error_highlight (>= 0.4.0)
factory_bot_rails
faker
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,23 @@ Here are some of the cool features we are envisioning:

* Ruby 3.2.1

* Requires Postgres and Redis to be running
* Requires Docker

* Run `rails db:setup` to create the database
* Long-term memory for bots requires Marqo, an open-source, multi-modal vector search engine that you can download and run locally using Docker. More information at https://www.marqo.ai/

* Run `bin/dev` to fire up the app
configure environment variables
```sh
cp .env.example .env.local
```

* Long-term memory for bots requires Marqo, an open-source, multi-modal vector search engine that you can download and run locally using Docker. More information at https://www.marqo.ai/
fire up the app
```sh
docker-compose up --build
```

### OpenAI API

Make sure you have `OPENAI_ACCESS_TOKEN` environment variable set. (Developers, use a `.env` file in the root of the project.)
Make sure you have `OPENAI_ACCESS_TOKEN` environment variable set. (Developers, use a `.env.local` file in the root of the project.)

### Google Oauth

Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "dotenv/load"
require_relative "boot"

require "rails/all"
Expand Down
6 changes: 0 additions & 6 deletions config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations.

if ENV["RAILS_ENV"] == "production"
require "dotenv/load"
else
require 'dotenv'
Dotenv.load('.env.development')
end
9 changes: 4 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new(STDOUT)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
Expand Down
1 change: 1 addition & 0 deletions db/development.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE magma_chat_development;
1 change: 1 addition & 0 deletions db/production.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE magma_chat_production;
25 changes: 8 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ x-app: &default-app
db:
condition: service_healthy
env_file:
- .env
environment:
- RAILS_ENV=development
- DATABASE_URL=postgres://postgres:[email protected]:5432/magma_chat_development
- REDIS_URL=redis://host.docker.internal:6379/1
- MARQO_URL=https://marqo-ai.magmalabs.io/
- .env.local
tty: true
volumes:
- .:/rails
Expand All @@ -25,11 +20,7 @@ x-assets: &default-assets
context: "."
dockerfile: Dockerfile
env_file:
- .env
environment:
- RAILS_ENV=development
- DATABASE_URL=postgres://postgres:[email protected]:5432/magma_chat_development
- REDIS_URL=redis://host.docker.internal:6379/1
- .env.local
tty: true
volumes:
- .:/rails
Expand All @@ -44,9 +35,9 @@ services:
interval: 5s
timeout: 5s
retries: 5
command: redis-server
command: redis-server --requirepass password
ports:
- '6379:6379'
- '6380:6379'
volumes:
- 'redis-data:/data'
networks:
Expand All @@ -55,20 +46,20 @@ services:
db:
image: postgres:15
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: ["CMD-SHELL", "pg_isready -U rails"]
interval: 5s
timeout: 5s
retries: 5
ports:
- "5432:5432"
- "5433:5432"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_USER=rails
- POSTGRES_PASSWORD=password
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=magma_chat_development
volumes:
- 'pg-data:/var/lib/postgresql/data'
- './db/development.sql:/docker-entrypoint-initdb.d/setup.sql'
networks:
default:

Expand Down

0 comments on commit e7da6e8

Please sign in to comment.