From 256e3adc1d9508423aab8fcfb13745c9f85ff948 Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Tue, 23 May 2017 08:54:44 -0600 Subject: Add Support for Nanobox (#1709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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` (#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! --- boxfile.yml | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 boxfile.yml (limited to 'boxfile.yml') diff --git a/boxfile.yml b/boxfile.yml new file mode 100644 index 000000000..65f5f6c8c --- /dev/null +++ b/boxfile.yml @@ -0,0 +1,158 @@ +run.config: + engine: ruby + engine.config: + runtime: ruby-2.4.1 + + extra_packages: + # basic servers: + - nginx + - nodejs + + # for images: + - ImageMagick + + # for videos: + - ffmpeg3 + + # to prep the .env file + - gettext-tools + + cache_dirs: + - node_modules + + extra_path_dirs: + - node_modules/.bin + + build_triggers: + - .ruby-version + - Gemfile + - Gemfile.lock + - package.json + - yarn.lock + + extra_steps: + - cp .env.nanobox .env + - gem install bundler + - bundle config build.nokogiri --with-iconv-dir=/data/ --with-zlib-dir=/data/ + - bundle config build.nokogumbo --with-iconv-dir=/data/ --with-zlib-dir=/data/ + - bundle install --clean + - yarn + + fs_watch: true + +deploy.config: + extra_steps: + - NODE_ENV=production bundle exec rake assets:precompile + - "[ -r /app/.env.production ] || sed 's/LOCAL_HTTPS=.*/LOCAL_HTTPS=true/i' /app/.env.nanobox > /app/.env.production" + transform: + - envsubst < /app/.env.production > /tmp/.env.production && mv /tmp/.env.production /app/.env.production + - |- + if [ -z "$LOCAL_DOMAIN" ] + then + . /app/.env.production + export LOCAL_DOMAIN + fi + erb /app/nanobox/nginx-web.conf.erb > /app/nanobox/nginx-web.conf + erb /app/nanobox/nginx-stream.conf.erb > /app/nanobox/nginx-stream.conf + - touch /app/log/production.log + before_live: + web.web: + - bundle exec rake db:migrate:setup + +web.web: + start: + nginx: nginx -c /app/nanobox/nginx-web.conf + rails: bundle exec puma -C /app/config/puma.rb + + routes: + - '/' + + writable_dirs: + - tmp + + log_watch: + rails: 'log/production.log' + + network_dirs: + data.storage: + - public/system + +web.stream: + start: + nginx: nginx -c /app/nanobox/nginx-stream.conf + node: yarn run start + + routes: + - '/api/v1/streaming*' + # Somehow we're getting requests for scheme://domain//api/v1/streaming* - match those, too + - '//api/v1/streaming*' + + writable_dirs: + - tmp + +worker.sidekiq: + start: bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push -L /app/log/sidekiq.log + + writable_dirs: + - tmp + + log_watch: + rails: 'log/production.log' + sidekiq: 'log/sidekiq.log' + + network_dirs: + data.storage: + - public/system + + cron: + - id: generate_static_gifs + schedule: '*/15 * * * *' + command: 'bundle exec rake mastodon:maintenance:add_static_avatars' + + - id: update_counter_caches + schedule: '50 * * * *' + command: 'bundle exec rake mastodon:maintenance:update_counter_caches' + + # runs feeds:clear, media:clear, users:clear, and push:refresh + - id: do_daily_tasks + schedule: '00 00 * * *' + command: 'bundle exec rake mastodon:daily' + + - id: clear_silenced_media + schedule: '10 00 * * *' + command: 'bundle exec rake mastodon:media:remove_silenced' + + - id: clear_remote_media + schedule: '20 00 * * *' + command: 'bundle exec rake mastodon:media:remove_remote' + + - id: clear_unfollowed_subs + schedule: '30 00 * * *' + command: 'bundle exec rake mastodon:push:clear' + + - id: send_digest_emails + schedule: '00 20 * * *' + command: 'bundle exec rake mastodon:emails:digest' + + # The following two tasks can be uncommented to automatically open and close + # registrations on a schedule. The format of 'schedule' is a standard cron + # time expression: minute hour day month day-of-week; search for "cron + # time expressions" for more info on how to set these up. The examples here + # open registration only from 8 am to 4 pm, server time. + # + # - id: open_registrations + # schedule: '00 08 * * *' + # command: 'bundle exec rake mastodon:settings:open_registrations' + # + # - id: close_registrations + # schedule: '00 16 * * *' + # command: 'bundle exec rake mastodon:settings:close_registrations' + +data.db: + image: nanobox/postgresql:9.5 + +data.redis: + image: nanobox/redis:3.0 + +data.storage: + image: nanobox/unfs:0.9 -- cgit