├── .gitignore ├── .luacheckrc ├── Dockerfile ├── Dockerfile.ingest ├── LICENSE ├── Makefile ├── README.md ├── admin ├── .gitignore ├── .rspec ├── .ruby-version ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── Makefile ├── README.md ├── Rakefile ├── app │ ├── admin │ │ ├── admin_users.rb │ │ ├── computing_units.rb │ │ └── dashboard.rb │ ├── assets │ │ ├── config │ │ │ └── manifest.js │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ ├── active_admin.js │ │ │ ├── application.js │ │ │ ├── cable.js │ │ │ └── channels │ │ │ │ └── .keep │ │ └── stylesheets │ │ │ ├── active_admin.scss │ │ │ └── application.css │ ├── channels │ │ └── application_cable │ │ │ ├── channel.rb │ │ │ └── connection.rb │ ├── controllers │ │ ├── application_controller.rb │ │ └── concerns │ │ │ └── .keep │ ├── helpers │ │ └── application_helper.rb │ ├── jobs │ │ └── application_job.rb │ ├── mailers │ │ └── application_mailer.rb │ ├── models │ │ ├── admin_user.rb │ │ ├── application_record.rb │ │ ├── computing_unit.rb │ │ └── concerns │ │ │ └── .keep │ └── views │ │ ├── layouts │ │ ├── application.html.erb │ │ ├── mailer.html.erb │ │ └── mailer.text.erb │ │ └── summary │ │ └── show.html.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ ├── setup │ ├── spring │ ├── update │ └── yarn ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── cable.yml │ ├── credentials.yml.enc │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── active_admin.rb │ │ ├── activeadmin_addons.rb │ │ ├── application_controller_renderer.rb │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── content_security_policy.rb │ │ ├── cookies_serializer.rb │ │ ├── devise.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ ├── devise.en.yml │ │ └── en.yml │ ├── puma.rb │ ├── routes.rb │ ├── spring.rb │ └── storage.yml ├── db │ ├── migrate │ │ ├── 20200723130114_devise_create_admin_users.rb │ │ ├── 20200723130119_create_active_admin_comments.rb │ │ └── 20210513192719_create_computing_units.rb │ ├── schema.rb │ └── seeds.rb ├── docker-compose.yml ├── entrypoint.sh ├── lib │ ├── assets │ │ └── .keep │ └── tasks │ │ └── .keep ├── log │ └── .keep ├── package.json ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ ├── apple-touch-icon-precomposed.png │ ├── apple-touch-icon.png │ ├── favicon.ico │ └── robots.txt ├── scripts │ └── wait-for.sh ├── spec │ ├── models │ │ └── computing_unit_spec.rb │ ├── rails_helper.rb │ └── spec_helper.rb ├── storage │ └── .keep ├── tmp │ └── .keep └── vendor │ └── .keep ├── cms.jpg ├── docker-compose.yml ├── edge.conf ├── ffmpeg_colorbar.sh ├── ingest.conf ├── mysqldata └── .gitkeep └── src └── resty-edge-computing.lua /.gitignore: -------------------------------------------------------------------------------- 1 | luacov.stats.out 2 | mysqldata/* 3 | !mysqldata/.gitkeep 4 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | std="ngx_lua+busted" 2 | globals={"update_cu"} 3 | max_line_length=120 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openresty/openresty:xenial 2 | 3 | RUN apt-get update \ 4 | && apt-get install -y \ 5 | git \ 6 | && mkdir /src \ 7 | && cd /src \ 8 | && git config --global url."https://".insteadOf git:// \ 9 | && luarocks install lua-resty-http 10 | -------------------------------------------------------------------------------- /Dockerfile.ingest: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | 3 | ENV DEBIAN_FRONTEND noninteractive 4 | ENV PATH $PATH:/usr/local/nginx/sbin 5 | 6 | EXPOSE 1935 7 | EXPOSE 80 8 | 9 | # create directories 10 | RUN mkdir /src /config /logs /data /static 11 | 12 | # update and upgrade packages 13 | RUN apt-get update && \ 14 | apt-get upgrade -y && \ 15 | apt-get clean && \ 16 | apt-get install -y --no-install-recommends build-essential \ 17 | wget software-properties-common && \ 18 | # ffmpeg 19 | add-apt-repository ppa:mc3man/trusty-media && \ 20 | apt-get update && \ 21 | apt-get install -y --no-install-recommends ffmpeg && \ 22 | # nginx dependencies 23 | apt-get install -y --no-install-recommends libpcre3-dev \ 24 | zlib1g-dev libssl-dev wget && \ 25 | rm -rf /var/lib/apt/lists/* 26 | 27 | # get nginx source 28 | WORKDIR /src 29 | RUN wget http://nginx.org/download/nginx-1.16.1.tar.gz && \ 30 | tar zxf nginx-1.16.1.tar.gz && \ 31 | rm nginx-1.16.1.tar.gz && \ 32 | # geting a fork of nginx-rtmp module 33 | wget https://github.com/ut0mt8/nginx-rtmp-module/archive/v1.2.0.tar.gz && \ 34 | tar zxf v1.2.0.tar.gz && \ 35 | rm v1.2.0.tar.gz 36 | 37 | # compile nginx 38 | WORKDIR /src/nginx-1.16.1 39 | RUN ./configure --add-module=/src/nginx-rtmp-module-1.2.0 \ 40 | --conf-path=/config/nginx.conf \ 41 | --error-log-path=/logs/error.log \ 42 | --http-log-path=/logs/access.log && \ 43 | make && \ 44 | make install 45 | 46 | WORKDIR / 47 | CMD "nginx" 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, Leandro Moreira 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: down run broadcast_tvshow 2 | 3 | down: 4 | docker-compose down -v 5 | 6 | run: down 7 | docker-compose run --rm --service-ports edge 8 | 9 | lint: 10 | docker-compose run --rm lint 11 | 12 | broadcast_tvshow: 13 | docker-compose run --rm origin 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **Warning** 2 | > There's a more robust and complete solution available called [lua-resty-dynacode](https://github.com/leandromoreira/lua-resty-dynacode#quick-start) 3 | 4 | # Edge computing resty 5 | 6 | During our hackday, we created a simple edge computing platform using nginx, lua and rails. The ideas is to inject lua code into a running nginx through a CMS. 7 | 8 | ## Demo 9 | 10 | https://user-images.githubusercontent.com/55913/118967200-ce974e00-b940-11eb-89ab-d4366e360dc9.mp4 11 | 12 | ## Quick start 13 | 14 | ```bash 15 | 16 | # running all the systems 17 | make run 18 | # open another tab - simulating a live colorbar live hls signal 19 | make broadcast_tvshow 20 | 21 | # you can check the streaming manifest content 22 | http http://localhost:8080/hls/colorbar.m3u8 23 | ```` 24 | 25 | Go to http://localhost:3000/ and create a simple lua code to ensure a super secret token scheme: 26 | 27 | ```lua 28 | local token = ngx.var.arg_token or ngx.var.cookie_superstition 29 | 30 | if token ~= 'token' then 31 | return ngx.exit(ngx.HTTP_FORBIDDEN) 32 | else 33 | ngx.header['Set-Cookie'] = {'superstition=token'} 34 | end 35 | ``` 36 | 37 | ![A CMS print screen](/cms.jpg "A CMS print screen") 38 | 39 | ```bash 40 | # if you try to fetch the token again, the server will reply with a 403 41 | http http://localhost:8080/hls/colorbar.m3u8 42 | 43 | # but if you pass the super token, then it's going to work fine :) 44 | http http://localhost:8080/hls/colorbar.m3u8?token=token 45 | ``` 46 | 47 | # Future work 48 | 49 | * Federated functions 50 | * maybe using the domain to shard and sum with a global domain * 51 | * Some form of lua sandboxing 52 | * since [luajit can't enforce](https://github.com/Kong/kong-lua-sandbox) quota, one might use the admin phase to run the code and mesure the time, check syntax, security?! 53 | * Provide a API hook for authentication 54 | * Publish it as a rock 55 | * Add measurements 56 | -------------------------------------------------------------------------------- /admin/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore uploaded files in development 17 | /storage/* 18 | !/storage/.keep 19 | 20 | /node_modules 21 | /yarn-error.log 22 | 23 | /public/assets 24 | .byebug_history 25 | 26 | # Ignore master key for decrypting credentials and more. 27 | /config/master.key 28 | -------------------------------------------------------------------------------- /admin/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /admin/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.5.8 -------------------------------------------------------------------------------- /admin/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.6.3 2 | RUN apt-get update -qq && apt-get install -y nodejs default-libmysqlclient-dev yarn 3 | RUN mkdir /myapp 4 | WORKDIR /myapp 5 | COPY Gemfile /myapp/Gemfile 6 | COPY Gemfile.lock /myapp/Gemfile.lock 7 | RUN bundle install 8 | # Start the main process. 9 | CMD ["rails", "server", "-b", "0.0.0.0"] 10 | -------------------------------------------------------------------------------- /admin/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby '2.6.3' 5 | 6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7 | gem 'rails', '~> 5.2.4', '>= 5.2.4.3' 8 | # Use mysql as the database for Active Record 9 | gem 'mysql2', '>= 0.4.4', '< 0.6.0' 10 | # Use Puma as the app server 11 | gem 'puma', '~> 3.11' 12 | # Use SCSS for stylesheets 13 | gem 'sass-rails', '~> 5.0' 14 | # Use Uglifier as compressor for JavaScript assets 15 | gem 'uglifier', '>= 1.3.0' 16 | # See https://github.com/rails/execjs#readme for more supported runtimes 17 | # gem 'mini_racer', platforms: :ruby 18 | 19 | # Use CoffeeScript for .coffee assets and views 20 | gem 'coffee-rails', '~> 4.2' 21 | # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22 | gem 'turbolinks', '~> 5' 23 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24 | gem 'jbuilder', '~> 2.5' 25 | # Use Redis adapter to run Action Cable in production 26 | # gem 'redis', '~> 4.0' 27 | # Use ActiveModel has_secure_password 28 | # gem 'bcrypt', '~> 3.1.7' 29 | 30 | # Use ActiveStorage variant 31 | # gem 'mini_magick', '~> 4.8' 32 | 33 | # Use Capistrano for deployment 34 | # gem 'capistrano-rails', group: :development 35 | 36 | # Reduces boot times through caching; required in config/boot.rb 37 | gem 'bootsnap', '>= 1.1.0', require: false 38 | 39 | group :development, :test do 40 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42 | end 43 | 44 | group :development do 45 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 | gem 'web-console', '>= 3.3.0' 47 | gem 'listen', '>= 3.0.5', '< 3.2' 48 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 | gem 'spring' 50 | gem 'spring-watcher-listen', '~> 2.0.0' 51 | end 52 | 53 | group :test do 54 | # Adds support for Capybara system testing and selenium driver 55 | gem 'capybara', '>= 2.15' 56 | gem 'selenium-webdriver' 57 | # Easy installation and use of chromedriver to run system tests with Chrome 58 | gem 'chromedriver-helper' 59 | end 60 | 61 | group :development, :test do 62 | gem 'rspec-rails', '~> 4.0.1' 63 | end 64 | 65 | gem 'activeadmin' 66 | # Plus integrations with: 67 | gem 'devise' 68 | gem 'cancancan' 69 | gem 'draper' 70 | gem 'pundit' 71 | gem 'paperclip' 72 | gem 'activeadmin_addons' 73 | 74 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 75 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 76 | -------------------------------------------------------------------------------- /admin/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.2.6) 5 | actionpack (= 5.2.6) 6 | nio4r (~> 2.0) 7 | websocket-driver (>= 0.6.1) 8 | actionmailer (5.2.6) 9 | actionpack (= 5.2.6) 10 | actionview (= 5.2.6) 11 | activejob (= 5.2.6) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.2.6) 15 | actionview (= 5.2.6) 16 | activesupport (= 5.2.6) 17 | rack (~> 2.0, >= 2.0.8) 18 | rack-test (>= 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.2.6) 22 | activesupport (= 5.2.6) 23 | builder (~> 3.1) 24 | erubi (~> 1.4) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | active_material (1.4.2) 28 | activeadmin (2.9.0) 29 | arbre (~> 1.2, >= 1.2.1) 30 | formtastic (>= 3.1, < 5.0) 31 | formtastic_i18n (~> 0.4) 32 | inherited_resources (~> 1.7) 33 | jquery-rails (~> 4.2) 34 | kaminari (~> 1.0, >= 1.2.1) 35 | railties (>= 5.2, < 6.2) 36 | ransack (~> 2.1, >= 2.1.1) 37 | activeadmin_addons (1.7.1) 38 | active_material 39 | railties 40 | require_all (~> 1.5) 41 | sass 42 | select2-rails (~> 4.0) 43 | xdan-datetimepicker-rails (~> 2.5.1) 44 | activejob (5.2.6) 45 | activesupport (= 5.2.6) 46 | globalid (>= 0.3.6) 47 | activemodel (5.2.6) 48 | activesupport (= 5.2.6) 49 | activemodel-serializers-xml (1.0.2) 50 | activemodel (> 5.x) 51 | activesupport (> 5.x) 52 | builder (~> 3.1) 53 | activerecord (5.2.6) 54 | activemodel (= 5.2.6) 55 | activesupport (= 5.2.6) 56 | arel (>= 9.0) 57 | activestorage (5.2.6) 58 | actionpack (= 5.2.6) 59 | activerecord (= 5.2.6) 60 | marcel (~> 1.0.0) 61 | activesupport (5.2.6) 62 | concurrent-ruby (~> 1.0, >= 1.0.2) 63 | i18n (>= 0.7, < 2) 64 | minitest (~> 5.1) 65 | tzinfo (~> 1.1) 66 | addressable (2.7.0) 67 | public_suffix (>= 2.0.2, < 5.0) 68 | arbre (1.4.0) 69 | activesupport (>= 3.0.0, < 6.2) 70 | ruby2_keywords (>= 0.0.2, < 1.0) 71 | archive-zip (0.12.0) 72 | io-like (~> 0.3.0) 73 | arel (9.0.0) 74 | bcrypt (3.1.16) 75 | bindex (0.8.1) 76 | bootsnap (1.7.5) 77 | msgpack (~> 1.0) 78 | builder (3.2.4) 79 | byebug (11.1.3) 80 | cancancan (3.2.1) 81 | capybara (3.35.3) 82 | addressable 83 | mini_mime (>= 0.1.3) 84 | nokogiri (~> 1.8) 85 | rack (>= 1.6.0) 86 | rack-test (>= 0.6.3) 87 | regexp_parser (>= 1.5, < 3.0) 88 | xpath (~> 3.2) 89 | childprocess (3.0.0) 90 | chromedriver-helper (2.1.1) 91 | archive-zip (~> 0.10) 92 | nokogiri (~> 1.8) 93 | climate_control (0.2.0) 94 | coffee-rails (4.2.2) 95 | coffee-script (>= 2.2.0) 96 | railties (>= 4.0.0) 97 | coffee-script (2.4.1) 98 | coffee-script-source 99 | execjs 100 | coffee-script-source (1.12.2) 101 | concurrent-ruby (1.1.8) 102 | crass (1.0.6) 103 | devise (4.8.0) 104 | bcrypt (~> 3.0) 105 | orm_adapter (~> 0.1) 106 | railties (>= 4.1.0) 107 | responders 108 | warden (~> 1.2.3) 109 | diff-lcs (1.4.4) 110 | draper (4.0.1) 111 | actionpack (>= 5.0) 112 | activemodel (>= 5.0) 113 | activemodel-serializers-xml (>= 1.0) 114 | activesupport (>= 5.0) 115 | request_store (>= 1.0) 116 | erubi (1.10.0) 117 | execjs (2.8.0) 118 | ffi (1.15.0) 119 | formtastic (4.0.0) 120 | actionpack (>= 5.2.0) 121 | formtastic_i18n (0.6.0) 122 | globalid (0.4.2) 123 | activesupport (>= 4.2.0) 124 | has_scope (0.8.0) 125 | actionpack (>= 5.2) 126 | activesupport (>= 5.2) 127 | i18n (1.8.10) 128 | concurrent-ruby (~> 1.0) 129 | inherited_resources (1.13.0) 130 | actionpack (>= 5.2, < 6.2) 131 | has_scope (~> 0.6) 132 | railties (>= 5.2, < 6.2) 133 | responders (>= 2, < 4) 134 | io-like (0.3.1) 135 | jbuilder (2.11.2) 136 | activesupport (>= 5.0.0) 137 | jquery-rails (4.4.0) 138 | rails-dom-testing (>= 1, < 3) 139 | railties (>= 4.2.0) 140 | thor (>= 0.14, < 2.0) 141 | kaminari (1.2.1) 142 | activesupport (>= 4.1.0) 143 | kaminari-actionview (= 1.2.1) 144 | kaminari-activerecord (= 1.2.1) 145 | kaminari-core (= 1.2.1) 146 | kaminari-actionview (1.2.1) 147 | actionview 148 | kaminari-core (= 1.2.1) 149 | kaminari-activerecord (1.2.1) 150 | activerecord 151 | kaminari-core (= 1.2.1) 152 | kaminari-core (1.2.1) 153 | listen (3.1.5) 154 | rb-fsevent (~> 0.9, >= 0.9.4) 155 | rb-inotify (~> 0.9, >= 0.9.7) 156 | ruby_dep (~> 1.2) 157 | loofah (2.9.1) 158 | crass (~> 1.0.2) 159 | nokogiri (>= 1.5.9) 160 | mail (2.7.1) 161 | mini_mime (>= 0.1.1) 162 | marcel (1.0.1) 163 | method_source (1.0.0) 164 | mime-types (3.3.1) 165 | mime-types-data (~> 3.2015) 166 | mime-types-data (3.2021.0225) 167 | mimemagic (0.3.10) 168 | nokogiri (~> 1) 169 | rake 170 | mini_mime (1.1.0) 171 | mini_portile2 (2.5.1) 172 | minitest (5.14.4) 173 | msgpack (1.4.2) 174 | mysql2 (0.5.3) 175 | nio4r (2.5.7) 176 | nokogiri (1.11.3) 177 | mini_portile2 (~> 2.5.0) 178 | racc (~> 1.4) 179 | orm_adapter (0.5.0) 180 | paperclip (6.1.0) 181 | activemodel (>= 4.2.0) 182 | activesupport (>= 4.2.0) 183 | mime-types 184 | mimemagic (~> 0.3.0) 185 | terrapin (~> 0.6.0) 186 | public_suffix (4.0.6) 187 | puma (3.12.6) 188 | pundit (2.1.0) 189 | activesupport (>= 3.0.0) 190 | racc (1.5.2) 191 | rack (2.2.3) 192 | rack-test (1.1.0) 193 | rack (>= 1.0, < 3) 194 | rails (5.2.6) 195 | actioncable (= 5.2.6) 196 | actionmailer (= 5.2.6) 197 | actionpack (= 5.2.6) 198 | actionview (= 5.2.6) 199 | activejob (= 5.2.6) 200 | activemodel (= 5.2.6) 201 | activerecord (= 5.2.6) 202 | activestorage (= 5.2.6) 203 | activesupport (= 5.2.6) 204 | bundler (>= 1.3.0) 205 | railties (= 5.2.6) 206 | sprockets-rails (>= 2.0.0) 207 | rails-dom-testing (2.0.3) 208 | activesupport (>= 4.2.0) 209 | nokogiri (>= 1.6) 210 | rails-html-sanitizer (1.3.0) 211 | loofah (~> 2.3) 212 | railties (5.2.6) 213 | actionpack (= 5.2.6) 214 | activesupport (= 5.2.6) 215 | method_source 216 | rake (>= 0.8.7) 217 | thor (>= 0.19.0, < 2.0) 218 | rake (13.0.3) 219 | ransack (2.4.2) 220 | activerecord (>= 5.2.4) 221 | activesupport (>= 5.2.4) 222 | i18n 223 | rb-fsevent (0.11.0) 224 | rb-inotify (0.10.1) 225 | ffi (~> 1.0) 226 | regexp_parser (2.1.1) 227 | request_store (1.5.0) 228 | rack (>= 1.4) 229 | require_all (1.5.0) 230 | responders (3.0.1) 231 | actionpack (>= 5.0) 232 | railties (>= 5.0) 233 | rspec-core (3.10.1) 234 | rspec-support (~> 3.10.0) 235 | rspec-expectations (3.10.1) 236 | diff-lcs (>= 1.2.0, < 2.0) 237 | rspec-support (~> 3.10.0) 238 | rspec-mocks (3.10.2) 239 | diff-lcs (>= 1.2.0, < 2.0) 240 | rspec-support (~> 3.10.0) 241 | rspec-rails (4.0.2) 242 | actionpack (>= 4.2) 243 | activesupport (>= 4.2) 244 | railties (>= 4.2) 245 | rspec-core (~> 3.10) 246 | rspec-expectations (~> 3.10) 247 | rspec-mocks (~> 3.10) 248 | rspec-support (~> 3.10) 249 | rspec-support (3.10.2) 250 | ruby2_keywords (0.0.4) 251 | ruby_dep (1.5.0) 252 | rubyzip (2.3.0) 253 | sass (3.7.4) 254 | sass-listen (~> 4.0.0) 255 | sass-listen (4.0.0) 256 | rb-fsevent (~> 0.9, >= 0.9.4) 257 | rb-inotify (~> 0.9, >= 0.9.7) 258 | sass-rails (5.1.0) 259 | railties (>= 5.2.0) 260 | sass (~> 3.1) 261 | sprockets (>= 2.8, < 4.0) 262 | sprockets-rails (>= 2.0, < 4.0) 263 | tilt (>= 1.1, < 3) 264 | select2-rails (4.0.13) 265 | selenium-webdriver (3.142.7) 266 | childprocess (>= 0.5, < 4.0) 267 | rubyzip (>= 1.2.2) 268 | spring (2.1.1) 269 | spring-watcher-listen (2.0.1) 270 | listen (>= 2.7, < 4.0) 271 | spring (>= 1.2, < 3.0) 272 | sprockets (3.7.2) 273 | concurrent-ruby (~> 1.0) 274 | rack (> 1, < 3) 275 | sprockets-rails (3.2.2) 276 | actionpack (>= 4.0) 277 | activesupport (>= 4.0) 278 | sprockets (>= 3.0.0) 279 | terrapin (0.6.0) 280 | climate_control (>= 0.0.3, < 1.0) 281 | thor (1.1.0) 282 | thread_safe (0.3.6) 283 | tilt (2.0.10) 284 | turbolinks (5.2.1) 285 | turbolinks-source (~> 5.2) 286 | turbolinks-source (5.2.0) 287 | tzinfo (1.2.9) 288 | thread_safe (~> 0.1) 289 | uglifier (4.2.0) 290 | execjs (>= 0.3.0, < 3) 291 | warden (1.2.9) 292 | rack (>= 2.0.9) 293 | web-console (3.7.0) 294 | actionview (>= 5.0) 295 | activemodel (>= 5.0) 296 | bindex (>= 0.4.0) 297 | railties (>= 5.0) 298 | websocket-driver (0.7.3) 299 | websocket-extensions (>= 0.1.0) 300 | websocket-extensions (0.1.5) 301 | xdan-datetimepicker-rails (2.5.4) 302 | jquery-rails 303 | rails (>= 3.2.16) 304 | xpath (3.2.0) 305 | nokogiri (~> 1.8) 306 | 307 | PLATFORMS 308 | ruby 309 | 310 | DEPENDENCIES 311 | activeadmin 312 | activeadmin_addons 313 | bootsnap (>= 1.1.0) 314 | byebug 315 | cancancan 316 | capybara (>= 2.15) 317 | chromedriver-helper 318 | coffee-rails (~> 4.2) 319 | devise 320 | draper 321 | jbuilder (~> 2.5) 322 | listen (>= 3.0.5, < 3.2) 323 | mysql2 (>= 0.4.4, < 0.6.0) 324 | paperclip 325 | puma (~> 3.11) 326 | pundit 327 | rails (~> 5.2.4, >= 5.2.4.3) 328 | rspec-rails (~> 4.0.1) 329 | sass-rails (~> 5.0) 330 | selenium-webdriver 331 | spring 332 | spring-watcher-listen (~> 2.0.0) 333 | turbolinks (~> 5) 334 | tzinfo-data 335 | uglifier (>= 1.3.0) 336 | web-console (>= 3.3.0) 337 | 338 | RUBY VERSION 339 | ruby 2.6.3p62 340 | 341 | BUNDLED WITH 342 | 1.17.2 343 | -------------------------------------------------------------------------------- /admin/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: run test 2 | 3 | run: 4 | docker-compose run --rm --service-ports web 5 | test: 6 | docker-compose run --rm web bundle exec rspec 7 | -------------------------------------------------------------------------------- /admin/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /admin/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /admin/app/admin/admin_users.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register AdminUser do 2 | #menu priority: 30 3 | menu false 4 | permit_params :email, :password, :password_confirmation 5 | 6 | index do 7 | selectable_column 8 | id_column 9 | column :email 10 | column :current_sign_in_at 11 | column :sign_in_count 12 | column :created_at 13 | actions 14 | end 15 | 16 | filter :email 17 | filter :current_sign_in_at 18 | filter :sign_in_count 19 | filter :created_at 20 | 21 | form do |f| 22 | f.inputs do 23 | f.input :email 24 | f.input :password 25 | f.input :password_confirmation 26 | end 27 | f.actions 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /admin/app/admin/computing_units.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register ComputingUnit do 2 | permit_params :name, :phase, :code, :sampling 3 | 4 | form do |f| 5 | f.inputs "Computing Unit" do 6 | f.input :name 7 | f.input :phase, as: :select, collection: ComputingUnit::PHASE_OPTIONS 8 | f.input :code, :as => :text 9 | f.input :sampling, :as => :number 10 | end 11 | actions 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /admin/app/admin/dashboard.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register_page "Dashboard" do 2 | menu false 3 | 4 | content title: proc { I18n.t("active_admin.dashboard") } do 5 | div class: "blank_slate_container", id: "dashboard_default_message" do 6 | span class: "blank_slate" do 7 | span I18n.t("active_admin.dashboard_welcome.welcome") 8 | small I18n.t("active_admin.dashboard_welcome.call_to_action") 9 | end 10 | end 11 | 12 | # Here is an example of a simple dashboard with columns and panels. 13 | # 14 | # columns do 15 | # column do 16 | # panel "Recent Posts" do 17 | # ul do 18 | # Post.recent(5).map do |post| 19 | # li link_to(post.title, admin_post_path(post)) 20 | # end 21 | # end 22 | # end 23 | # end 24 | 25 | # column do 26 | # panel "Info" do 27 | # para "Welcome to ActiveAdmin." 28 | # end 29 | # end 30 | # end 31 | end # content 32 | end 33 | -------------------------------------------------------------------------------- /admin/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /admin/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/app/assets/images/.keep -------------------------------------------------------------------------------- /admin/app/assets/javascripts/active_admin.js: -------------------------------------------------------------------------------- 1 | //= require active_admin/base 2 | //= require activeadmin_addons/all 3 | -------------------------------------------------------------------------------- /admin/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's 5 | // vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require rails-ujs 14 | //= require activestorage 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /admin/app/assets/javascripts/cable.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the `rails generate channel` command. 3 | // 4 | //= require action_cable 5 | //= require_self 6 | //= require_tree ./channels 7 | 8 | (function() { 9 | this.App || (this.App = {}); 10 | 11 | App.cable = ActionCable.createConsumer(); 12 | 13 | }).call(this); 14 | -------------------------------------------------------------------------------- /admin/app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/app/assets/javascripts/channels/.keep -------------------------------------------------------------------------------- /admin/app/assets/stylesheets/active_admin.scss: -------------------------------------------------------------------------------- 1 | @import 'activeadmin_addons/all'; 2 | // SASS variable overrides must be declared before loading up Active Admin's styles. 3 | // 4 | // To view the variables that Active Admin provides, take a look at 5 | // `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the 6 | // Active Admin source. 7 | // 8 | // For example, to change the sidebar width: 9 | // $sidebar-width: 242px; 10 | 11 | // Active Admin's got SASS! 12 | @import "active_admin/mixins"; 13 | @import "active_admin/base"; 14 | 15 | // Overriding any non-variable SASS must be done after the fact. 16 | // For example, to change the default status-tag color: 17 | // 18 | // .status_tag { background: #6090DB; } 19 | -------------------------------------------------------------------------------- /admin/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /admin/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /admin/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /admin/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /admin/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /admin/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /admin/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /admin/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /admin/app/models/admin_user.rb: -------------------------------------------------------------------------------- 1 | class AdminUser < ApplicationRecord 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 | devise :database_authenticatable, 5 | :recoverable, :rememberable, :validatable 6 | end 7 | -------------------------------------------------------------------------------- /admin/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /admin/app/models/computing_unit.rb: -------------------------------------------------------------------------------- 1 | class ComputingUnit < ApplicationRecord 2 | validates :name, uniqueness: true, presence: true 3 | validates :phase, :code, presence: true 4 | 5 | PHASE_OPTIONS = ["rewrite", "balancer", "access", "content", "header_filter", "body_filter", "log"] 6 | end 7 | -------------------------------------------------------------------------------- /admin/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/app/models/concerns/.keep -------------------------------------------------------------------------------- /admin/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Myapp 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | 8 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 9 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 10 | 11 | 12 | 13 | <%= yield %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /admin/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /admin/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /admin/app/views/summary/show.html.erb: -------------------------------------------------------------------------------- 1 | <%# https://developers.google.com/chart/interactive/docs/gallery/timeline %> 2 | <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %> 3 | 4 | 26 | 27 |
28 | -------------------------------------------------------------------------------- /admin/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /admin/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /admin/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /admin/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a starting point to setup your application. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | # puts "\n== Copying sample files ==" 24 | # unless File.exist?('config/database.yml') 25 | # cp 'config/database.yml.sample', 'config/database.yml' 26 | # end 27 | 28 | puts "\n== Preparing database ==" 29 | system! 'bin/rails db:setup' 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! 'bin/rails log:clear tmp:clear' 33 | 34 | puts "\n== Restarting application server ==" 35 | system! 'bin/rails restart' 36 | end 37 | -------------------------------------------------------------------------------- /admin/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads Spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == 'spring' } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /admin/bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a way to update your development environment automatically. 14 | # Add necessary update steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | puts "\n== Updating database ==" 24 | system! 'bin/rails db:migrate' 25 | 26 | puts "\n== Removing old logs and tempfiles ==" 27 | system! 'bin/rails log:clear tmp:clear' 28 | 29 | puts "\n== Restarting application server ==" 30 | system! 'bin/rails restart' 31 | end 32 | -------------------------------------------------------------------------------- /admin/bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | begin 5 | exec "yarnpkg", *ARGV 6 | rescue Errno::ENOENT 7 | $stderr.puts "Yarn executable was not detected in the system." 8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 9 | exit 1 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /admin/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /admin/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Myapp 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 5.2 13 | 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration can go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded after loading 17 | # the framework and any gems in your application. 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /admin/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /admin/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: myapp_production 11 | -------------------------------------------------------------------------------- /admin/config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | HmSQHIMbW3BcBpeIcHaYzfD+AlyGay9wm3VSsOKlJE60uiKKeZ8yKIlEY8aNGRRYCQiNLBvHaqQAqOsZNyVtDgLFgy6FXawaEaCKp1eUL+ZQ1hrFH37VWD24sZkwi5dNIdx7HF+lgMBgzcEOFXe0CP7CclnUr3MHzroaKDOEXS9tyh3g9gMy7tS90pPZ22sYYqjYA13IareMJDtCtOWTmIf1CqnoMxRuhQjWvyw9md5cWw0i8xX03Ry7kU7XY/w0LU3qUbHRSredZgKIF2q6cZtmWK6ZVeuunfS6u5ssqNhJX/43CG9cAJRGpaMLQio1fzwSu8+yRQSMJu5ld4xVXo33J2dMbJMcp0NODX4saWX7laUOYiU6BVn7HQSDNQ4EYO99maY8M9dNn0nC8SgZYxzMJNNzWFukC7Ue--JuFtKl9bEbwM7Zix--Q5qEX0VPjFyJLbtZffqvfg== -------------------------------------------------------------------------------- /admin/config/database.yml: -------------------------------------------------------------------------------- 1 | # MySQL. Versions 5.1.10 and up are supported. 2 | # 3 | # Install the MySQL driver 4 | # gem install mysql2 5 | # 6 | # Ensure the MySQL gem is defined in your Gemfile 7 | # gem 'mysql2' 8 | # 9 | # And be sure to use new-style password hashing: 10 | # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html 11 | # 12 | default: &default 13 | adapter: mysql2 14 | encoding: utf8 15 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 16 | username: <%= ENV.fetch("DB_USER") %> 17 | password: <%= ENV.fetch("DB_PASSWORD") %> 18 | host: <%= ENV.fetch("DB_HOST") %> 19 | 20 | development: 21 | <<: *default 22 | database: <%= ENV.fetch("DB_NAME") %> 23 | 24 | # Warning: The database defined as "test" will be erased and 25 | # re-generated from your development database when you run "rake". 26 | # Do not set this db to the same as development or production. 27 | test: 28 | <<: *default 29 | database: myapp_test 30 | 31 | # As with config/secrets.yml, you never want to store sensitive information, 32 | # like your database password, in your source code. If your source code is 33 | # ever seen by anyone, they now have access to your database. 34 | # 35 | # Instead, provide the password as a unix environment variable when you boot 36 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 37 | # for a full rundown on how to provide these environment variables in a 38 | # production deployment. 39 | # 40 | # On Heroku and other platform providers, you may have a full connection URL 41 | # available as an environment variable. For example: 42 | # 43 | # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" 44 | # 45 | # You can use this database configuration with: 46 | # 47 | # production: 48 | # url: <%= ENV['DATABASE_URL'] %> 49 | # 50 | production: 51 | <<: *default 52 | database: myapp_production 53 | username: myapp 54 | password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %> 55 | -------------------------------------------------------------------------------- /admin/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /admin/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | # Run rails dev:cache to toggle caching. 17 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 18 | config.action_controller.perform_caching = true 19 | 20 | config.cache_store = :memory_store 21 | config.public_file_server.headers = { 22 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 23 | } 24 | else 25 | config.action_controller.perform_caching = false 26 | 27 | config.cache_store = :null_store 28 | end 29 | 30 | # Store uploaded files on the local file system (see config/storage.yml for options) 31 | config.active_storage.service = :local 32 | 33 | # Don't care if the mailer can't send. 34 | config.action_mailer.raise_delivery_errors = false 35 | 36 | config.action_mailer.perform_caching = false 37 | 38 | # Print deprecation notices to the Rails logger. 39 | config.active_support.deprecation = :log 40 | 41 | # Raise an error on page load if there are pending migrations. 42 | config.active_record.migration_error = :page_load 43 | 44 | # Highlight code that triggered database queries in logs. 45 | config.active_record.verbose_query_logs = true 46 | 47 | # Debug mode disables concatenation and preprocessing of assets. 48 | # This option may cause significant delays in view rendering with a large 49 | # number of complex assets. 50 | config.assets.debug = true 51 | 52 | # Suppress logger output for asset requests. 53 | config.assets.quiet = true 54 | 55 | # Raises error for missing translations 56 | # config.action_view.raise_on_missing_translations = true 57 | 58 | # Use an evented file watcher to asynchronously detect changes in source code, 59 | # routes, locales, etc. This feature depends on the listen gem. 60 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 61 | end 62 | -------------------------------------------------------------------------------- /admin/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 18 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 19 | # config.require_master_key = true 20 | 21 | # Disable serving static files from the `/public` folder by default since 22 | # Apache or NGINX already handles this. 23 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = :uglifier 27 | # config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = false 31 | 32 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 33 | 34 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 35 | # config.action_controller.asset_host = 'http://assets.example.com' 36 | 37 | # Specifies the header that your server uses for sending files. 38 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 39 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 40 | 41 | # Store uploaded files on the local file system (see config/storage.yml for options) 42 | config.active_storage.service = :local 43 | 44 | # Mount Action Cable outside main process or domain 45 | # config.action_cable.mount_path = nil 46 | # config.action_cable.url = 'wss://example.com/cable' 47 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 48 | 49 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 50 | # config.force_ssl = true 51 | 52 | # Use the lowest log level to ensure availability of diagnostic information 53 | # when problems arise. 54 | config.log_level = :debug 55 | 56 | # Prepend all log lines with the following tags. 57 | config.log_tags = [ :request_id ] 58 | 59 | # Use a different cache store in production. 60 | # config.cache_store = :mem_cache_store 61 | 62 | # Use a real queuing backend for Active Job (and separate queues per environment) 63 | # config.active_job.queue_adapter = :resque 64 | # config.active_job.queue_name_prefix = "myapp_#{Rails.env}" 65 | 66 | config.action_mailer.perform_caching = false 67 | 68 | # Ignore bad email addresses and do not raise email delivery errors. 69 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 70 | # config.action_mailer.raise_delivery_errors = false 71 | 72 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 73 | # the I18n.default_locale when a translation cannot be found). 74 | config.i18n.fallbacks = true 75 | 76 | # Send deprecation notices to registered listeners. 77 | config.active_support.deprecation = :notify 78 | 79 | # Use default logging formatter so that PID and timestamp are not suppressed. 80 | config.log_formatter = ::Logger::Formatter.new 81 | 82 | # Use a different logger for distributed setups. 83 | # require 'syslog/logger' 84 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 85 | 86 | if ENV["RAILS_LOG_TO_STDOUT"].present? 87 | logger = ActiveSupport::Logger.new(STDOUT) 88 | logger.formatter = config.log_formatter 89 | config.logger = ActiveSupport::TaggedLogging.new(logger) 90 | end 91 | 92 | # Do not dump schema after migrations. 93 | config.active_record.dump_schema_after_migration = false 94 | end 95 | -------------------------------------------------------------------------------- /admin/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | 31 | # Store uploaded files on the local file system in a temporary directory 32 | config.active_storage.service = :test 33 | 34 | config.action_mailer.perform_caching = false 35 | 36 | # Tell Action Mailer not to deliver emails to the real world. 37 | # The :test delivery method accumulates sent emails in the 38 | # ActionMailer::Base.deliveries array. 39 | config.action_mailer.delivery_method = :test 40 | 41 | # Print deprecation notices to the stderr. 42 | config.active_support.deprecation = :stderr 43 | 44 | # Raises error for missing translations 45 | # config.action_view.raise_on_missing_translations = true 46 | end 47 | -------------------------------------------------------------------------------- /admin/config/initializers/active_admin.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.setup do |config| 2 | # == Site Title 3 | # 4 | # Set the title that is displayed on the main layout 5 | # for each of the active admin pages. 6 | # 7 | config.site_title = "Edge Admin" 8 | 9 | # Set the link url for the title. For example, to take 10 | # users to your main site. Defaults to no link. 11 | # 12 | # config.site_title_link = "/" 13 | 14 | # Set an optional image to be displayed for the header 15 | # instead of a string (overrides :site_title) 16 | # 17 | # Note: Aim for an image that's 21px high so it fits in the header. 18 | # 19 | # config.site_title_image = "logo.png" 20 | 21 | # == Default Namespace 22 | # 23 | # Set the default namespace each administration resource 24 | # will be added to. 25 | # 26 | # eg: 27 | # config.default_namespace = :hello_world 28 | # 29 | # This will create resources in the HelloWorld module and 30 | # will namespace routes to /hello_world/* 31 | # 32 | # To set no namespace by default, use: 33 | # config.default_namespace = false 34 | # 35 | # Default: 36 | # config.default_namespace = :admin 37 | # 38 | # You can customize the settings for each namespace by using 39 | # a namespace block. For example, to change the site title 40 | # within a namespace: 41 | # 42 | # config.namespace :admin do |admin| 43 | # admin.site_title = "Custom Admin Title" 44 | # end 45 | # 46 | # This will ONLY change the title for the admin section. Other 47 | # namespaces will continue to use the main "site_title" configuration. 48 | 49 | # == User Authentication 50 | # 51 | # Active Admin will automatically call an authentication 52 | # method in a before filter of all controller actions to 53 | # ensure that there is a currently logged in admin user. 54 | # 55 | # This setting changes the method which Active Admin calls 56 | # within the application controller. 57 | #config.authentication_method = :authenticate_admin_user! 58 | config.authentication_method = false 59 | 60 | # == User Authorization 61 | # 62 | # Active Admin will automatically call an authorization 63 | # method in a before filter of all controller actions to 64 | # ensure that there is a user with proper rights. You can use 65 | # CanCanAdapter or make your own. Please refer to documentation. 66 | # config.authorization_adapter = ActiveAdmin::CanCanAdapter 67 | 68 | # In case you prefer Pundit over other solutions you can here pass 69 | # the name of default policy class. This policy will be used in every 70 | # case when Pundit is unable to find suitable policy. 71 | # config.pundit_default_policy = "MyDefaultPunditPolicy" 72 | 73 | # If you wish to maintain a separate set of Pundit policies for admin 74 | # resources, you may set a namespace here that Pundit will search 75 | # within when looking for a resource's policy. 76 | # config.pundit_policy_namespace = :admin 77 | 78 | # You can customize your CanCan Ability class name here. 79 | # config.cancan_ability_class = "Ability" 80 | 81 | # You can specify a method to be called on unauthorized access. 82 | # This is necessary in order to prevent a redirect loop which happens 83 | # because, by default, user gets redirected to Dashboard. If user 84 | # doesn't have access to Dashboard, he'll end up in a redirect loop. 85 | # Method provided here should be defined in application_controller.rb. 86 | # config.on_unauthorized_access = :access_denied 87 | 88 | # == Current User 89 | # 90 | # Active Admin will associate actions with the current 91 | # user performing them. 92 | # 93 | # This setting changes the method which Active Admin calls 94 | # (within the application controller) to return the currently logged in user. 95 | config.current_user_method = :current_admin_user 96 | 97 | # == Logging Out 98 | # 99 | # Active Admin displays a logout link on each screen. These 100 | # settings configure the location and method used for the link. 101 | # 102 | # This setting changes the path where the link points to. If it's 103 | # a string, the strings is used as the path. If it's a Symbol, we 104 | # will call the method to return the path. 105 | # 106 | # Default: 107 | config.logout_link_path = :destroy_admin_user_session_path 108 | 109 | # This setting changes the http method used when rendering the 110 | # link. For example :get, :delete, :put, etc.. 111 | # 112 | # Default: 113 | # config.logout_link_method = :get 114 | 115 | # == Root 116 | # 117 | # Set the action to call for the root path. You can set different 118 | # roots for each namespace. 119 | # 120 | # Default: 121 | config.root_to = 'dashboard#index' 122 | 123 | # == Admin Comments 124 | # 125 | # This allows your users to comment on any resource registered with Active Admin. 126 | # 127 | # You can completely disable comments: 128 | config.comments = false 129 | # 130 | # You can change the name under which comments are registered: 131 | # config.comments_registration_name = 'AdminComment' 132 | # 133 | # You can change the order for the comments and you can change the column 134 | # to be used for ordering: 135 | # config.comments_order = 'created_at ASC' 136 | # 137 | # You can disable the menu item for the comments index page: 138 | #config.comments_menu = false 139 | # 140 | # You can customize the comment menu: 141 | # config.comments_menu = { parent: 'Admin', priority: 1 } 142 | 143 | # == Batch Actions 144 | # 145 | # Enable and disable Batch Actions 146 | # 147 | config.batch_actions = true 148 | 149 | # == Controller Filters 150 | # 151 | # You can add before, after and around filters to all of your 152 | # Active Admin resources and pages from here. 153 | # 154 | # config.before_action :do_something_awesome 155 | 156 | # == Attribute Filters 157 | # 158 | # You can exclude possibly sensitive model attributes from being displayed, 159 | # added to forms, or exported by default by ActiveAdmin 160 | # 161 | config.filter_attributes = [:encrypted_password, :password, :password_confirmation] 162 | 163 | # == Localize Date/Time Format 164 | # 165 | # Set the localize format to display dates and times. 166 | # To understand how to localize your app with I18n, read more at 167 | # https://guides.rubyonrails.org/i18n.html 168 | # 169 | # You can run `bin/rails runner 'puts I18n.t("date.formats")'` to see the 170 | # available formats in your application. 171 | # 172 | config.localize_format = :long 173 | 174 | # == Setting a Favicon 175 | # 176 | # config.favicon = 'favicon.ico' 177 | 178 | # == Meta Tags 179 | # 180 | # Add additional meta tags to the head element of active admin pages. 181 | # 182 | # Add tags to all pages logged in users see: 183 | # config.meta_tags = { author: 'My Company' } 184 | 185 | # By default, sign up/sign in/recover password pages are excluded 186 | # from showing up in search engine results by adding a robots meta 187 | # tag. You can reset the hash of meta tags included in logged out 188 | # pages: 189 | # config.meta_tags_for_logged_out_pages = {} 190 | 191 | # == Removing Breadcrumbs 192 | # 193 | # Breadcrumbs are enabled by default. You can customize them for individual 194 | # resources or you can disable them globally from here. 195 | # 196 | # config.breadcrumb = false 197 | 198 | # == Create Another Checkbox 199 | # 200 | # Create another checkbox is disabled by default. You can customize it for individual 201 | # resources or you can enable them globally from here. 202 | # 203 | # config.create_another = true 204 | 205 | # == Register Stylesheets & Javascripts 206 | # 207 | # We recommend using the built in Active Admin layout and loading 208 | # up your own stylesheets / javascripts to customize the look 209 | # and feel. 210 | # 211 | # To load a stylesheet: 212 | # config.register_stylesheet 'my_stylesheet.css' 213 | # 214 | # You can provide an options hash for more control, which is passed along to stylesheet_link_tag(): 215 | # config.register_stylesheet 'my_print_stylesheet.css', media: :print 216 | # 217 | # To load a javascript file: 218 | # config.register_javascript 'my_javascript.js' 219 | 220 | # == CSV options 221 | # 222 | # Set the CSV builder separator 223 | # config.csv_options = { col_sep: ';' } 224 | # 225 | # Force the use of quotes 226 | # config.csv_options = { force_quotes: true } 227 | 228 | # == Menu System 229 | # 230 | # You can add a navigation menu to be used in your application, or configure a provided menu 231 | # 232 | # To change the default utility navigation to show a link to your website & a logout btn 233 | # 234 | # config.namespace :admin do |admin| 235 | # admin.build_menu :utility_navigation do |menu| 236 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank } 237 | # admin.add_logout_button_to_menu menu 238 | # end 239 | # end 240 | # 241 | # If you wanted to add a static menu item to the default menu provided: 242 | # 243 | # config.namespace :admin do |admin| 244 | # admin.build_menu :default do |menu| 245 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank } 246 | # end 247 | # end 248 | 249 | # == Download Links 250 | # 251 | # You can disable download links on resource listing pages, 252 | # or customize the formats shown per namespace/globally 253 | # 254 | # To disable/customize for the :admin namespace: 255 | # 256 | # config.namespace :admin do |admin| 257 | # 258 | # # Disable the links entirely 259 | # admin.download_links = false 260 | # 261 | # # Only show XML & PDF options 262 | # admin.download_links = [:xml, :pdf] 263 | # 264 | # # Enable/disable the links based on block 265 | # # (for example, with cancan) 266 | # admin.download_links = proc { can?(:view_download_links) } 267 | # 268 | # end 269 | 270 | # == Pagination 271 | # 272 | # Pagination is enabled by default for all resources. 273 | # You can control the default per page count for all resources here. 274 | # 275 | # config.default_per_page = 30 276 | # 277 | # You can control the max per page count too. 278 | # 279 | # config.max_per_page = 10_000 280 | 281 | # == Filters 282 | # 283 | # By default the index screen includes a "Filters" sidebar on the right 284 | # hand side with a filter for each attribute of the registered model. 285 | # You can enable or disable them for all resources here. 286 | # 287 | # config.filters = true 288 | # 289 | # By default the filters include associations in a select, which means 290 | # that every record will be loaded for each association (up 291 | # to the value of config.maximum_association_filter_arity). 292 | # You can enabled or disable the inclusion 293 | # of those filters by default here. 294 | # 295 | # config.include_default_association_filters = true 296 | 297 | # config.maximum_association_filter_arity = 256 # default value of :unlimited will change to 256 in a future version 298 | # config.filter_columns_for_large_association, [ 299 | # :display_name, 300 | # :full_name, 301 | # :name, 302 | # :username, 303 | # :login, 304 | # :title, 305 | # :email, 306 | # ] 307 | # config.filter_method_for_large_association, '_starts_with' 308 | 309 | # == Head 310 | # 311 | # You can add your own content to the site head like analytics. Make sure 312 | # you only pass content you trust. 313 | # 314 | # config.head = ''.html_safe 315 | 316 | # == Footer 317 | # 318 | # By default, the footer shows the current Active Admin version. You can 319 | # override the content of the footer here. 320 | # 321 | # config.footer = 'my custom footer text' 322 | 323 | # == Sorting 324 | # 325 | # By default ActiveAdmin::OrderClause is used for sorting logic 326 | # You can inherit it with own class and inject it for all resources 327 | # 328 | # config.order_clause = MyOrderClause 329 | 330 | # == Webpacker 331 | # 332 | # By default, Active Admin uses Sprocket's asset pipeline. 333 | # You can switch to using Webpacker here. 334 | # 335 | # config.use_webpacker = true 336 | end 337 | -------------------------------------------------------------------------------- /admin/config/initializers/activeadmin_addons.rb: -------------------------------------------------------------------------------- 1 | ActiveadminAddons.setup do |config| 2 | # Change to "default" if you want to use ActiveAdmin's default select control. 3 | # config.default_select = "select2" 4 | 5 | # Set default options for DateTimePickerInput. The options you can provide are the same as in 6 | # xdan's datetimepicker library (https://github.com/xdan/datetimepicker/tree/2.5.4). Yo need to 7 | # pass a ruby hash, avoid camelCase keys. For example: use min_date instead of minDate key. 8 | # config.datetime_picker_default_options = {} 9 | 10 | # Set DateTimePickerInput input format. This if for backend (Ruby) 11 | # config.datetime_picker_input_format = "%Y-%m-%d %H:%M" 12 | end 13 | -------------------------------------------------------------------------------- /admin/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /admin/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | # Add Yarn node_modules folder to the asset load path. 9 | Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 | 11 | # Precompile additional assets. 12 | # application.js, application.css, and all non-JS/CSS in the app/assets 13 | # folder are already added. 14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 15 | -------------------------------------------------------------------------------- /admin/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /admin/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy 4 | # For further information see the following documentation 5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 6 | 7 | # Rails.application.config.content_security_policy do |policy| 8 | # policy.default_src :self, :https 9 | # policy.font_src :self, :https, :data 10 | # policy.img_src :self, :https, :data 11 | # policy.object_src :none 12 | # policy.script_src :self, :https 13 | # policy.style_src :self, :https 14 | 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | 19 | # If you are using UJS then enable automatic nonce generation 20 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } 21 | 22 | # Report CSP violations to a specified URI 23 | # For further information see the following documentation: 24 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 25 | # Rails.application.config.content_security_policy_report_only = true 26 | -------------------------------------------------------------------------------- /admin/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /admin/config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Assuming you have not yet modified this file, each configuration option below 4 | # is set to its default value. Note that some are commented out while others 5 | # are not: uncommented lines are intended to protect your configuration from 6 | # breaking changes in upgrades (i.e., in the event that future versions of 7 | # Devise change the default values for those options). 8 | # 9 | # Use this hook to configure devise mailer, warden hooks and so forth. 10 | # Many of these configuration options can be set straight in your model. 11 | Devise.setup do |config| 12 | # The secret key used by Devise. Devise uses this key to generate 13 | # random tokens. Changing this key will render invalid all existing 14 | # confirmation, reset password and unlock tokens in the database. 15 | # Devise will use the `secret_key_base` as its `secret_key` 16 | # by default. You can change it below and use your own secret key. 17 | # config.secret_key = '06ddab8f4d6eb8ad0834d22f3e1ebc1a0df34388ff575e8106b64f6e1d9444f94d38beb81184b6a9216343ae6727976b7c7328afc2caa20ffbfab276c3bd7228' 18 | 19 | # ==> Controller configuration 20 | # Configure the parent class to the devise controllers. 21 | # config.parent_controller = 'DeviseController' 22 | 23 | # ==> Mailer Configuration 24 | # Configure the e-mail address which will be shown in Devise::Mailer, 25 | # note that it will be overwritten if you use your own mailer class 26 | # with default "from" parameter. 27 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 28 | 29 | # Configure the class responsible to send e-mails. 30 | # config.mailer = 'Devise::Mailer' 31 | 32 | # Configure the parent class responsible to send e-mails. 33 | # config.parent_mailer = 'ActionMailer::Base' 34 | 35 | # ==> ORM configuration 36 | # Load and configure the ORM. Supports :active_record (default) and 37 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 38 | # available as additional gems. 39 | require 'devise/orm/active_record' 40 | 41 | # ==> Configuration for any authentication mechanism 42 | # Configure which keys are used when authenticating a user. The default is 43 | # just :email. You can configure it to use [:username, :subdomain], so for 44 | # authenticating a user, both parameters are required. Remember that those 45 | # parameters are used only when authenticating and not when retrieving from 46 | # session. If you need permissions, you should implement that in a before filter. 47 | # You can also supply a hash where the value is a boolean determining whether 48 | # or not authentication should be aborted when the value is not present. 49 | # config.authentication_keys = [:email] 50 | 51 | # Configure parameters from the request object used for authentication. Each entry 52 | # given should be a request method and it will automatically be passed to the 53 | # find_for_authentication method and considered in your model lookup. For instance, 54 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 55 | # The same considerations mentioned for authentication_keys also apply to request_keys. 56 | # config.request_keys = [] 57 | 58 | # Configure which authentication keys should be case-insensitive. 59 | # These keys will be downcased upon creating or modifying a user and when used 60 | # to authenticate or find a user. Default is :email. 61 | config.case_insensitive_keys = [:email] 62 | 63 | # Configure which authentication keys should have whitespace stripped. 64 | # These keys will have whitespace before and after removed upon creating or 65 | # modifying a user and when used to authenticate or find a user. Default is :email. 66 | config.strip_whitespace_keys = [:email] 67 | 68 | # Tell if authentication through request.params is enabled. True by default. 69 | # It can be set to an array that will enable params authentication only for the 70 | # given strategies, for example, `config.params_authenticatable = [:database]` will 71 | # enable it only for database (email + password) authentication. 72 | # config.params_authenticatable = true 73 | 74 | # Tell if authentication through HTTP Auth is enabled. False by default. 75 | # It can be set to an array that will enable http authentication only for the 76 | # given strategies, for example, `config.http_authenticatable = [:database]` will 77 | # enable it only for database authentication. 78 | # For API-only applications to support authentication "out-of-the-box", you will likely want to 79 | # enable this with :database unless you are using a custom strategy. 80 | # The supported strategies are: 81 | # :database = Support basic authentication with authentication key + password 82 | # config.http_authenticatable = false 83 | 84 | # If 401 status code should be returned for AJAX requests. True by default. 85 | # config.http_authenticatable_on_xhr = true 86 | 87 | # The realm used in Http Basic Authentication. 'Application' by default. 88 | # config.http_authentication_realm = 'Application' 89 | 90 | # It will change confirmation, password recovery and other workflows 91 | # to behave the same regardless if the e-mail provided was right or wrong. 92 | # Does not affect registerable. 93 | # config.paranoid = true 94 | 95 | # By default Devise will store the user in session. You can skip storage for 96 | # particular strategies by setting this option. 97 | # Notice that if you are skipping storage for all authentication paths, you 98 | # may want to disable generating routes to Devise's sessions controller by 99 | # passing skip: :sessions to `devise_for` in your config/routes.rb 100 | config.skip_session_storage = [:http_auth] 101 | 102 | # By default, Devise cleans up the CSRF token on authentication to 103 | # avoid CSRF token fixation attacks. This means that, when using AJAX 104 | # requests for sign in and sign up, you need to get a new CSRF token 105 | # from the server. You can disable this option at your own risk. 106 | # config.clean_up_csrf_token_on_authentication = true 107 | 108 | # When false, Devise will not attempt to reload routes on eager load. 109 | # This can reduce the time taken to boot the app but if your application 110 | # requires the Devise mappings to be loaded during boot time the application 111 | # won't boot properly. 112 | # config.reload_routes = true 113 | 114 | # ==> Configuration for :database_authenticatable 115 | # For bcrypt, this is the cost for hashing the password and defaults to 12. If 116 | # using other algorithms, it sets how many times you want the password to be hashed. 117 | # The number of stretches used for generating the hashed password are stored 118 | # with the hashed password. This allows you to change the stretches without 119 | # invalidating existing passwords. 120 | # 121 | # Limiting the stretches to just one in testing will increase the performance of 122 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 123 | # a value less than 10 in other environments. Note that, for bcrypt (the default 124 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 125 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 126 | config.stretches = Rails.env.test? ? 1 : 12 127 | 128 | # Set up a pepper to generate the hashed password. 129 | # config.pepper = '9eb8525bad1ed61bc0307e46976dae7e391fd048f3083a44753b89b66e068abc109a4fa3ca538fc622c162bcd0db87571474877f85c9ae08fe1e9722d809202d' 130 | 131 | # Send a notification to the original email when the user's email is changed. 132 | # config.send_email_changed_notification = false 133 | 134 | # Send a notification email when the user's password is changed. 135 | # config.send_password_change_notification = false 136 | 137 | # ==> Configuration for :confirmable 138 | # A period that the user is allowed to access the website even without 139 | # confirming their account. For instance, if set to 2.days, the user will be 140 | # able to access the website for two days without confirming their account, 141 | # access will be blocked just in the third day. 142 | # You can also set it to nil, which will allow the user to access the website 143 | # without confirming their account. 144 | # Default is 0.days, meaning the user cannot access the website without 145 | # confirming their account. 146 | # config.allow_unconfirmed_access_for = 2.days 147 | 148 | # A period that the user is allowed to confirm their account before their 149 | # token becomes invalid. For example, if set to 3.days, the user can confirm 150 | # their account within 3 days after the mail was sent, but on the fourth day 151 | # their account can't be confirmed with the token any more. 152 | # Default is nil, meaning there is no restriction on how long a user can take 153 | # before confirming their account. 154 | # config.confirm_within = 3.days 155 | 156 | # If true, requires any email changes to be confirmed (exactly the same way as 157 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 158 | # db field (see migrations). Until confirmed, new email is stored in 159 | # unconfirmed_email column, and copied to email column on successful confirmation. 160 | config.reconfirmable = true 161 | 162 | # Defines which key will be used when confirming an account 163 | # config.confirmation_keys = [:email] 164 | 165 | # ==> Configuration for :rememberable 166 | # The time the user will be remembered without asking for credentials again. 167 | # config.remember_for = 2.weeks 168 | 169 | # Invalidates all the remember me tokens when the user signs out. 170 | config.expire_all_remember_me_on_sign_out = true 171 | 172 | # If true, extends the user's remember period when remembered via cookie. 173 | # config.extend_remember_period = false 174 | 175 | # Options to be passed to the created cookie. For instance, you can set 176 | # secure: true in order to force SSL only cookies. 177 | # config.rememberable_options = {} 178 | 179 | # ==> Configuration for :validatable 180 | # Range for password length. 181 | config.password_length = 6..128 182 | 183 | # Email regex used to validate email formats. It simply asserts that 184 | # one (and only one) @ exists in the given string. This is mainly 185 | # to give user feedback and not to assert the e-mail validity. 186 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 187 | 188 | # ==> Configuration for :timeoutable 189 | # The time you want to timeout the user session without activity. After this 190 | # time the user will be asked for credentials again. Default is 30 minutes. 191 | # config.timeout_in = 30.minutes 192 | 193 | # ==> Configuration for :lockable 194 | # Defines which strategy will be used to lock an account. 195 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 196 | # :none = No lock strategy. You should handle locking by yourself. 197 | # config.lock_strategy = :failed_attempts 198 | 199 | # Defines which key will be used when locking and unlocking an account 200 | # config.unlock_keys = [:email] 201 | 202 | # Defines which strategy will be used to unlock an account. 203 | # :email = Sends an unlock link to the user email 204 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 205 | # :both = Enables both strategies 206 | # :none = No unlock strategy. You should handle unlocking by yourself. 207 | # config.unlock_strategy = :both 208 | 209 | # Number of authentication tries before locking an account if lock_strategy 210 | # is failed attempts. 211 | # config.maximum_attempts = 20 212 | 213 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 214 | # config.unlock_in = 1.hour 215 | 216 | # Warn on the last attempt before the account is locked. 217 | # config.last_attempt_warning = true 218 | 219 | # ==> Configuration for :recoverable 220 | # 221 | # Defines which key will be used when recovering the password for an account 222 | # config.reset_password_keys = [:email] 223 | 224 | # Time interval you can reset your password with a reset password key. 225 | # Don't put a too small interval or your users won't have the time to 226 | # change their passwords. 227 | config.reset_password_within = 6.hours 228 | 229 | # When set to false, does not sign a user in automatically after their password is 230 | # reset. Defaults to true, so a user is signed in automatically after a reset. 231 | # config.sign_in_after_reset_password = true 232 | 233 | # ==> Configuration for :encryptable 234 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 235 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 236 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 237 | # for default behavior) and :restful_authentication_sha1 (then you should set 238 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 239 | # 240 | # Require the `devise-encryptable` gem when using anything other than bcrypt 241 | # config.encryptor = :sha512 242 | 243 | # ==> Scopes configuration 244 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 245 | # "users/sessions/new". It's turned off by default because it's slower if you 246 | # are using only default views. 247 | # config.scoped_views = false 248 | 249 | # Configure the default scope given to Warden. By default it's the first 250 | # devise role declared in your routes (usually :user). 251 | # config.default_scope = :user 252 | 253 | # Set this configuration to false if you want /users/sign_out to sign out 254 | # only the current scope. By default, Devise signs out all scopes. 255 | # config.sign_out_all_scopes = true 256 | 257 | # ==> Navigation configuration 258 | # Lists the formats that should be treated as navigational. Formats like 259 | # :html, should redirect to the sign in page when the user does not have 260 | # access, but formats like :xml or :json, should return 401. 261 | # 262 | # If you have any extra navigational formats, like :iphone or :mobile, you 263 | # should add them to the navigational formats lists. 264 | # 265 | # The "*/*" below is required to match Internet Explorer requests. 266 | # config.navigational_formats = ['*/*', :html] 267 | 268 | # The default HTTP method used to sign out a resource. Default is :delete. 269 | config.sign_out_via = :delete 270 | 271 | # ==> OmniAuth 272 | # Add a new OmniAuth provider. Check the wiki for more information on setting 273 | # up on your models and hooks. 274 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 275 | 276 | # ==> Warden configuration 277 | # If you want to use other strategies, that are not supported by Devise, or 278 | # change the failure app, you can configure them inside the config.warden block. 279 | # 280 | # config.warden do |manager| 281 | # manager.intercept_401 = false 282 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 283 | # end 284 | 285 | # ==> Mountable engine configurations 286 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 287 | # is mountable, there are some extra configurations to be taken into account. 288 | # The following options are available, assuming the engine is mounted as: 289 | # 290 | # mount MyEngine, at: '/my_engine' 291 | # 292 | # The router that invoked `devise_for`, in the example above, would be: 293 | # config.router_name = :my_engine 294 | # 295 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 296 | # so you need to do it manually. For the users scope, it would be: 297 | # config.omniauth_path_prefix = '/my_engine/users/auth' 298 | 299 | # ==> Turbolinks configuration 300 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: 301 | # 302 | # ActiveSupport.on_load(:devise_failure_app) do 303 | # include Turbolinks::Controller 304 | # end 305 | 306 | # ==> Configuration for :registerable 307 | 308 | # When set to false, does not sign a user in automatically after their password is 309 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 310 | # config.sign_in_after_change_password = true 311 | end 312 | -------------------------------------------------------------------------------- /admin/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /admin/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /admin/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /admin/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /admin/config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/heartcombo/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | email_changed: 27 | subject: "Email Changed" 28 | password_change: 29 | subject: "Password Changed" 30 | omniauth_callbacks: 31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 32 | success: "Successfully authenticated from %{kind} account." 33 | passwords: 34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 37 | updated: "Your password has been changed successfully. You are now signed in." 38 | updated_not_active: "Your password has been changed successfully." 39 | registrations: 40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 41 | signed_up: "Welcome! You have signed up successfully." 42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." 45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address." 46 | updated: "Your account has been updated successfully." 47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again" 48 | sessions: 49 | signed_in: "Signed in successfully." 50 | signed_out: "Signed out successfully." 51 | already_signed_out: "Signed out successfully." 52 | unlocks: 53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 56 | errors: 57 | messages: 58 | already_confirmed: "was already confirmed, please try signing in" 59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 60 | expired: "has expired, please request a new one" 61 | not_found: "not found" 62 | not_locked: "was not locked" 63 | not_saved: 64 | one: "1 error prohibited this %{resource} from being saved:" 65 | other: "%{count} errors prohibited this %{resource} from being saved:" 66 | -------------------------------------------------------------------------------- /admin/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at http://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /admin/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the `pidfile` that Puma will use. 19 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 20 | 21 | # Specifies the number of `workers` to boot in clustered mode. 22 | # Workers are forked webserver processes. If using threads and workers together 23 | # the concurrency of the application would be max `threads` * `workers`. 24 | # Workers do not work on JRuby or Windows (both of which do not support 25 | # processes). 26 | # 27 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 28 | 29 | # Use the `preload_app!` method when specifying a `workers` number. 30 | # This directive tells Puma to first boot the application and load code 31 | # before forking the application. This takes advantage of Copy On Write 32 | # process behavior so workers use less memory. 33 | # 34 | # preload_app! 35 | 36 | # Allow puma to be restarted by `rails restart` command. 37 | plugin :tmp_restart 38 | -------------------------------------------------------------------------------- /admin/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | devise_for :admin_users, ActiveAdmin::Devise.config 3 | ActiveAdmin.routes(self) 4 | root to: "admin/computing_units#index" 5 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 6 | end 7 | -------------------------------------------------------------------------------- /admin/config/spring.rb: -------------------------------------------------------------------------------- 1 | %w[ 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ].each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /admin/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket 23 | 24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /admin/db/migrate/20200723130114_devise_create_admin_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class DeviseCreateAdminUsers < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :admin_users do |t| 6 | ## Database authenticatable 7 | t.string :email, null: false, default: "" 8 | t.string :encrypted_password, null: false, default: "" 9 | 10 | ## Recoverable 11 | t.string :reset_password_token 12 | t.datetime :reset_password_sent_at 13 | 14 | ## Rememberable 15 | t.datetime :remember_created_at 16 | 17 | ## Trackable 18 | # t.integer :sign_in_count, default: 0, null: false 19 | # t.datetime :current_sign_in_at 20 | # t.datetime :last_sign_in_at 21 | # t.string :current_sign_in_ip 22 | # t.string :last_sign_in_ip 23 | 24 | ## Confirmable 25 | # t.string :confirmation_token 26 | # t.datetime :confirmed_at 27 | # t.datetime :confirmation_sent_at 28 | # t.string :unconfirmed_email # Only if using reconfirmable 29 | 30 | ## Lockable 31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 | # t.string :unlock_token # Only if unlock strategy is :email or :both 33 | # t.datetime :locked_at 34 | 35 | 36 | t.timestamps null: false 37 | end 38 | 39 | add_index :admin_users, :email, unique: true 40 | add_index :admin_users, :reset_password_token, unique: true 41 | # add_index :admin_users, :confirmation_token, unique: true 42 | # add_index :admin_users, :unlock_token, unique: true 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /admin/db/migrate/20200723130119_create_active_admin_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateActiveAdminComments < ActiveRecord::Migration[5.2] 2 | def self.up 3 | create_table :active_admin_comments do |t| 4 | t.string :namespace 5 | t.text :body 6 | t.references :resource, polymorphic: true 7 | t.references :author, polymorphic: true 8 | t.timestamps 9 | end 10 | add_index :active_admin_comments, [:namespace] 11 | end 12 | 13 | def self.down 14 | drop_table :active_admin_comments 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /admin/db/migrate/20210513192719_create_computing_units.rb: -------------------------------------------------------------------------------- 1 | class CreateComputingUnits < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :computing_units do |t| 4 | t.string :name 5 | t.string :phase 6 | t.string :code 7 | t.string :sampling 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /admin/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2021_05_13_192719) do 14 | 15 | create_table "active_admin_comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 16 | t.string "namespace" 17 | t.text "body" 18 | t.string "resource_type" 19 | t.bigint "resource_id" 20 | t.string "author_type" 21 | t.bigint "author_id" 22 | t.datetime "created_at", null: false 23 | t.datetime "updated_at", null: false 24 | t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id" 25 | t.index ["namespace"], name: "index_active_admin_comments_on_namespace" 26 | t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id" 27 | end 28 | 29 | create_table "admin_users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 30 | t.string "email", default: "", null: false 31 | t.string "encrypted_password", default: "", null: false 32 | t.string "reset_password_token" 33 | t.datetime "reset_password_sent_at" 34 | t.datetime "remember_created_at" 35 | t.datetime "created_at", null: false 36 | t.datetime "updated_at", null: false 37 | t.index ["email"], name: "index_admin_users_on_email", unique: true 38 | t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true 39 | end 40 | 41 | create_table "computing_units", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 42 | t.string "name" 43 | t.string "phase" 44 | t.string "code" 45 | t.string "sampling" 46 | t.datetime "created_at", null: false 47 | t.datetime "updated_at", null: false 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /admin/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? 9 | 10 | -------------------------------------------------------------------------------- /admin/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | db: 4 | image: mysql:5.6 5 | environment: 6 | - MYSQL_ROOT_PASSWORD=secret 7 | - MYSQL_DATABASE=admin 8 | web: 9 | build: . 10 | command: bash -c "./scripts/wait-for.sh db 3306 && rails db:migrate:reset && rake db:seed && rails s -p 3000 -b '0.0.0.0'" 11 | volumes: 12 | - .:/myapp 13 | ports: 14 | - "3000:3000" 15 | depends_on: 16 | - db 17 | environment: 18 | - DB_HOST=db 19 | - DB_USER=root 20 | - DB_PASSWORD=secret 21 | - DB_NAME=admin 22 | -------------------------------------------------------------------------------- /admin/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Remove a potentially pre-existing server.pid for Rails. 5 | rm -f /myapp/tmp/pids/server.pid 6 | 7 | # Then exec the container's main process (what's set as CMD in the Dockerfile). 8 | exec "$@" 9 | 10 | -------------------------------------------------------------------------------- /admin/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/lib/assets/.keep -------------------------------------------------------------------------------- /admin/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/lib/tasks/.keep -------------------------------------------------------------------------------- /admin/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/log/.keep -------------------------------------------------------------------------------- /admin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myapp", 3 | "private": true, 4 | "dependencies": {} 5 | } 6 | -------------------------------------------------------------------------------- /admin/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /admin/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /admin/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /admin/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /admin/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/public/apple-touch-icon.png -------------------------------------------------------------------------------- /admin/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/public/favicon.ico -------------------------------------------------------------------------------- /admin/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /admin/scripts/wait-for.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # version 0.1 4 | # 5 | 6 | retries=${3:-20} 7 | 8 | if [ -z "$1" ]; then 9 | echo "host not specified" 10 | exit 1 11 | fi 12 | 13 | if [ -z "$2" ]; then 14 | echo "port not specified" 15 | exit 1 16 | fi 17 | 18 | try=0 19 | 20 | while ! echo 1 2>/dev/null > /dev/tcp/$1/$2; 21 | do 22 | if [ $try -ge $retries ]; then 23 | echo "max retries (${retries}) exceeded, aborting" 24 | break 25 | fi 26 | echo "waiting for ${1}:${2} to be ready..."; sleep 3; 27 | try=`expr $try + 1` 28 | done 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /admin/spec/models/computing_unit_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe ComputingUnit, type: :model do 4 | pending "add some examples to (or delete) #{__FILE__}" 5 | end 6 | -------------------------------------------------------------------------------- /admin/spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require File.expand_path('../config/environment', __dir__) 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | puts e.to_s.strip 31 | exit 1 32 | end 33 | RSpec.configure do |config| 34 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 35 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 36 | 37 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 38 | # examples within a transaction, remove the following line or assign false 39 | # instead of true. 40 | config.use_transactional_fixtures = true 41 | 42 | # You can uncomment this line to turn off ActiveRecord support entirely. 43 | # config.use_active_record = false 44 | 45 | # RSpec Rails can automatically mix in different behaviours to your tests 46 | # based on their file location, for example enabling you to call `get` and 47 | # `post` in specs under `spec/controllers`. 48 | # 49 | # You can disable this behaviour by removing the line below, and instead 50 | # explicitly tag your specs with their type, e.g.: 51 | # 52 | # RSpec.describe UsersController, type: :controller do 53 | # # ... 54 | # end 55 | # 56 | # The different available types are documented in the features, such as in 57 | # https://relishapp.com/rspec/rspec-rails/docs 58 | config.infer_spec_type_from_file_location! 59 | 60 | # Filter lines from Rails gems in backtraces. 61 | config.filter_rails_from_backtrace! 62 | # arbitrary gems may also be filtered via: 63 | # config.filter_gems_from_backtrace("gem name") 64 | end 65 | -------------------------------------------------------------------------------- /admin/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | =begin 50 | # This allows you to limit a spec run to individual examples or groups 51 | # you care about by tagging them with `:focus` metadata. When nothing 52 | # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | config.filter_run_when_matching :focus 56 | 57 | # Allows RSpec to persist some state between runs in order to support 58 | # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # you configure your source control system to ignore this file. 60 | config.example_status_persistence_file_path = "spec/examples.txt" 61 | 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 67 | config.disable_monkey_patching! 68 | 69 | # Many RSpec users commonly either run the entire suite or an individual 70 | # file, and it's useful to allow more verbose output when running an 71 | # individual spec file. 72 | if config.files_to_run.one? 73 | # Use the documentation formatter for detailed output, 74 | # unless a formatter has already been configured 75 | # (e.g. via a command-line flag). 76 | config.default_formatter = "doc" 77 | end 78 | 79 | # Print the 10 slowest examples and example groups at the 80 | # end of the spec run, to help surface which specs are running 81 | # particularly slow. 82 | config.profile_examples = 10 83 | 84 | # Run specs in random order to surface order dependencies. If you find an 85 | # order dependency and want to debug it, you can fix the order by providing 86 | # the seed, which is printed after each run. 87 | # --seed 1234 88 | config.order = :random 89 | 90 | # Seed global randomization in this process using the `--seed` CLI option. 91 | # Setting this allows you to use `--seed` to deterministically reproduce 92 | # test failures related to randomization by passing the same `--seed` value 93 | # as the one that triggered the failure. 94 | Kernel.srand config.seed 95 | =end 96 | end 97 | -------------------------------------------------------------------------------- /admin/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/storage/.keep -------------------------------------------------------------------------------- /admin/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/tmp/.keep -------------------------------------------------------------------------------- /admin/vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/admin/vendor/.keep -------------------------------------------------------------------------------- /cms.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/cms.jpg -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | edge: # front end 5 | build: 6 | context: . 7 | volumes: 8 | - "./edge.conf:/usr/local/openresty/nginx/conf/nginx.conf" 9 | - "./src/:/lua/src/" 10 | depends_on: 11 | - admin 12 | - ingest 13 | links: 14 | - admin 15 | - ingest 16 | ports: 17 | - "8080:8080" 18 | - "9090:9090" 19 | 20 | ingest: # back end 21 | build: 22 | context: . 23 | dockerfile: Dockerfile.ingest 24 | volumes: 25 | - "./ingest.conf:/config/nginx.conf" 26 | ports: 27 | - "1935:1935" 28 | 29 | origin: # simulating a live transmission 30 | image: jrottenberg/ffmpeg:4.1 31 | entrypoint: bash 32 | command: "/scripts/ffmpeg_colorbar.sh" 33 | volumes: 34 | - "./:/scripts" 35 | environment: 36 | - INGEST_HOST=ingest 37 | depends_on: 38 | - ingest 39 | links: 40 | - ingest 41 | 42 | admin: 43 | build: ./admin 44 | command: bash -c "./scripts/wait-for.sh db 3306 && rails db:migrate && rails s -p 3000 -b '0.0.0.0'" 45 | volumes: 46 | - ./admin:/myapp 47 | ports: 48 | - "3000:3000" 49 | depends_on: 50 | - db 51 | environment: 52 | - DB_HOST=db 53 | - DB_USER=root 54 | - DB_PASSWORD=secret 55 | - DB_NAME=admin 56 | 57 | db: 58 | image: mysql:5.6 59 | volumes: 60 | - "./mysqldata:/var/lib/mysql" 61 | environment: 62 | - MYSQL_ROOT_PASSWORD=secret 63 | - MYSQL_DATABASE=admin 64 | 65 | lint: 66 | command: bash -c "luacheck -q ." 67 | build: 68 | context: . 69 | dockerfile: Dockerfile.test 70 | volumes: 71 | - ".:/lua/" 72 | working_dir: "/lua" 73 | 74 | -------------------------------------------------------------------------------- /edge.conf: -------------------------------------------------------------------------------- 1 | events { 2 | worker_connections 1024; 3 | } 4 | worker_processes 2; 5 | 6 | error_log stderr; 7 | 8 | http { 9 | resolver 127.0.0.11 ipv6=off; 10 | 11 | lua_package_path "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/lua/src/?.lua"; 12 | lua_package_cpath "/usr/local/openresty/lualib/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;"; 13 | 14 | init_by_lua_block { 15 | edge_computing = require "resty-edge-computing" 16 | require "cjson" 17 | require 'resty.http' 18 | } 19 | 20 | init_worker_by_lua_block { 21 | edge_computing.interval = 5 -- polling seconds 22 | edge_computing.workers_max_jitter = 5 -- jitter among the workers seconds 23 | edge_computing.api_uri = "http://admin:3000/admin/computing_units.json" -- API uri 24 | edge_computing.api_timeout = 2 -- API timeout seconds 25 | 26 | edge_computing.spawn_poller() 27 | } 28 | 29 | upstream backend { 30 | server ingest; 31 | } 32 | 33 | proxy_cache_path /tmp levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=10m use_temp_path=off; 34 | server { 35 | listen 8080; 36 | 37 | location / { 38 | proxy_cache my_cache; 39 | proxy_cache_lock on; 40 | 41 | proxy_cache_lock_timeout 2s; 42 | proxy_cache_use_stale error timeout updating invalid_header; 43 | 44 | proxy_ignore_headers Cache-Control; 45 | proxy_cache_valid any 2s; 46 | 47 | add_header X-Cache-Status $upstream_cache_status; 48 | proxy_pass http://backend; 49 | } 50 | 51 | rewrite_by_lua_block { 52 | local status, errs = edge_computing.execute() 53 | if errs ~= {} then 54 | for _, err in ipairs(errs) do 55 | ngx.log(ngx.ERR, " edge_computing.execute error ", err) 56 | end 57 | end 58 | } 59 | 60 | access_by_lua_block { 61 | local status, errs = edge_computing.execute() 62 | if errs ~= {} then 63 | for _, err in ipairs(errs) do 64 | ngx.log(ngx.ERR, " edge_computing.execute error ", err) 65 | end 66 | end 67 | } 68 | 69 | header_filter_by_lua_block { 70 | local status, errs = edge_computing.execute() 71 | if errs ~= {} then 72 | for _, err in ipairs(errs) do 73 | ngx.log(ngx.ERR, " edge_computing.execute error ", err) 74 | end 75 | end 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ffmpeg_colorbar.sh: -------------------------------------------------------------------------------- 1 | ffmpeg -hide_banner -re -f lavfi -i 'testsrc2=size=1280x720:rate=60,format=yuv420p' \ 2 | -f lavfi -i 'sine=frequency=440:sample_rate=48000:beep_factor=4' \ 3 | -f lavfi -i 'sine=frequency=440:sample_rate=48000:beep_factor=4' \ 4 | -c:v libx264 -preset ultrafast -tune zerolatency -profile:v high \ 5 | -b:v 1400k -bufsize 2800k -x264opts keyint=120:min-keyint=120:scenecut=-1 \ 6 | -c:a aac -b:a 32k -filter_complex amerge -f flv rtmp://${INGEST_HOST}:1935/encoder/colorbar 7 | -------------------------------------------------------------------------------- /ingest.conf: -------------------------------------------------------------------------------- 1 | daemon off; 2 | 3 | events { 4 | worker_connections 1024; 5 | } 6 | 7 | error_log stderr; 8 | 9 | rtmp { 10 | server { 11 | listen 1935; 12 | chunk_size 4000; 13 | 14 | application encoder { 15 | live on; 16 | 17 | exec ffmpeg -i rtmp://localhost:1935/encoder/$name 18 | -c:a libfdk_aac -b:a 128k -c:v libx264 -x264opts keyint=120:min-keyint=120:scenecut=-1 -tune zerolatency -b:v 750k -f flv -g 120 -r 60 -s 640x360 -preset superfast rtmp://localhost:1935/hls/$name_360p878kbs 19 | -c:a libfdk_aac -b:a 128k -c:v libx264 -x264opts keyint=120:min-keyint=120:scenecut=-1 -tune zerolatency -b:v 400k -f flv -g 120 -r 60 -s 426x240 -preset superfast rtmp://localhost:1935/hls/$name_240p528kbs 20 | -c:a libfdk_aac -b:a 128k -c:v libx264 -x264opts keyint=120:min-keyint=120:scenecut=-1 -tune zerolatency -b:v 200k -f flv -g 120 -r 60 -s 426x240 -preset superfast rtmp://localhost:1935/hls/$name_240p264kbs; 21 | } 22 | 23 | application hls { 24 | live on; 25 | hls on; 26 | hls_fragment_slicing aligned; 27 | hls_fragment_naming timestamp; 28 | hls_fragment 4s; 29 | hls_playlist_length 600s; 30 | hls_path /data/hls; 31 | hls_nested on; 32 | hls_cleanup on; 33 | 34 | hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360; 35 | hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240; 36 | hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240; 37 | } 38 | } 39 | } 40 | 41 | http { 42 | server { 43 | listen 80; 44 | location /hls { 45 | types { 46 | application/vnd.apple.mpegurl m3u8; 47 | video/mp2t ts; 48 | } 49 | root /data; 50 | add_header Cache-Control no-cache; 51 | add_header Access-Control-Allow-Origin * always; 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /mysqldata/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandromoreira/edge-computing-resty/bcc796610e2c07a3926271b74da096c2949f1d04/mysqldata/.gitkeep -------------------------------------------------------------------------------- /src/resty-edge-computing.lua: -------------------------------------------------------------------------------- 1 | local edge_computing = {} 2 | local http = require 'resty.http' 3 | local json = require "cjson" 4 | 5 | 6 | --- computing unit --- 7 | --- cu = {} 8 | --- cu["id"] = "coding id" 9 | --- cu["phase"] = "phase" 10 | --- cu["code"] = function_code 11 | --- cu["sampling"] = 50 12 | --- computing unit --- 13 | 14 | edge_computing.cus = {} 15 | edge_computing.ready = false 16 | edge_computing.interval = 20 -- seconds 17 | edge_computing.workers_max_jitter = 5 -- seconds 18 | edge_computing.phases = { 19 | "init", "init_worker", "ssl_cert", "ssl_session_fetch", "ssl_session_store", "set", 20 | "rewrite", "balancer", "access", "content", "header_filter", "body_filter", "log", 21 | "timer" 22 | } 23 | 24 | edge_computing.api_uri = "http://localhost:9090/computing_units.json" 25 | edge_computing.api_timeout = 1 26 | 27 | edge_computing.spawn_poller = function() 28 | -- starting luajit entropy per worker 29 | math.randomseed(ngx.time() + ngx.worker.pid()) 30 | 31 | -- initializating cus 32 | edge_computing.reset_cus() 33 | 34 | local jitter_seconds = math.random(1, edge_computing.workers_max_jitter) 35 | local worker_interval_seconds = edge_computing.interval + jitter_seconds 36 | 37 | -- scheduling recurring a polling 38 | ngx.timer.every(worker_interval_seconds, edge_computing.fetch_code) 39 | 40 | -- polling right away (in the next nginx "cicle") 41 | -- to avoid all the workers to go downstream we add a jitter of 60s 42 | ngx.timer.at(0 + math.random(0, 60), edge_computing.fetch_code) 43 | end 44 | 45 | edge_computing.reset_cus = function() 46 | edge_computing.cus = {} 47 | for _, phase in ipairs(edge_computing.phases) do 48 | edge_computing.cus[phase] = {} 49 | end 50 | end 51 | 52 | edge_computing.fetch_code = function() 53 | local httpc = http.new() 54 | httpc:set_timeout(edge_computing.api_timeout * 1000) 55 | local res_api, err_api = httpc:request_uri(edge_computing.api_uri) 56 | 57 | if err_api ~= nil and type(err_api) == "string" and err_api ~= "" then 58 | return "error" 59 | end 60 | 61 | if res_api.status ~= 200 then 62 | return "error" 63 | end 64 | 65 | local admin_response, err = json.decode(res_api.body) 66 | if err ~= nil then 67 | return "error" 68 | end 69 | 70 | edge_computing.reset_cus() 71 | for _, coding_unit in ipairs(admin_response) do 72 | local function_code, _ = edge_computing.loadstring(coding_unit.code) 73 | local cu = {} 74 | cu["id"] = coding_unit.id 75 | cu["phase"] = coding_unit.phase 76 | cu["code"] = function_code 77 | cu["sampling"] = coding_unit.sampling 78 | table.insert(edge_computing.cus[cu["phase"]], cu) 79 | end 80 | edge_computing.log("all code was processed") 81 | end 82 | 83 | -- lua phases 84 | -- https://github.com/openresty/lua-nginx-module#ngxget_phase 85 | edge_computing.phase = function() 86 | return ngx.get_phase() 87 | end 88 | 89 | edge_computing.log = function(msg) 90 | ngx.log(ngx.ERR, " :: edge_computing :: [" .. ngx.worker.id() .. "] " .. msg) 91 | end 92 | 93 | edge_computing.should_skip = function(n) 94 | return n < math.random(100) 95 | end 96 | 97 | -- returns status and computing units runtime errors 98 | -- it can be true and still have some runtime errors 99 | edge_computing.execute = function() 100 | local phase = edge_computing.phase() 101 | local runtime_errors = {} 102 | 103 | for _, cu in ipairs(edge_computing.cus[phase]) do 104 | if cu["sampling"] ~= nil and cu["sampling"] ~= "" then 105 | local sampling = tonumber(cu["sampling"]) 106 | local should_skip = edge_computing.should_skip(sampling) 107 | if should_skip then goto continue end 108 | end 109 | 110 | local status, ret = pcall(cu["code"], {ctx="anything"}) 111 | 112 | if not status then 113 | table.insert(runtime_errors, "execution of cu id=" .. cu["id"] .. ", failed due err=" .. ret) 114 | end 115 | ::continue:: 116 | end 117 | 118 | return true, runtime_errors 119 | end 120 | 121 | edge_computing.loadstring = function(str_code) 122 | -- API wrapper 123 | local api_fun, err = loadstring("return function (ctx) " .. str_code .. " end") 124 | if api_fun then 125 | return api_fun() 126 | else 127 | return api_fun, err 128 | end 129 | end 130 | 131 | return edge_computing 132 | --------------------------------------------------------------------------------