Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 256e3ad

Browse files
danhunsakerGargron
authored andcommitted
Add Support for Nanobox (mastodon#1709)
* Nanobox Support - Added support for running Mastodon using Nanobox, both for local development, and for deployment to production - Dev mode tested and is working properly - Deployment is undergoing test as of this writing. If it works, this line will be amended to state success; if not, one or more subsequent commits will provide fixes. * [nanobox] Resolve Deploy Issues Everything seems to work except routing to the streaming API. Will investigate with the Nanobox staff and make fix commits if needed. Changes made: - Also need `NODE_ENV` in production - Node runs on `:4000` - Use `envsubst` to commit `.env.production` values, since `dotEnv` packages don't always support referencing other variables - Can't precompile assets after `transform` hook, but do this locally so it only has to be done once. - Rails won't create `production.log` on its own, so we do this ourselves. - Some `start` commands run from `/data/` for some reason, so use absolute paths in command arguments * [nanobox] Update Ruby version * [nanobox] Fix db.rake Ruby code style issues * [nanobox] Minor Fixes Some minor adjustments to improve functionality: - Fixed routing to `web.stream` instances - Adjust `.env.nanobox` to properly generate a default `SMTP_FROM_ADDRESS` via `envsubst` - Update Nginx configs to properly support the needed HTTP version and headers for proper functionality (the streaming API doesn't work without some of these settings in place) * [nanobox] Move usage info to docs repo * [nanobox] Updates for 1.2.x - Need to leave out `pkg-config` since Nanobox deploys without Ruby's headers - create a gem group to exclude the gem during Nanobox installs, but allow it to remain part of the default set otherwise - Update cron jobs to cover new/updated Rake tasks - Update `.env.nanobox` to include latest defaults and additions * [nanobox] Fix for nokogumbo, added in 1.3.x Apparently, nokogumbo (pulled in by sanitize, added with `OEmbed Support for PreviewCard` (mastodon#2337) - 88725d6) tries to install before nokogiri, despite needing nokogiri available to build properly. Instruct it to use the same settings as nokogiri does when building nokogiri directly, instead of via bundler. * [nanobox] Set NODE_ENV during asset compile The switch to WebPack will rely on the local value of the NODE_ENV evar, so set it to production during asset compilation. * [nanobox] Rebase on master; update Nginx configs - `pkg-config` Gem no longer causes issues in Nanobox, so revert the Gemfile change which allowed excluding it - Update Nginx configuration files with latest recommendations from production documentation - Rebase on master to Get This Merged™ Everything should be golden!
1 parent 152b4d5 commit 256e3ad

7 files changed

+501
-0
lines changed

