diff --git a/.env b/.env deleted file mode 100644 index 2fc80e3a4..000000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -PORT=3000 diff --git a/.gcloudignore b/.gcloudignore new file mode 100644 index 000000000..1ee4d0dca --- /dev/null +++ b/.gcloudignore @@ -0,0 +1,43 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile ~/.gitignore_global + +# Ignore bundler config +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 + +# Ignore all logfiles and tempfiles. +/tmp +*.swp +*.swo +*~ +.ruby-version +.DS_Store +log/ +tmp/* +tmp/**/* +coverage* +public/warpables/* +public/system/* +public/warps/* +public/tms/* +db/schema.rb +*.db +config/database.yml +config/amazon_s3.yml +config/initializers/recaptcha.rb +config/config.yml +config/initializers/site_keys.rb +vendor/bundle +app/assets/bower_components +app/assets/node_modules +public/assets +public/lib +node_modules +todo.txt +.sass-cache +.git/ diff --git a/.gitignore b/.gitignore index 5c03ac56c..5866d40c4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ # Ignore bundler config /.bundle +# avoid committing your secrets inadvertly +./app.yaml + # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/.travis.yml b/.travis.yml index cee7cba88..adbcc79a3 100755 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,10 @@ env: - RAILS_ENV=test - CI=true - TRAVIS=true + - DB_HOST='127.0.0.1' + - DB_USER='mapknitter' + - DB_PASS='mapknitter' + - DB_NAME='mapknitter' jobs: include: diff --git a/Dockerfile b/Dockerfile index 3af3f9a22..b047667b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,4 +51,6 @@ RUN git config --global url."https://".insteadOf git:// COPY . /app/ WORKDIR /app +RUN bundle install + CMD [ "sh", "/app/start.sh" ] diff --git a/Gemfile b/Gemfile index cda9fb459..639ea8b18 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ group :dependencies do gem 'open_id_authentication' gem 'RubyInline', '~> 3.12.5' gem 'paperclip', '~> 6.1.0' - gem 'bootsnap', '~> 1.4.5' + gem 'bootsnap', '~> 1.4.6' gem 'turbolinks', '~> 5' gem 'mini_magick', '~> 4.8' gem 'puma', '~> 4.3.3' diff --git a/Gemfile.lock b/Gemfile.lock index f240f273c..7497cfb0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,45 +4,45 @@ GEM RubyInline (3.12.5) ZenTest (~> 4.3) ZenTest (4.12.0) - action-cable-testing (0.6.0) + action-cable-testing (0.6.1) actioncable (>= 5.0) - actioncable (5.2.4) - actionpack (= 5.2.4) + actioncable (5.2.4.2) + actionpack (= 5.2.4.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4) - actionpack (= 5.2.4) - actionview (= 5.2.4) - activejob (= 5.2.4) + actionmailer (5.2.4.2) + actionpack (= 5.2.4.2) + actionview (= 5.2.4.2) + activejob (= 5.2.4.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4) - actionview (= 5.2.4) - activesupport (= 5.2.4) - rack (~> 2.0) + actionpack (5.2.4.2) + actionview (= 5.2.4.2) + activesupport (= 5.2.4.2) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4) - activesupport (= 5.2.4) + actionview (5.2.4.2) + activesupport (= 5.2.4.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4) - activesupport (= 5.2.4) + activejob (5.2.4.2) + activesupport (= 5.2.4.2) globalid (>= 0.3.6) - activemodel (5.2.4) - activesupport (= 5.2.4) - activerecord (5.2.4) - activemodel (= 5.2.4) - activesupport (= 5.2.4) + activemodel (5.2.4.2) + activesupport (= 5.2.4.2) + activerecord (5.2.4.2) + activemodel (= 5.2.4.2) + activesupport (= 5.2.4.2) arel (>= 9.0) - activestorage (5.2.4) - actionpack (= 5.2.4) - activerecord (= 5.2.4) + activestorage (5.2.4.2) + actionpack (= 5.2.4.2) + activerecord (= 5.2.4.2) marcel (~> 0.3.1) - activesupport (5.2.4) + activesupport (5.2.4.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -52,33 +52,33 @@ GEM ansi (1.5.0) arel (9.0.0) ast (2.4.0) - autoprefixer-rails (9.7.3) + autoprefixer-rails (9.7.6) execjs - aws-eventstream (1.0.3) - aws-partitions (1.258.0) - aws-sdk-core (3.86.0) - aws-eventstream (~> 1.0, >= 1.0.2) + aws-eventstream (1.1.0) + aws-partitions (1.303.0) + aws-sdk-core (3.94.0) + aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.27.0) + aws-sdk-kms (1.30.0) aws-sdk-core (~> 3, >= 3.71.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.60.1) + aws-sdk-s3 (1.63.0) aws-sdk-core (~> 3, >= 3.83.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) - aws-sigv4 (1.1.0) + aws-sigv4 (1.1.2) aws-eventstream (~> 1.0, >= 1.0.2) bindex (0.8.1) - bootsnap (1.4.5) + bootsnap (1.4.6) msgpack (~> 1.0) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) builder (3.2.4) byebug (11.0.1) - capybara (3.29.0) + capybara (3.32.1) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -93,16 +93,16 @@ GEM simplecov url coderay (1.1.2) - concurrent-ruby (1.1.5) - crass (1.0.5) + concurrent-ruby (1.1.6) + crass (1.0.6) docile (1.3.2) erubi (1.9.0) execjs (2.7.0) faker (2.6.0) i18n (>= 1.6, < 1.8) - faraday (0.15.4) + faraday (1.0.1) multipart-post (>= 1.2, < 3) - ffi (1.11.3) + ffi (1.12.2) friendly_id (5.3.0) activerecord (>= 4.0.0) geokit (1.13.1) @@ -110,14 +110,14 @@ GEM geokit (>= 1.5.0) globalid (0.4.2) activesupport (>= 4.2.0) - httparty (0.17.3) + httparty (0.18.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.7.0) + i18n (1.7.1) concurrent-ruby (~> 1.0) image_science (1.3.0) RubyInline (~> 3.9) - jaro_winkler (1.5.3) + jaro_winkler (1.5.4) jmespath (1.4.0) jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) @@ -127,43 +127,43 @@ GEM execjs multi_json (>= 1.3) rake - json (2.2.0) + json (2.3.0) libv8 (7.3.492.27.1) libxml-ruby (3.1.0) listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.4.0) + loofah (2.5.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - method_source (0.9.2) - mime-types (3.3) + method_source (1.0.0) + mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2019.1009) - mimemagic (0.3.3) - mini_magick (4.9.5) + mimemagic (0.3.4) + mini_magick (4.10.1) mini_mime (1.0.2) mini_portile2 (2.4.0) - mini_racer (0.2.8) - libv8 (>= 6.9.411) + mini_racer (0.2.10) + libv8 (> 7.3) minitest (5.14.0) minitest-reporters (1.4.2) ansi builder minitest (>= 5.0) ruby-progressbar - msgpack (1.3.1) - multi_json (1.13.1) + msgpack (1.3.3) + multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) mysql2 (0.5.3) net-http-persistent (2.9.4) nio4r (2.5.2) - nokogiri (1.10.7) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) oa-core (0.3.2) oa-openid (0.3.2) @@ -181,22 +181,22 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - parallel (1.17.0) - parser (2.6.4.0) + parallel (1.19.1) + parser (2.7.1.1) ast (~> 2.4.0) passenger (6.0.4) rack rake (>= 0.8.1) - popper_js (1.14.5) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) + popper_js (1.16.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.1) + public_suffix (4.0.4) puma (4.3.3) nio4r (~> 2.0) - rack (2.1.1) + rack (2.2.2) rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) @@ -205,18 +205,18 @@ GEM rack_session_access (0.2.0) builder (>= 2.0.0) rack (>= 1.0.0) - rails (5.2.4) - actioncable (= 5.2.4) - actionmailer (= 5.2.4) - actionpack (= 5.2.4) - actionview (= 5.2.4) - activejob (= 5.2.4) - activemodel (= 5.2.4) - activerecord (= 5.2.4) - activestorage (= 5.2.4) - activesupport (= 5.2.4) + rails (5.2.4.2) + actioncable (= 5.2.4.2) + actionmailer (= 5.2.4.2) + actionpack (= 5.2.4.2) + actionview (= 5.2.4.2) + activejob (= 5.2.4.2) + activemodel (= 5.2.4.2) + activerecord (= 5.2.4.2) + activestorage (= 5.2.4.2) + activesupport (= 5.2.4.2) bundler (>= 1.3.0) - railties (= 5.2.4) + railties (= 5.2.4.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.4) actionpack (>= 5.0.1.x) @@ -228,23 +228,23 @@ GEM rails-html-sanitizer (1.3.0) loofah (~> 2.3) rails-perftest (0.0.7) - railties (5.2.4) - actionpack (= 5.2.4) - activesupport (= 5.2.4) + railties (5.2.4.2) + actionpack (= 5.2.4.2) + activesupport (= 5.2.4.2) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rainbow (3.0.0) rake (12.3.3) rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rb-inotify (0.10.1) ffi (~> 1.0) rdiscount (2.2.0.1) recaptcha (5.0.0) json redcarpet (3.5.0) - regexp_parser (1.6.0) - request_store (1.4.1) + regexp_parser (1.7.0) + request_store (1.5.0) rack (>= 1.4) right_aws_api (0.3.5) right_cloud_api_base (>= 0.2.6) @@ -264,18 +264,18 @@ GEM rubocop-performance (1.3.0) rubocop (>= 0.68.0) ruby-hmac (0.4.0) - ruby-openid (2.9.1) + ruby-openid (2.9.2) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) - ruby-prof (1.2.0) + ruby-prof (1.3.2) ruby-progressbar (1.10.1) - rubyzip (2.0.0) + rubyzip (2.3.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sassc (2.2.0) + sassc (2.3.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -283,19 +283,18 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (3.142.6) + selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sentry-raven (2.11.1) - faraday (>= 0.7.6, < 1.0) - simplecov (0.17.1) + sentry-raven (3.0.0) + faraday (>= 1.0) + simplecov (0.18.5) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - skylight (4.2.0) - skylight-core (= 4.2.0) - skylight-core (4.2.0) + simplecov-html (~> 0.11) + simplecov-html (0.12.2) + skylight (4.3.0) + skylight-core (= 4.3.0) + skylight-core (4.3.0) activesupport (>= 4.2.0) spring (2.1.0) spring-watcher-listen (2.0.1) @@ -311,19 +310,19 @@ GEM sqlite3 (1.4.2) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (0.20.3) + thor (1.0.1) thread_safe (0.3.6) - tilt (2.0.9) + tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.5) + tzinfo (1.2.7) thread_safe (~> 0.1) - tzinfo-data (1.2019.2) + tzinfo-data (1.2020.1) tzinfo (>= 1.0.0) uglifier (4.1.20) execjs (>= 0.3.0, < 3) - unicode-display_width (1.6.0) + unicode-display_width (1.6.1) url (0.3.2) web-console (3.7.0) actionview (>= 5.0) @@ -347,7 +346,7 @@ DEPENDENCIES action-cable-testing autoprefixer-rails (~> 9.7.3) aws-sdk-s3 (~> 1) - bootsnap (~> 1.4.5) + bootsnap (~> 1.4.6) bootstrap-sass byebug (~> 11.0.1) capybara diff --git a/Makefile b/Makefile index 6425efa7d..785044a78 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ export COMPOSE_HTTP_TIMEOUT=360 +export COMPOSE_PROJECT_NAME +export PORT define wait_for_container @while ! docker-compose logs web | grep "web server started"; do\ @@ -10,7 +12,9 @@ endef build: cp config/database.yml.example config/database.yml cp config/config.yml.example config/config.yml + cp config/initializers/recaptcha.rb.example config/initializers/recaptcha.rb cp db/schema.rb.example db/schema.rb + docker-compose down --remove-orphans docker-compose build deploy-container: diff --git a/Procfile b/Procfile index 841da4133..b015561fd 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -passenger: passenger start +passenger: passenger start --port $PORT puma: puma -C config/puma.rb diff --git a/app.yaml b/app.yaml new file mode 100644 index 000000000..76a354b38 --- /dev/null +++ b/app.yaml @@ -0,0 +1,25 @@ +env: flex +runtime: custom + +manual_scaling: + instances: 1 + +resources: + cpu: 1 + memory_gb: 4 +env_variables: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + DB_USER: mapknitter + DB_PASS: mapknitter + DB_NAME: mapknitter + DB_HOST: localhost + DB_SOCKET: + RAILS_ENV: production + RECAPTCHA_KEY: + RECAPTCHA_SITE_KEY: + SECRET_KEY_BASE: + SENTRY_DSN: + +beta_settings: + cloud_sql_instances: diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 000000000..a3bd75ed7 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,14 @@ +steps: +- name: 'docker/compose:1.19.0' + args: ['up', '-d'] +- name: 'gcr.io/cloud-builders/docker' + args: ['tag', 'mapknitter-dev:latest', 'gcr.io/public-lab/mapknitter-dev'] +# Push it to GCR. +- name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/mapknitter-dev'] +# Deploy your Flex app from the image in GCR. +#- name: 'gcr.io/cloud-builders/gcloud' +# args: ['app', 'deploy', 'app.yaml', '--image-url=gcr.io/$PROJECT_ID/mapknitter-dev'] +# Note that this build pushes this image. +images: ['gcr.io/$PROJECT_ID/mapknitter-dev'] +timeout: 2200s diff --git a/config/database.yml.example b/config/database.yml.example index 6f196c70d..17eb65c53 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -14,10 +14,12 @@ production: adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - host: <%= ENV.fetch("MYSQL_HOST") { '127.0.0.1' } %> - username: mapknitter - password: mapknitter - database: mapknitter + host: <%= ENV['DB_HOST'] || 'db' %> + username: <%= ENV['DB_USER'] || 'mapknitter' %> + password: <%= ENV['DB_PASS'] || 'mapknitter' %> + database: <%= ENV['DB_NAME'] || 'mapknitter' %> + socket: <%= ENV['DB_SOCKET'] %> + timeout: 5000 test: <<: *default diff --git a/config/routes.rb b/config/routes.rb index 5d7240e9b..dc8370d06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -120,4 +120,5 @@ # See how all your routes lay out with 'rails routes' + get '/warps/:map/:file(.:format)', to: redirect('https://archive.publiclab.org/warps/%{map}/%{file}.%{format}') end diff --git a/db/migrate/20191214062147_add_index_for_warpable_map_id.rb b/db/migrate/20191214062147_add_index_for_warpable_map_id.rb index 2e0c62688..4eb1d67a4 100644 --- a/db/migrate/20191214062147_add_index_for_warpable_map_id.rb +++ b/db/migrate/20191214062147_add_index_for_warpable_map_id.rb @@ -1,4 +1,4 @@ -class AddIndexForWarpableMapId < ActiveRecord::Migration +class AddIndexForWarpableMapId < ActiveRecord::Migration[5.2] def up add_index "warpables", ["map_id"], :name => "index_warpables_on_map_id" end diff --git a/docker-compose.yml b/docker-compose.yml index 39445612c..e12aff86f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: build: . ulimits: core: 0 + image: mapknitter-dev env_file: - mapknitter.env volumes: @@ -18,7 +19,7 @@ services: - bundle_cache:/usr/local/bundle - yarn_cache:/app/node_modules/ ports: - - $PORT:3000 + - ${PORT:-3000}:${PORT:-3000} depends_on: - db diff --git a/script/redirect.py b/script/redirect.py new file mode 100644 index 000000000..a221f4762 --- /dev/null +++ b/script/redirect.py @@ -0,0 +1,15 @@ +from google.appengine.ext import webapp +from google.appengine.ext.webapp.util import run_wsgi_app + +class AllHandler(webapp.RequestHandler): + def get(self): + self.redirect("https://tycho.media.mit.edu/warps", True) + +application = webapp.WSGIApplication([('/.*', AllHandler)]) + +def main(): + run_wsgi_app(application) + +if __name__ == "__main__": + main() + diff --git a/start.sh b/start.sh index 8bae2f5a7..d5f24df31 100755 --- a/start.sh +++ b/start.sh @@ -2,6 +2,12 @@ pidfile=/app/tmp/pids/server.pid +cp config/database.yml.example config/database.yml +cp config/config.yml.example config/config.yml +cp db/schema.rb.example db/schema.rb +mkdir -p tmp/pids +rm -rf tmp/cache/bootsnap* + if [ ! -f "./config/initializers/recaptcha.rb" ]; then echo -e "\e[33mWARNING\e[0m: You haven't configured recaptcha!" echo -e "\e[94mRead More\e[0m: https://github.com/publiclab/mapknitter#installation-steps" @@ -22,7 +28,7 @@ else bump_database fi -bundle exec rails assets:precompile +rake assets:precompile if [ -f $pidfile ] ; then >&2 echo 'Server PID file already exists. Removing it...'; diff --git a/yarn.lock b/yarn.lock index 2f3ee7c78..da0a906cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1036,14 +1036,6 @@ lazy-cache@^1.0.3: jquery "^3.2.1" leaflet "^1.3.3" -"leaflet-blurred-location@git://github.com/publiclab/leaflet-blurred-location.git#main": - version "1.6.0" - resolved "git://github.com/publiclab/leaflet-blurred-location.git#ef66dcb768094680e92d4f972b68f18cd4db6ccc" - dependencies: - haversine-distance "^1.1.4" - jquery "^3.2.1" - leaflet "^1.3.3" - leaflet-dist@vperron/leaflet-dist#0.7.x: version "0.0.0" resolved "https://codeload.github.com/vperron/leaflet-dist/tar.gz/2ec7a0846eaecdce1321d92b3c45c74f4fd08dd3"