diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..338a5b5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.6.6 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f98c652 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ruby:2.3.5 + +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client +RUN gem install bundler:2.1.4 + +RUN mkdir /200donors +WORKDIR /200donors +COPY Gemfile /200donors/Gemfile +COPY Gemfile.lock /200donors/Gemfile.lock +RUN bundle install +COPY . /200donors + +# Add a script to be executed every time the container starts. +COPY docker-entrypoint.sh /usr/bin/entrypoint.sh +RUN chmod +x /usr/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 3000 + +# Start the main process. +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/Gemfile b/Gemfile index 4d6061f..cb266a7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ source 'https://rubygems.org' -ruby '2.2.1' +ruby '2.6.6' gem 'sinatra' gem 'stripe' -gem 'data_mapper' -gem 'dm-postgres-adapter' +gem 'rom' +gem 'rom-sql' gem 'pg' gem 'mail' diff --git a/Gemfile.lock b/Gemfile.lock index d8dd0a8..14f7a28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,187 +1,170 @@ GEM remote: https://rubygems.org/ specs: - actionpack (4.2.7.1) - actionview (= 4.2.7.1) - activesupport (= 4.2.7.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.7.1) - activesupport (= 4.2.7.1) + actionpack (6.1.3) + actionview (= 6.1.3) + activesupport (= 6.1.3) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actionview (6.1.3) + activesupport (= 6.1.3) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activesupport (4.2.7.1) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - addressable (2.5.0) - public_suffix (~> 2.0, >= 2.0.2) - bcrypt (3.1.11) - bcrypt-ruby (3.1.5) - bcrypt (>= 3.1.3) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activesupport (6.1.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) bond (0.5.1) - builder (3.2.2) - coderay (1.1.1) - data_mapper (1.2.0) - dm-aggregates (~> 1.2.0) - dm-constraints (~> 1.2.0) - dm-core (~> 1.2.0) - dm-migrations (~> 1.2.0) - dm-serializer (~> 1.2.0) - dm-timestamps (~> 1.2.0) - dm-transactions (~> 1.2.0) - dm-types (~> 1.2.0) - dm-validations (~> 1.2.0) - data_objects (0.10.17) - addressable (~> 2.1) - dm-aggregates (1.2.0) - dm-core (~> 1.2.0) - dm-constraints (1.2.0) - dm-core (~> 1.2.0) - dm-core (1.2.1) - addressable (~> 2.3) - dm-do-adapter (1.2.0) - data_objects (~> 0.10.6) - dm-core (~> 1.2.0) - dm-migrations (1.2.0) - dm-core (~> 1.2.0) - dm-postgres-adapter (1.2.0) - dm-do-adapter (~> 1.2.0) - do_postgres (~> 0.10.6) - dm-serializer (1.2.2) - dm-core (~> 1.2.0) - fastercsv (~> 1.5) - json (~> 1.6) - json_pure (~> 1.6) - multi_json (~> 1.0) - dm-timestamps (1.2.0) - dm-core (~> 1.2.0) - dm-transactions (1.2.0) - dm-core (~> 1.2.0) - dm-types (1.2.2) - bcrypt-ruby (~> 3.0) - dm-core (~> 1.2.0) - fastercsv (~> 1.5) - json (~> 1.6) - multi_json (~> 1.0) - stringex (~> 1.4) - uuidtools (~> 2.1) - dm-validations (1.2.0) - dm-core (~> 1.2.0) - do_postgres (0.10.17) - data_objects (= 0.10.17) - domain_name (0.5.20161021) - unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.1) - dotenv-rails (2.1.1) - dotenv (= 2.1.1) - railties (>= 4.0, < 5.1) - erubis (2.7.0) - fastercsv (1.5.5) - http-cookie (1.0.3) - domain_name (~> 0.5) - i18n (0.7.0) - json (1.8.3) - json_pure (1.8.3) - loofah (2.0.3) + builder (3.2.4) + coderay (1.1.3) + concurrent-ruby (1.1.8) + crass (1.0.6) + dotenv (2.7.6) + dotenv-rails (2.7.6) + dotenv (= 2.7.6) + railties (>= 3.2) + dry-configurable (0.12.1) + concurrent-ruby (~> 1.0) + dry-core (~> 0.5, >= 0.5.0) + dry-container (0.7.2) + concurrent-ruby (~> 1.0) + dry-configurable (~> 0.1, >= 0.1.3) + dry-core (0.5.0) + concurrent-ruby (~> 1.0) + dry-equalizer (0.3.0) + dry-inflector (0.2.0) + dry-initializer (3.0.4) + dry-logic (1.1.0) + concurrent-ruby (~> 1.0) + dry-core (~> 0.5, >= 0.5) + dry-struct (1.4.0) + dry-core (~> 0.5, >= 0.5) + dry-types (~> 1.5) + ice_nine (~> 0.11) + dry-types (1.5.1) + concurrent-ruby (~> 1.0) + dry-container (~> 0.3) + dry-core (~> 0.5, >= 0.5) + dry-inflector (~> 0.1, >= 0.1.2) + dry-logic (~> 1.0, >= 1.0.2) + erubi (1.10.0) + i18n (1.8.9) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + loofah (2.9.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.1) - multi_json (1.12.1) - netrc (0.11.0) - nokogiri (1.6.8.1) - mini_portile2 (~> 2.1.0) - pg (0.19.0) - pry (0.10.4) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - public_suffix (2.0.4) - rack (1.6.4) - rack-protection (1.5.3) + mail (2.7.1) + mini_mime (>= 0.1.1) + method_source (1.0.0) + mini_mime (1.0.2) + minitest (5.14.4) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + nokogiri (1.11.1-x86_64-darwin) + racc (~> 1.4) + pg (1.2.3) + pry (0.14.0) + coderay (~> 1.1) + method_source (~> 1.0) + racc (1.5.2) + rack (2.2.3) + rack-protection (2.1.0) rack - rack-test (0.6.3) - rack (>= 1.0) - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (4.2.7.1) - actionpack (= 4.2.7.1) - activesupport (= 4.2.7.1) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.1.3) + actionpack (= 6.1.3) + activesupport (= 6.1.3) + method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (11.3.0) - rest-client (2.0.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) + thor (~> 1.0) + rake (13.0.3) ripl (0.7.1) bond (~> 0.5.1) ripl-multi_line (0.3.1) ripl (>= 0.3.6) - ripl-rack (0.2.1) + ripl-rack (0.2.0) rack (>= 1.0) - rack-test (~> 0.6.2) - ripl (>= 0.7.0) + rack-test (>= 0.5) + ripl (>= 0.3.5) + rom (5.2.6) + rom-changeset (~> 5.2, >= 5.2.3) + rom-core (~> 5.2, >= 5.2.5) + rom-repository (~> 5.2, >= 5.2.2) + rom-changeset (5.2.3) + dry-core (~> 0.4) + rom-core (~> 5.2) + transproc (~> 1.0, >= 1.1.0) + rom-core (5.2.5) + concurrent-ruby (~> 1.1) + dry-container (~> 0.7) + dry-core (~> 0.4) + dry-equalizer (~> 0.2) + dry-inflector (~> 0.1) + dry-initializer (~> 3.0, >= 3.0.1) + dry-struct (~> 1.0) + dry-types (~> 1.0) + transproc (~> 1.0, >= 1.1.0) + rom-repository (5.2.2) + dry-core (~> 0.4) + dry-initializer (~> 3.0, >= 3.0.1) + rom-core (~> 5.2, >= 5.2.2) + rom-sql (3.3.2) + dry-core (~> 0.5, >= 0.5) + dry-types (~> 1.0) + rom (~> 5.2, >= 5.2.1) + sequel (>= 4.49) + ruby2_keywords (0.0.4) + sequel (5.41.0) shotgun (0.9.2) rack (>= 1.0) - sinatra (1.4.7) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) - slop (3.6.0) - stringex (1.5.1) - stripe (1.56.0) - rest-client (>= 1.4, < 4.0) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) + sinatra (2.1.0) + mustermann (~> 1.0) + rack (~> 2.2) + rack-protection (= 2.1.0) + tilt (~> 2.0) + stripe (5.30.0) + thor (1.1.0) + tilt (2.0.10) + transproc (1.1.1) tux (0.3.0) ripl (>= 0.3.5) ripl-multi_line (>= 0.2.4) ripl-rack (>= 0.2.0) sinatra (>= 1.2.1) - tzinfo (1.2.2) - thread_safe (~> 0.1) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.2) - uuidtools (2.1.5) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + zeitwerk (2.4.2) PLATFORMS - ruby + x86_64-darwin-20 DEPENDENCIES - data_mapper - dm-postgres-adapter dotenv-rails mail pg pry + rom + rom-sql shotgun sinatra stripe tux RUBY VERSION - ruby 2.2.1p85 + ruby 2.6.6p146 BUNDLED WITH - 1.15.0 + 2.2.11 diff --git a/README.md b/README.md index ce76edb..210a9e3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Wanna try for yourself? 1. Bundle Install -2. If you're using Postgres, you'll need a db named 'mydb' or whatever you change your database file to (createdb mydb) +2. If you're using Postgres, you'll need a db named '200donors' or whatever you change your database file to (createdb 200donors) 3. Seed database (Database.seed_data) diff --git a/app.rb b/app.rb index 91b0552..8a25b55 100644 --- a/app.rb +++ b/app.rb @@ -80,8 +80,8 @@ def markpaid(amount) mail = Mail.deliver do to customer.email - from 'Ryan McCrary ' - subject 'GOAT Christmas!' + from 'Joe Canney ' + subject 'New Cov 200' text_part do body "Thank you so much for participating in GOAT Christmas! We're constantly amazed at the generosity of each of you who make GOAT possible for the kids that we serve. diff --git a/database.rb b/database.rb index 078fbee..4438520 100644 --- a/database.rb +++ b/database.rb @@ -1,29 +1,71 @@ -require 'data_mapper' - -class Database - def self.initialize - DataMapper::Logger.new($stdout, :debug) - # memory database appears to timeout if not used in ~5 mins, which causes the database to be dumped - #DataMapper.setup(:default, 'sqlite::memory:') - DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/mydb') - DataMapper.finalize - DataMapper.auto_upgrade! +require 'rom-sql' + +rom = ROM.container(:sql, 'postgres://localhost/200donors', username: 'postgres', password: 'postgres') do |config| + config.default.connection.create_table(:donations) do + primary_key :id + column :amount, Integer, null: false + column :paid, Boolean, null: false end - def self.seed_data - (1..200).each do |donation| - Donation.create( - amount: donation, - paid: false - ) - end + config.relation(:donations) do + schema(infer: true) + auto_struct true end end -class Donation - include DataMapper::Resource +donations = rom.relations[:donations] + +(1..200).each do |donation| + users.changeset(:create, amount: donation, paid: false).commit +end + + + +# require 'rom' + +# class Database +# def self.initialize +# ROM.container(:sql, 'postgres://localhost/my_db', extensions: [:pg_json]) do |config| +# config.default.connection.create_table(:donations) do +# primary_key :id +# column :amount, Integer, null: false +# column :paid, Boolean, null: false +# end + +# config.relation(:donations) do +# schema(infer: true) +# auto_struct true +# end +# end +# end + +# def self.seed_data +# (1..200).each do |donation| +# Donation.create( +# amount: donation, +# paid: false +# ) +# end +# end +# end + +# class DonationRepo < ROM::Repository[:donation] +# def query(conditions) +# users.where(conditions).to_a +# end + +# def by_id(id) +# users.by_pk(id).one! +# end + +# # ... etc +# end + +# # class Donation < ROM::Repository[:donation] + +# # property :id, Serial +# # property :amount, Integer +# # property :paid, Boolean +# # end - property :id, Serial - property :amount, Integer - property :paid, Boolean -end \ No newline at end of file +# donation_repo = DonationRepo.new(rom) \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..bb58221 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Remove a potentially pre-existing server.pid for Rails. +rm -f /200donors/tmp/pids/server.pid + +# Then exec the container's main process (what's set as CMD in the Dockerfile). +exec "$@" diff --git a/scripts/docker_start b/scripts/docker_start new file mode 100755 index 0000000..0748afb --- /dev/null +++ b/scripts/docker_start @@ -0,0 +1,9 @@ +#!/bin/bash + +# Used to start the Docker container + +# bundle exec rails db:migrate:with_data +# rm -f tmp/pids/server.pid +# see config/puma.rb for PORT options +# bundle exec puma +ruby app.rb \ No newline at end of file