Skip to content

Commit

Permalink
Merge pull request #10 from the-teacher/mailcatcher
Browse files Browse the repository at this point in the history
Add Mailcatcher
  • Loading branch information
the-teacher committed Jan 28, 2023
2 parents fd563c3 + fa8608b commit 2a3407e
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 16 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,26 @@ bin/setup
You will see something like that:

```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rails 7. StartKit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What was done:
1. Pull all required Images
2. Launching ElasticSearch Container
3. Launching PgSQL Container
4. Launching Redis Container
5. Launching Rails Container
6. Installing Gems. Please Wait
7. Create DB. Migrate DB. Create Seeds
8. Indexing Article Model
9. Launching Rails App with Puma
10. Launching Sidekiq
11. Visit: http://localhost:3000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3. Launching Mailcatcher Container
4. Launching PgSQL Container
5. Launching Redis Container
6. Launching Rails Container
7. Installing Gems. Please Wait
8. Create DB. Migrate DB. Create Seeds
9. Indexing Article Model
10. Launching Rails App with Puma
11. Launching Sidekiq
12. Visit Rails App: http://localhost:3000
13. Visit Mail Service: http://localhost:1080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Welcome to RAILS 7!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

<details>
Expand Down
13 changes: 13 additions & 0 deletions app/mailers/demo_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# rails generate mailer demo
#
# DemoMailer.welcome_email.deliver!
class DemoMailer < ApplicationMailer
default from: 'demo@rails7startkit.com'

def welcome_email
mail(
to: "test@test.com",
subject: 'Welcome to Rails 7. StartKit'
)
end
end
10 changes: 10 additions & 0 deletions app/views/demo_mailer/welcome_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to Rails7. StartKit</h1>
<p>Thanks for using this project!</p>
</body>
</html>
3 changes: 2 additions & 1 deletion bin/open
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CONTAINER_SHELL_MAP = {
rails: :bash,
psql: :bash,
redis: :ash,
elastic: :bash
elastic: :bash,
mailcatcher: :ash
}

unless CONTAINER_SHELL_MAP.key?(container_name)
Expand Down
10 changes: 8 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ FileUtils.chdir APP_ROOT do
# ElasticSearch
step_info "Launching ElasticSearch Container"
system('docker compose -f docker/docker-compose.yml up elastic -d')
wait('to launch ElasticSearch Container', 5)
wait('to launch ElasticSearch Container')

# Mailcatcher
step_info "Launching Mailcatcher Container"
system('docker compose -f docker/docker-compose.yml up mailcatcher -d')
wait('to launch Mailcatcher Container')

# PgSQL
FileUtils.rm('db/PGSQL/.keep', force: true)
Expand Down Expand Up @@ -50,7 +55,8 @@ FileUtils.chdir APP_ROOT do
step_info "Launching Sidekiq"
sidekiq_start

step_info "Visit: http://localhost:3000"
step_info "Visit Rails App: http://localhost:3000"
step_info "Visit Mail Service: http://localhost:1080"

containers_information

Expand Down
6 changes: 6 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "mailcatcher",
port: 1025
}

config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ services:
- ../log/ELASTIC:/usr/share/elasticsearch/logs
- ../shared:/shared

# port 1080
#
# mailcatcher does not start with ruby 3.2
mailcatcher:
image: schickling/mailcatcher
ports:
- 1080:1080

# port 3000
#
rails:
Expand Down
7 changes: 7 additions & 0 deletions test/mailers/demo_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class DemoMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/mailers/previews/demo_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Preview all emails at http://localhost:3000/rails/mailers/demo_mailer
class DemoMailerPreview < ActionMailer::Preview
# Accessible from http://localhost:3000/rails/mailers/demo_mailer/welcome_email
def welcome_email
DemoMailer.welcome_email
end
end

0 comments on commit 2a3407e

Please sign in to comment.