Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Klaxon Instance Variable Name to Home Page & Change Mailer (Issue#70 and Issue#373) #552

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
# Running Klaxon with Docker

## Development Quickstart
## Developing Klaxon using Docker

This assumes you already have Docker installed on your system. If you haven't done that yet, visit https://docs.docker.com/get-docker/

1. Run the following commands:

```
docker-compose up
open http://localhost:3000
mkdir .docker_data
docker compose -f docker-compose.yml -f docker-compose-dev.yml up
```

2. Enter 'admin@news.org' in the email window. It should redirect you to a page that says: "Email Sent".
The first time you do this may take a while as Docker downloads files and builds the container.

2. In a browser, open http://localhost:3000

3. Enter 'admin@news.org' in the email field. It should redirect you to a page that says: "Email Sent".

4. In the console find where it says "Go to Dashboard ( ... )" and copy and paste the link into the browser.

5. You'll now be logged in. The page should say "Watch Your First Item".

## Deploying Klaxon using Docker

3. In the console find where it says "Go to Dashboard ( ... )" and copy and paste the link into the browser.
TK: explain deployment methods, including elaborating environment variables below.

4. You'll now be logged in. The page should say "Watch Your First Item".
### Expected environment variables

## Expected environmental variables
Klaxon needs certain environment variables to be able to run. For development (see above), these are defined in files in this repository, but for production, the environment variable values are often things which should not be in version control, so if you're deploying using Docker, you'll need to make sure these are set correctly.

Klaxon needs certain environmental variables to be able to run. One way to accomplish this in Docker is with an [env file](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables-e-env-env-file). Below is a template for setting one up.
One way to accomplish this in Docker is with an [env file](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables-e-env-env-file). Below is a template for setting one up.

```sh
DATABASE_URL=
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

skip_before_action :verify_authenticity_token
helper_method :authorize
def authorize
unless current_user.present?
Expand Down
8 changes: 6 additions & 2 deletions app/mailers/change_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ def page(user: nil, change: nil)
@change = change
@page = @change.after.page
@user = user

mail(to: @user.email, subject: "#{@page.name} changed")
if ENV['KLAXON_INSTANCE_NAME'].present?
@instanceid = "Klaxon @ #{ENV['KLAXON_INSTANCE_NAME']}"
else
@instanceid = "Klaxon"
end
mail(to: @user.email, subject: "#{@instanceid}: #{@page.name} changed"
end
end
8 changes: 6 additions & 2 deletions app/views/change_mailer/page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@

<div class="container">
<div class="klax-app-name">
Klaxon
<% if ENV['KLAXON_INSTANCE_NAME'].present? -%>
<b> Klaxon @ <%= ENV['KLAXON_INSTANCE_NAME'] %></b>
<% else -%>
<b>Klaxon</b>
<% end -%></a>
</div>
<h3>Something Changed</h3>
<h3>Something Changed @ <%= ENV['KLAXON_INSTANCE_NAME'] %></h3>

<p class="klax-lead"><b><%= @page.name %></b> changed. It has changed <b><%= @page.num_changes %></b> times since Klaxon started monitoring it on <b><%= @page.created_at.strftime("%A, %B %d, %Y") %>.</b></p>

Expand Down
7 changes: 6 additions & 1 deletion app/views/layouts/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
</button>
<a class="navbar-brand" href="/">
<svg style="padding-top: 2px;" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="23px" height="20px" viewBox="0 0 100 86.9" enable-background="new 0 0 100 86.9" xml:space="preserve"><g><path id="logo-no-fill" fill="none" d="M38.5,33.7c-2.6-12.6-1.8-19.5-1.8-19.5S23.8,54.4,54.3,76.7c-3.1-6-5.6-11.7-7.7-16.9c5.4-2.3,8-9.3,5.7-16.2C50.1,36.9,44.1,32.7,38.5,33.7z"/><polygon fill="none" points="79.3,39.2 79.3,39.2 79.3,39.2 "/><path fill="#FF0B3A" d="M33.2,5.9c-20,34.4-10.7,30.4-21.6,34.2C8.4,41.2,4,43.6,2,46.3C-3,53,1.2,71,15.1,71.7c21,1,4.2-2,35.9,13C94.6,105.4,53.7-29.4,33.2,5.9z M46.5,59.8c2.1,5.3,4.6,10.9,7.7,16.9C23.8,54.4,36.7,14.2,36.7,14.2s-0.8,6.9,1.8,19.5c5.6-1,11.6,3.2,13.8,9.9C54.5,50.5,51.9,57.5,46.5,59.8z"/><path fill="#FF0B3A" d="M78.7,11.2l-1.9-1.1c-1.1-0.7-2.7-0.3-3.4,0.9l-4.6,7.7c-0.7,1.2-0.3,2.7,0.9,3.4l1.9,1.1c0.4,0.2,0.8,0.4,1.3,0.4c0.9,0,1.7-0.5,2.1-1.2l4.6-7.7C80.2,13.4,79.8,11.9,78.7,11.2z"/><path fill="#FF0B3A" d="M99.8,33.6l-0.5-2.1c-0.2-0.8-1-1.7-2.6-1.7c-0.4,0-0.9,0.1-1.3,0.2L78.9,34c-0.7,0.2-1.9,0.6-2.5,1.6L76,36.5l0.7,2.9c0.1,0.4,0.6,1.7,2.6,1.7c0.4,0,0.9-0.1,1.3-0.2L97,36.8C99.5,36.2,100.1,34.7,99.8,33.6z M79.3,39.2L79.3,39.2L79.3,39.2L79.3,39.2z"/><path fill="#FF0B3A" d="M90.5,58.4l-7.7-4.7c-1.1-0.7-2.7-0.3-3.4,0.8l-1.1,1.9c-0.7,1.2-0.3,2.7,0.9,3.4l7.7,4.7c0.4,0.2,0.8,0.4,1.3,0.4c0.9,0,1.7-0.5,2.1-1.2l1.1-1.9c0.3-0.6,0.4-1.2,0.3-1.9C91.4,59.3,91,58.8,90.5,58.4z"/></g></svg>
<b>Klaxon</b></a>
<% if ENV['KLAXON_INSTANCE_NAME'].present? -%>
<b> Klaxon @ <%= ENV['KLAXON_INSTANCE_NAME'] %></b>
<% else -%>
<b>Klaxon</b>
<% end -%></a>

</div>
<div id="navbar" class="collapse navbar-collapse pull-right">
<ul class="nav navbar-nav navbar-right">
Expand Down
10 changes: 5 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

Expand Down
28 changes: 28 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ruby:2.7.2

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY Gemfile /usr/src/app/
COPY Gemfile.lock /usr/src/app/
RUN bundle install

COPY . /usr/src/app

EXPOSE 3000

# install s6overlay so that we can run cron inside this container as well.
ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / \
&& mkdir /config \
&& apt-get update \
&& apt-get install -y cron \
&& rm -rf /var/lib/apt/lists/*

COPY rootfs/ /
VOLUME ["/config"]

ENTRYPOINT ["/init"]
25 changes: 25 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '2.2'

services:
database:
environment:
POSTGRES_PASSWORD: PASSWORD
POSTGRES_DB: klaxon
POSTGRES_USER: postgres
volumes:
- ./.docker_data:/var/lib/postgresql

app:
ports: ["3000:3000"]
environment:
RACK_ENV: "development"
RAILS_ENV: "development"
DATABASE_URL: "postgres://postgres:PASSWORD@database/klaxon"
SECRET_KEY_BASE: "secret_key_base"
ADMIN_EMAILS: "admin@news.org"
KLAXON_INSTANCE_NAME: "Alex's News Room"
build:
context: .
dockerfile: dev.Dockerfile
volumes:
- .:/usr/src/app
11 changes: 0 additions & 11 deletions docker-compose.override.yml

This file was deleted.

33 changes: 0 additions & 33 deletions docker_example/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions docker_example/docker-compose.yml

This file was deleted.

25 changes: 0 additions & 25 deletions docker_example/env_local.list

This file was deleted.

6 changes: 6 additions & 0 deletions spec/mailers/previews/change_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Preview all emails at http://localhost:3000/rails/mailers/change_mailer
class ChangeMailerPreview < ActionMailer::Preview
def change_email
ChangeMailer.with(user: User.first, change: Change.first).page
end
end