From 9fe8c70ea6de55360126588a256856125b98a908 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Wed, 22 Dec 2021 22:45:37 -0500 Subject: [PATCH] This successfully builds a working bikebike rails app with Docker! Former-commit-id: 0a55db70c4049243d5eb6c164698c93f49b1746a --- .gitattributes | 1 + .gitignore | 4 +- Dockerfile | 43 +++++++++++++++ Gemfile | 16 +++--- README.md | 11 ++++ app/assets/config/manifest.js | 4 ++ app/helpers/i18n_helper.rb | 8 +-- app/mailers/user_mailer.rb | 6 +-- bumbleberry-css.tar.gz | 3 ++ config/environments/production.rb | 19 ++++--- docker-compose.build | 12 +++++ docker-compose.yml | 89 +++++++++++++++++++++++++++++++ entrypoint.sh | 8 +++ 13 files changed, 199 insertions(+), 25 deletions(-) create mode 100644 .gitattributes create mode 100644 Dockerfile create mode 100644 app/assets/config/manifest.js create mode 100644 bumbleberry-css.tar.gz create mode 100755 docker-compose.build create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cfbd406 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.tar.gz filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/.gitignore b/.gitignore index 89a61b4..afa6f76 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,9 @@ !.openshift *~ - +# Docker.gitignore +.env +bike_bike_advanced_environment # OSX.gitignore .DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23f4071 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +############ +# BikeBike # +############ + + +FROM ruby:2.5 +MAINTAINER Jonathan Rosenbaum + +##RUN git clone https://github.com/fspc/BikeBikeBike.git /app/BikeBike +COPY . /app/BikeBike + +RUN apt-get update && apt-get install -y nodejs postgresql-client + +# Note: phantomjs has been deprecated in favor of headless chrome +WORKDIR /app/BikeBike + +# COPY changes/Gemfile . +# Use DATABASE_URL env variable instead, although it takes precedence, regardless +# COPY database.yml ./config/database.yml +RUN bundle install + +RUN mkdir -p public/stylesheets/application -p public/stylesheets/web-fonts && tar xvfz bumbleberry-css.tar.gz -C public/stylesheets/application && tar xvfz bumbleberry-css.tar.gz -C public/stylesheets/web-fonts + +#RUN gem install json -v '1.8.6' +#RUN gem install activesupport -v '4.2.0' +#RUN gem install mini_portile2 -v '2.6.1' +#RUN gem install racc -v '1.6.0' +#RUN gem install actionview -v '4.2.0' + +# Gem::LoadError: You have already activated rake 12.3.3, but your Gemfile requires rake 11.1.2. Prepending `bundle exec` to your command may solve this. +# Do this with docker-compose +# RUN rake db:create +# RUN rake db:migrate + + +# Add a script to be executed every time the container starts. +COPY entrypoint.sh /usr/bin/ +RUN chmod +x /usr/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 3000 + +# Configure the main process to run when running the image +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/Gemfile b/Gemfile index 89c16d4..8597961 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ source 'http://rubygems.org' -gem 'rails', '4.2.0' -gem 'pg' -gem 'rake', '11.1.2' -gem 'ruby_dep', '1.3.1' # Lock at 1.3.1 since 1.4 requires ruby 2.5. We should unlock once we upgrade the ruby version on our server +gem 'rails', '4.2.8' +gem 'pg', '0.21.0' +gem 'rake', '12.3.3' +gem 'ruby_dep', '1.4' # Lock at 1.3.1 since 1.4 requires ruby 2.5. We should unlock once we upgrade the ruby version on our server gem 'rack-mini-profiler' @@ -41,17 +41,18 @@ gem 'sitemap_generator' gem 'sass-json-vars' gem 'redcarpet' gem 'to_spreadsheet', git: 'https://github.com/glebm/to_spreadsheet.git' +gem 'net-ssh', '4.1.0' group :development do gem 'better_errors', '2.2.0' gem 'binding_of_caller' gem 'meta_request' - + gem 'capistrano', '~> 3.1' gem 'capistrano-rails', '~> 1.1' gem 'capistrano-faster-assets', '~> 1.0' - gem 'eventmachine', git: 'https://github.com/krzcho/eventmachine', :branch => 'master' + gem 'eventmachine', git: 'https://github.com/eventmachine/eventmachine', :branch => 'master' gem 'thin' gem 'rubocop', require: false gem 'haml-lint', require: false @@ -67,6 +68,7 @@ group :test do gem 'guard-cucumber' gem 'poltergeist' + gem 'capybara', '2.15.1' gem 'capybara-email' gem 'guard-rspec' gem 'factory_girl_rails' @@ -93,7 +95,7 @@ end platforms 'mswin', 'mingw' do gem 'tzinfo-data' - + group :test do gem 'wdm', '>= 0.1.0' gem 'win32console', require: false diff --git a/README.md b/README.md index 773b475..bc2de03 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,17 @@ | Development | [![Development Build Status](https://travis-ci.org/bikebike/BikeBike.svg?branch=development)](https://travis-ci.org/bikebike/BikeBike) | | Production | [![Production Build Status](https://travis-ci.org/bikebike/BikeBike.svg?branch=master)](https://travis-ci.org/bikebike/BikeBike) | +## About this Fork + +The Tech group for BikeBike!Everywhere! decided to utilize this conferencing/scheduling software for the next BikeBike. + +This repository creates a test environment so that we can test/fix issues before manually committing them to the live site. + +Instructions can be found in docker-compose.yml, and docker-compose.build. + + +## From bikebike/bikebike + This is the repository for the Bike!Bike! website. It can be found in development at [preview.bikebike.org](https://preview-en.bikebike.org/) and in production at [bikebike.org](https://bikebike.org/) Feel free to clone or fork the repository any time to start working on new features or fixes. To get help create an issue or contact Godwin: `goodgodwin` `@` `hotmail.com` any time. diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..aa822eb --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,4 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .scss +//= link_directory ../fonts diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index fa39abe..f6687f8 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -5,8 +5,8 @@ module I18nHelper url ||= current_path(true) return url if Rails.env.development? || Rails.env.test? - return "https://preview-#{locale.to_s}.bikebike.org#{url}" if Rails.env.preview? - "https://#{locale.to_s}.bikebike.org#{url}" + return "https://preview-#{locale.to_s}." + ENV['DEFAULT_URL'] + "#{url}" if Rails.env.preview? + "https://#{locale.to_s}." + ENV['DEFAULT_URL'] + "#{url}" end def current_path(relative = false) @@ -21,13 +21,13 @@ module I18nHelper return url_for(new_params) if relative subdomain = Rails.env.preview? ? "preview-#{locale.to_s}" : locale.to_s - url_for(new_params.merge(host: "#{subdomain}.bikebike.org")) + url_for(new_params.merge(host: "#{subdomain}." + ENV['DEFAULT_URL'])) end def canonical_url url = current_path return url if Rails.env.development? || Rails.env.test? - return "https://preview.bikebike.org#{url}" if Rails.env.preview? + return ENV['DEFAULT_URL'] + "#{url}" if Rails.env.preview? "https://bikebike.org#{url}" end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index da6cf38..300504c 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -6,7 +6,7 @@ class UserMailer < ActionMailer::Base before_filter :set_host - default from: "Bike!Bike! " + default from: "Bike!Bike! <" + ENV['SMTP_USER_NAME'] + ">" def email_confirmation(confirmation) @confirmation = EmailConfirmation.find_by_id(confirmation) if confirmation.present? @@ -172,9 +172,9 @@ class UserMailer < ActionMailer::Base private def set_host(*args) if Rails.env.production? - @host = "https://#{I18n.locale.to_s}.bikebike.org" + @host = "https://#{I18n.locale.to_s}." + ENV['DEFAULT_URL'] elsif Rails.env.preview? - @host = "https://preview-#{I18n.locale.to_s}.bikebike.org" + @host = "https://preview-#{I18n.locale.to_s}." + ENV['DEFAULT_URL'] else @host = UserMailer.default_url_options[:host] end diff --git a/bumbleberry-css.tar.gz b/bumbleberry-css.tar.gz new file mode 100644 index 0000000..e715d8d --- /dev/null +++ b/bumbleberry-css.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a35a36b336a9015ed0793d37ffd2caa6c2099b729b23b3b31467390f1e91635e +size 22906424 diff --git a/config/environments/production.rb b/config/environments/production.rb index 8f5eab4..ad7945d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -28,7 +28,7 @@ BikeBike::Application.configure do # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - #config.assets.compile = true + config.assets.compile = true # Generate digests for assets URLs. config.assets.digest = true @@ -46,8 +46,6 @@ BikeBike::Application.configure do # Set to :debug to see everything in the log. config.log_level = :info - config.assets.compile = false - # Prepend all log lines with the following tags. config.log_tags = [ :subdomain, :uuid ] @@ -61,7 +59,8 @@ BikeBike::Application.configure do # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets. - config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.json *.ttf *.otf *.woff *.woff2 *.svg *.json) + #config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.json *.ttf *.otf *.woff *.woff2 *.svg *.json) + config.assets.precompile = ["manifest.js"] # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. @@ -82,18 +81,18 @@ BikeBike::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: 'smtp.gmail.com', - domain: 'bikebike.org', - port: 587, + address: config.app_config['smtp_address'], + domain: config.app_config['smtp_domain'], + port: config.app_config['smtp_port'], authentication: :plain, enable_starttls_auto: true, openssl_verify_mode: 'none', - user_name: 'info@bikebike.org', - password: config.app_config['email_password'] + user_name: config.app_config['smtp_user_name'], + password: config.app_config['smtp_password'] } config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true I18n.config.language_detection_method = I18n::Config::DETECT_LANGUAGE_FROM_SUBDOMAIN - config.action_controller.default_url_options = { host: 'https://bikebike.org', trailing_slash: true } + config.action_controller.default_url_options = { host: config.app_config['default_url'], trailing_slash: true } Sidekiq::Extensions.enable_delay! end diff --git a/docker-compose.build b/docker-compose.build new file mode 100755 index 0000000..b36beb9 --- /dev/null +++ b/docker-compose.build @@ -0,0 +1,12 @@ +#!/bin/bash + +# This assume docker-compose build, which takes a long time and builds the image, has already happened, +# it should on up -d. +# Also, you may need to remove and create the external volumes again for the steps +# below to work correctly. +docker-compose up -d +docker-compose run bikebike rake db:setup +docker-compose run bikebike rake db:migrate +docker-compose run bikebike rake assets:precompile +docker-compose down +docker-compose up -d diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3324091 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,89 @@ +# BikeBike +# +# ENV DATABASE_URL string = https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING +# +# docker-compose up -d +# docker-compose run bikebike rake db:setup +# docker-compose run bikebike rake db:migrate +# docker-compose run bikebike rake assets:precompile +# docker-compose down +# docker-compose up +# +# don't do this because new sprockets and manifest.js isn't precompiling to *css, and breaks the container +# -- docker-compose run bikebike rake bumbleberry:update -- + + +version: '3' + +services: + + db: + container_name: bikebikebike-db + image: postgres:9.5 + ports: + - "5432" + restart: always + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + volumes: + - bikebikebike_db:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=password + - POSTGRES_USER=bike_bike + - POSTGRES_DB=bike_bike + + bikebike: + build: . + image: bikebikebike + container_name: bikebikebike + networks: + letsencrypt: + default: + command: /bin/sh -c "rm -f /app/BikeBike/tmp/pids/server.pid && rails server -e production -b '0.0.0.0'" + # Add environment values that are not in .env (environment:) below in the bike_bike_advanced_environment file + # Empty file ok, too, or just comment out this section + env_file: + - bike_bike_advanced_environment + # Add your own environment values in .env, or use the default ones + environment: + - PORT=3000 + - DATABASE_URL=${DATABASE_URL:-postgresql://bike_bike:password@db/bike_bike?encoding=unicode&pool=5} + - RAILS_ENV=${RAILS_ENV:-production rails assets:precompile.log} + - SMTP_ADDRESS=${SMTP_ADDRESS:-fake-smtp.bikebike.org} + - SMTP_DOMAIN=${SMTP_DOMAIN:-bikebike.org} + - SMTP_PORT=${SMTP_PORT:-587} + - SMTP_USER_NAME=${SMTP_USER_NAME:-info@bikebike.org} + - SMTP_PASSWORD=${SMTP_PASSWORD:-fake} + - DEFAULT_URL=${DEFAULT_URL:-bikebike.org} + volumes: + - bikebikebike:/app/BikeBike + - bikebikebike_bundle:/usr/local/bundle + build: . + expose: + - "3000" + links: + - db + restart: always + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + +# Create this volumes, docker volume create me +# or comment our external +volumes: + bikebikebike_db: + external: true + bikebikebike: + external: true + bikebikebike_bundle: + external: true + +# Remove this network if you don't use it +networks: + letsencrypt: + external: true diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0b36339 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Remove a potentially pre-existing server.pid for Rails. +rm -f /app/BikeBike/tmp/pids/server.pid + +# Then exec the container's main process (what's set as CMD in the Dockerfile). +exec "$@"