Skip to content

Commit

Permalink
changed Docker & domain mailgun & dns AWS thedownwinder
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrean committed Sep 20, 2020
1 parent ea037cf commit db1f61c
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 199 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN gem install rails bundler --no-document
# create folder called 'project' to host the codebase

RUN mkdir -p /api
# set the wroking directory to 'project' folder
# set the wroking directory to 'api' folder
WORKDIR /api
# copy from current directory '.' to the working directory './'
COPY Gemfile /api/Gemfile
Expand All @@ -19,6 +19,11 @@ COPY Gemfile.lock /api/Gemfile.lock
RUN bundle install --no-binstubs || bundle check
# Note: specific version can be set 'RUN gem install bundler -v 2.1.4'

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]

# node.js
#RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
# && apt install -y nodejs
Expand All @@ -28,7 +33,7 @@ RUN bundle install --no-binstubs || bundle check
#RUN yarn install --check-files

# copy the codebase into Docker
COPY . /api
COPY . .

EXPOSE 3001
# set the start command
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ gem 'bootsnap', '>= 1.4.2', require: false
gem 'rack-cors'

gem 'faker'#, :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
gem "oink"
# gem "oink"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
111 changes: 53 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.3.2)
actionpack (= 6.0.3.2)
actioncable (6.0.3.3)
actionpack (= 6.0.3.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.3.2)
actionpack (= 6.0.3.2)
activejob (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
actionmailbox (6.0.3.3)
actionpack (= 6.0.3.3)
activejob (= 6.0.3.3)
activerecord (= 6.0.3.3)
activestorage (= 6.0.3.3)
activesupport (= 6.0.3.3)
mail (>= 2.7.1)
actionmailer (6.0.3.2)
actionpack (= 6.0.3.2)
actionview (= 6.0.3.2)
activejob (= 6.0.3.2)
actionmailer (6.0.3.3)
actionpack (= 6.0.3.3)
actionview (= 6.0.3.3)
activejob (= 6.0.3.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.3.2)
actionview (= 6.0.3.2)
activesupport (= 6.0.3.2)
actionpack (6.0.3.3)
actionview (= 6.0.3.3)
activesupport (= 6.0.3.3)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.3.2)
actionpack (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
actiontext (6.0.3.3)
actionpack (= 6.0.3.3)
activerecord (= 6.0.3.3)
activestorage (= 6.0.3.3)
activesupport (= 6.0.3.3)
nokogiri (>= 1.8.5)
actionview (6.0.3.2)
activesupport (= 6.0.3.2)
actionview (6.0.3.3)
activesupport (= 6.0.3.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.3.2)
activesupport (= 6.0.3.2)
activejob (6.0.3.3)
activesupport (= 6.0.3.3)
globalid (>= 0.3.6)
activemodel (6.0.3.2)
activesupport (= 6.0.3.2)
activerecord (6.0.3.2)
activemodel (= 6.0.3.2)
activesupport (= 6.0.3.2)
activestorage (6.0.3.2)
actionpack (= 6.0.3.2)
activejob (= 6.0.3.2)
activerecord (= 6.0.3.2)
activemodel (6.0.3.3)
activesupport (= 6.0.3.3)
activerecord (6.0.3.3)
activemodel (= 6.0.3.3)
activesupport (= 6.0.3.3)
activestorage (6.0.3.3)
actionpack (= 6.0.3.3)
activejob (= 6.0.3.3)
activerecord (= 6.0.3.3)
marcel (~> 0.3.1)
activesupport (6.0.3.2)
activesupport (6.0.3.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand Down Expand Up @@ -81,13 +81,12 @@ GEM
dotenv (= 2.7.6)
railties (>= 3.2)
erubi (1.9.0)
faker (2.13.0)
faker (2.14.0)
i18n (>= 1.6, < 2)
ffi (1.13.1)
git-version-bump (0.17.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
hodel_3000_compliant_logger (0.1.1)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.8.5)
Expand Down Expand Up @@ -123,12 +122,9 @@ GEM
minitest (5.14.2)
msgpack (1.3.3)
netrc (0.11.0)
nio4r (2.5.3)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
oink (0.10.1)
activerecord
hodel_3000_compliant_logger
pg (1.2.3)
public_suffix (4.0.6)
puma (4.3.6)
Expand All @@ -142,29 +138,29 @@ GEM
rack (>= 2.0.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.3.2)
actioncable (= 6.0.3.2)
actionmailbox (= 6.0.3.2)
actionmailer (= 6.0.3.2)
actionpack (= 6.0.3.2)
actiontext (= 6.0.3.2)
actionview (= 6.0.3.2)
activejob (= 6.0.3.2)
activemodel (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
rails (6.0.3.3)
actioncable (= 6.0.3.3)
actionmailbox (= 6.0.3.3)
actionmailer (= 6.0.3.3)
actionpack (= 6.0.3.3)
actiontext (= 6.0.3.3)
actionview (= 6.0.3.3)
activejob (= 6.0.3.3)
activemodel (= 6.0.3.3)
activerecord (= 6.0.3.3)
activestorage (= 6.0.3.3)
activesupport (= 6.0.3.3)
bundler (>= 1.3.0)
railties (= 6.0.3.2)
railties (= 6.0.3.3)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.3.2)
actionpack (= 6.0.3.2)
activesupport (= 6.0.3.2)
railties (6.0.3.3)
actionpack (= 6.0.3.3)
activesupport (= 6.0.3.3)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
Expand All @@ -190,7 +186,7 @@ GEM
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand Down Expand Up @@ -223,7 +219,6 @@ DEPENDENCIES
letter_opener
listen (~> 3.2)
mailgun-ruby
oink
pg (>= 0.18, < 2.0)
puma (~> 4.1)
rack-brotli
Expand Down
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ ALTER TABLE "itinaries" ADD CONSTRAINT "fk_rails_events_itinaries" FOREIGN KEY (
ALTER TABLE "users" ADD CONSTRAINT "fk_rails_events_users" FOREIGN KEY ("id") REFERENCES "events" ("user_id");
```

# schema.rb

<https://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you>

```ruby
# /config/application.rb
config.active_record.schema_format :ruby
```

If set to `:sql` then the schema is in `db/structure.sql` and run:

```bash
rails db:schema:load
rails db:seed
```

# HTTP Caching w/Rails

`api:rails: ConditionalGet`
Expand Down Expand Up @@ -176,6 +192,16 @@ config.middleware.insert_before 0, Rack::Cors do
end
```
# Redis
```ruby
# .env
REDIS_URL='redis://localhost:6379'
#/config/initializers/sidekiq.rb
...config.redis = { url: ENV['REDIS_URL'], size: 2 }
```
# Procfile
> Dev localhost mode:
Expand All @@ -192,9 +218,16 @@ redis: redis-server --port 6379
```
api: bundle exec bin/rails server -p 3001
worker: bundle exec sidekiq -C ./config/sidekiq.yml
redis: redis-server --port 6379
```
- settings.config vars:
`REDIS_URL` will be set in 'setttings/config vars' after setting `REDIS_PROVIDER=REDISTOGO_URL` (free)
Set the keys `RAILS_MASTER_KEY` and `SECRET_KEY_BASE` (do `EDITOR="code ...wait" rails credentials:edit` to set)
The `DATABASE_URL` wil be set by Heroku.
# Compression
<https://pawelurbanek.com/rails-gzip-brotli-compression>
Expand All @@ -217,8 +250,27 @@ if params[:event][:itinary_attributes][:start_gps]
end
```
# Running multiple processes
Use `foreman`
The `database.yml` musn't use the key `db` (or set `localhost`)

# Docker

```bash
rm -rf tmp/*
docker rm $(docker ps -q -a) -f
docker rmi $(docker images -q) -f
docker-compose up --build
```

Set the key `host: db` in `database.yml` where `db` is the name of the Postgresql service in `docker-compose.yml`.

```ruby
```

<https://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-with-docker-compose>

Needs in `.env`:
Expand All @@ -237,3 +289,34 @@ POTGRES_PASSWORD=postgres
# .env
REDIS_URL='redis://localhost:6379'
```
Set for Postgres:
```
# .env
# Postgres Docker
POSTGRES_DB=godwd_development
POSTGRES_USER=postgres
POTGRES_PASSWORD=postgres
```
- create the database
```bash
docker-compose exec web rails db:create
docker-compse exec web rails db:schema:load # instead of db:migrate
docker-compose exec web rails db:seed
```

## docker commands

- list all containers: `docker container ls -a`

- list all containers's ids: `docker container ls -aq`

- stop all containers by passing a list of ids: `docker container stop $(docker container ls -aq)`

- remove all containers by passing a list of ids: `docker container rm $(docker container ls -aq)`

- To wipe Docker clean and start from scratch, enter the command:
`docker container stop $(docker container ls –aq) && docker system prune –af ––volumes`
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
#require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
# require "sprockets/railtie"
Expand All @@ -29,6 +29,7 @@ class Application < Rails::Application
config.middleware.use Rack::Deflater
config.middleware.use Rack::Brotli

config.active_record.schema_format :ruby
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
Loading

0 comments on commit db1f61c

Please sign in to comment.