.env.nanobox

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Service dependencies
2+
# You may set REDIS_URL instead for more advanced options
3+
REDIS_HOST=$DATA_REDIS_HOST
4+
REDIS_PORT=6379
5+
# REDIS_DB=0
6+
7+
# You may set DATABASE_URL instead for more advanced options
8+
DB_HOST=$DATA_DB_HOST
9+
DB_USER=$DATA_DB_USER
10+
DB_NAME=gonano
11+
DB_PASS=$DATA_DB_PASS
12+
DB_PORT=5432
13+
14+
# Federation
15+
# Note: Changing LOCAL_DOMAIN or LOCAL_HTTPS at a later time will cause unwanted side effects.
16+
# LOCAL_DOMAIN should *NOT* contain the protocol part of the domain e.g https://example.com.
17+
LOCAL_DOMAIN=${APP_NAME}.nanoapp.io
18+
LOCAL_HTTPS=false
19+
20+
# Use this only if you need to run mastodon on a different domain than the one used for federation.
21+
# You can read more about this option on https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Serving_a_different_domain.md
22+
# DO *NOT* USE THIS UNLESS YOU KNOW *EXACTLY* WHAT YOU ARE DOING.
23+
# WEB_DOMAIN=mastodon.example.com
24+
25+
# Use this if you want to have several aliases [email protected]
26+
# [email protected] etc. for the same user. LOCAL_DOMAIN should not
27+
# be added. Comma separated values
28+
# ALTERNATE_DOMAINS=example1.com,example2.com
29+
30+
# Application secrets
31+
# Generate each with the `rake secret` task (`nanobox run bundle exec rake secret`)
32+
PAPERCLIP_SECRET=$PAPERCLIP_SECRET
33+
SECRET_KEY_BASE=$SECRET_KEY_BASE
34+
OTP_SECRET=$OTP_SECRET
35+
36+
# Registrations
37+
# Single user mode will disable registrations and redirect frontpage to the first profile
38+
# SINGLE_USER_MODE=true
39+
# Prevent registrations with following e-mail domains
40+
# EMAIL_DOMAIN_BLACKLIST=example1.com|example2.de|etc
41+
# Only allow registrations with the following e-mail domains
42+
# EMAIL_DOMAIN_WHITELIST=example1.com|example2.de|etc
43+
44+
# Optionally change default language
45+
# DEFAULT_LOCALE=de
46+
47+
# E-mail configuration
48+
# Note: Mailgun and SparkPost (https://sparkpo.st/smtp) each have good free tiers
49+
# If you want to use an SMTP server without authentication (e.g local Postfix relay)
50+
# then set SMTP_AUTH_METHOD and SMTP_OPENSSL_VERIFY_MODE to 'none' and
51+
# *comment* SMTP_LOGIN and SMTP_PASSWORD (leaving them blank is not enough).
52+
SMTP_SERVER=$SMTP_SERVER
53+
SMTP_PORT=587
54+
SMTP_LOGIN=$SMTP_LOGIN
55+
SMTP_PASSWORD=$SMTP_PASSWORD
56+
SMTP_FROM_ADDRESS=notifications@${APP_NAME}.nanoapp.io
57+
#SMTP_DOMAIN= # defaults to LOCAL_DOMAIN
58+
#SMTP_DELIVERY_METHOD=smtp # delivery method can also be sendmail
59+
#SMTP_AUTH_METHOD=plain
60+
#SMTP_CA_FILE=/etc/ssl/certs/ca-certificates.crt
61+
#SMTP_OPENSSL_VERIFY_MODE=peer
62+
#SMTP_ENABLE_STARTTLS_AUTO=true
63+
64+
65+
# Optional user upload path and URL (images, avatars). Default is :rails_root/public/system. If you set this variable, you are responsible for making your HTTP server (eg. nginx) serve these files.
66+
# PAPERCLIP_ROOT_PATH=/var/lib/mastodon/public-system
67+
# PAPERCLIP_ROOT_URL=/system
68+
69+
# Optional asset host for multi-server setups
70+
# CDN_HOST=assets.example.com
71+
72+
# S3 (optional)
73+
# S3_ENABLED=true
74+
# S3_BUCKET=
75+
# AWS_ACCESS_KEY_ID=
76+
# AWS_SECRET_ACCESS_KEY=
77+
# S3_REGION=
78+
# S3_PROTOCOL=http
79+
# S3_HOSTNAME=192.168.1.123:9000
80+
81+
# S3 (Minio Config (optional) Please check Minio instance for details)
82+
# S3_ENABLED=true
83+
# S3_BUCKET=
84+
# AWS_ACCESS_KEY_ID=
85+
# AWS_SECRET_ACCESS_KEY=
86+
# S3_REGION=
87+
# S3_PROTOCOL=https
88+
# S3_HOSTNAME=
89+
# S3_ENDPOINT=
90+
# S3_SIGNATURE_VERSION=
91+
92+
# Optional alias for S3 if you want to use Cloudfront or Cloudflare in front
93+
# S3_CLOUDFRONT_HOST=
94+
95+
# Streaming API integration
96+
# STREAMING_API_BASE_URL=
97+
98+
# Advanced settings
99+
# If you need to use pgBouncer, you need to disable prepared statements:
100+
# PREPARED_STATEMENTS=false
101+
102+
# Cluster number setting for streaming API server.
103+
# If you comment out following line, cluster number will be `numOfCpuCores - 1`.
104+
STREAMING_CLUSTER_NUM=1
105+
106+
# Docker mastodon user
107+
# If you use Docker, you may want to assign UID/GID manually.
108+
# UID=1000
109+
# GID=1000

.nanoignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
.git/
3+
.gitignore
4+
5+
.bundle/
6+
.cache/
7+
config/deploy/*
8+
coverage
9+
docs/
10+
.env
11+
log/*.log
12+
neo4j/
13+
node_modules/
14+
public/assets/
15+
public/system/
16+
spec/
17+
storybook/
18+
tmp/
19+
.vagrant/
20+
vendor/bundle/

boxfile.yml

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
run.config:
2+
engine: ruby
3+
engine.config:
4+
runtime: ruby-2.4.1
5+
6+
extra_packages:
7+
# basic servers:
8+
- nginx
9+
- nodejs
10+
11+
# for images:
12+
- ImageMagick
13+
14+
# for videos:
15+
- ffmpeg3
16+
17+
# to prep the .env file
18+
- gettext-tools
19+
20+
cache_dirs:
21+
- node_modules
22+
23+
extra_path_dirs:
24+
- node_modules/.bin
25+
26+
build_triggers:
27+
- .ruby-version
28+
- Gemfile
29+
- Gemfile.lock
30+
- package.json
31+
- yarn.lock
32+
33+
extra_steps:
34+
- cp .env.nanobox .env
35+
- gem install bundler
36+
- bundle config build.nokogiri --with-iconv-dir=/data/ --with-zlib-dir=/data/
37+
- bundle config build.nokogumbo --with-iconv-dir=/data/ --with-zlib-dir=/data/
38+
- bundle install --clean
39+
- yarn
40+
41+
fs_watch: true
42+
43+
deploy.config:
44+
extra_steps:
45+
- NODE_ENV=production bundle exec rake assets:precompile
46+
- "[ -r /app/.env.production ] || sed 's/LOCAL_HTTPS=.*/LOCAL_HTTPS=true/i' /app/.env.nanobox > /app/.env.production"
47+
transform:
48+
- envsubst < /app/.env.production > /tmp/.env.production && mv /tmp/.env.production /app/.env.production
49+
- |-
50+
if [ -z "$LOCAL_DOMAIN" ]
51+
then
52+
. /app/.env.production
53+
export LOCAL_DOMAIN
54+
fi
55+
erb /app/nanobox/nginx-web.conf.erb > /app/nanobox/nginx-web.conf
56+
erb /app/nanobox/nginx-stream.conf.erb > /app/nanobox/nginx-stream.conf
57+
- touch /app/log/production.log
58+
before_live:
59+
web.web:
60+
- bundle exec rake db:migrate:setup
61+
62+
web.web:
63+
start:
64+
nginx: nginx -c /app/nanobox/nginx-web.conf
65+
rails: bundle exec puma -C /app/config/puma.rb
66+
67+
routes:
68+
- '/'
69+
70+
writable_dirs:
71+
- tmp
72+
73+
log_watch:
74+
rails: 'log/production.log'
75+
76+
network_dirs:
77+
data.storage:
78+
- public/system
79+
80+
web.stream:
81+
start:
82+
nginx: nginx -c /app/nanobox/nginx-stream.conf
83+
node: yarn run start
84+
85+
routes:
86+
- '/api/v1/streaming*'
87+
# Somehow we're getting requests for scheme://domain//api/v1/streaming* - match those, too
88+
- '//api/v1/streaming*'
89+
90+
writable_dirs:
91+
- tmp
92+
93+
worker.sidekiq:
94+
start: bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push -L /app/log/sidekiq.log
95+
96+
writable_dirs:
97+
- tmp
98+
99+
log_watch:
100+
rails: 'log/production.log'
101+
sidekiq: 'log/sidekiq.log'
102+
103+
network_dirs:
104+
data.storage:
105+
- public/system
106+
107+
cron:
108+
- id: generate_static_gifs
109+
schedule: '*/15 * * * *'
110+
command: 'bundle exec rake mastodon:maintenance:add_static_avatars'
111+
112+
- id: update_counter_caches
113+
schedule: '50 * * * *'
114+
command: 'bundle exec rake mastodon:maintenance:update_counter_caches'
115+
116+
# runs feeds:clear, media:clear, users:clear, and push:refresh
117+
- id: do_daily_tasks
118+
schedule: '00 00 * * *'
119+
command: 'bundle exec rake mastodon:daily'
120+
121+
- id: clear_silenced_media
122+
schedule: '10 00 * * *'
123+
command: 'bundle exec rake mastodon:media:remove_silenced'
124+
125+
- id: clear_remote_media
126+
schedule: '20 00 * * *'
127+
command: 'bundle exec rake mastodon:media:remove_remote'
128+
129+
- id: clear_unfollowed_subs
130+
schedule: '30 00 * * *'
131+
command: 'bundle exec rake mastodon:push:clear'
132+
133+
- id: send_digest_emails
134+
schedule: '00 20 * * *'
135+
command: 'bundle exec rake mastodon:emails:digest'
136+
137+
# The following two tasks can be uncommented to automatically open and close
138+
# registrations on a schedule. The format of 'schedule' is a standard cron
139+
# time expression: minute hour day month day-of-week; search for "cron
140+
# time expressions" for more info on how to set these up. The examples here
141+
# open registration only from 8 am to 4 pm, server time.
142+
#
143+
# - id: open_registrations
144+
# schedule: '00 08 * * *'
145+
# command: 'bundle exec rake mastodon:settings:open_registrations'
146+
#
147+
# - id: close_registrations
148+
# schedule: '00 16 * * *'
149+
# command: 'bundle exec rake mastodon:settings:close_registrations'
150+
151+
data.db:
152+
image: nanobox/postgresql:9.5
153+
154+
data.redis:
155+
image: nanobox/redis:3.0
156+
157+
data.storage:
158+
image: nanobox/unfs:0.9

lib/tasks/db.rake

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
namespace :db do
4+
namespace :migrate do
5+
desc 'Setup the db or migrate depending on state of db'
6+
task setup: :environment do
7+
begin
8+
ActiveRecord::Base.connection
9+
rescue ActiveRecord::NoDatabaseError
10+
Rake::Task['db:setup'].invoke
11+
else
12+
Rake::Task['db:migrate'].invoke
13+
end
14+
end
15+
end
16+
end

nanobox/nginx-local.conf

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
worker_processes 1;
2+
daemon off;
3+
4+
events {
5+
worker_connections 1024;
6+
}
7+
8+
http {
9+
include /data/etc/nginx/mime.types;
10+
sendfile on;
11+
12+
gzip on;
13+
gzip_http_version 1.0;
14+
gzip_proxied any;
15+
gzip_min_length 500;
16+
gzip_disable "MSIE [1-6]\.";
17+
gzip_types text/plain text/xml text/javascript text/css text/comma-separated-values application/xml+rss application/xml application/x-javascript application/json application/javascript application/atom+xml;
18+
19+
# Proxy upstream to the puma process
20+
upstream rails {
21+
server 127.0.0.1:3000;
22+
}
23+
24+
# Proxy upstream to the node process
25+
upstream node {
26+
server 127.0.0.1:4000;
27+
}
28+
29+
map $http_upgrade $connection_upgrade {
30+
default upgrade;
31+
'' close;
32+
}
33+
34+
# Configuration for Nginx
35+
server {
36+
# Listen on port 8080
37+
listen 8080;
38+
39+
root /app/public;
40+
41+
location / {
42+
try_files $uri @rails;
43+
}
44+
45+
# Proxy connections to rails
46+
location @rails {
47+
proxy_set_header Host $host;
48+
proxy_pass_header Server;
49+
50+
proxy_pass http://rails;
51+
proxy_buffering off;
52+
proxy_redirect off;
53+
proxy_http_version 1.1;
54+
proxy_set_header Upgrade $http_upgrade;
55+
proxy_set_header Connection $connection_upgrade;
56+
57+
tcp_nodelay on;
58+
}
59+
60+
# Proxy connections to node
61+
location /api/v1/streaming {
62+
proxy_set_header Host $host;
63+
64+
proxy_pass http://node;
65+
proxy_buffering off;
66+
proxy_redirect off;
67+
proxy_http_version 1.1;
68+
proxy_set_header Upgrade $http_upgrade;
69+
proxy_set_header Connection $connection_upgrade;
70+
71+
tcp_nodelay on;
72+
}
73+
}
74+
75+
error_page 500 501 502 503 504 /500.html;
76+
}

0 commit comments

Comments
 (0)