From 6845943e5e82aef2c38cbba9940965beacb7993c Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Fri, 9 Jun 2023 21:35:38 +0000 Subject: [PATCH 01/11] remove rake stuff, move db connection to dev --- Gemfile | 2 -- Gemfile.lock | 1 - Rakefile | 7 ------- config/environment.rb | 6 +++--- 4 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 Rakefile diff --git a/Gemfile b/Gemfile index ed72702..300de59 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,6 @@ gem 'puma', '~> 5.0' # use active record gem 'sinatra-activerecord' -# use rake -gem "rake" group :development do gem 'better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 54e8de6..8b9a2eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -165,7 +165,6 @@ DEPENDENCIES i18n pry puma (~> 5.0) - rake rspec rspec-html-matchers sinatra diff --git a/Rakefile b/Rakefile deleted file mode 100644 index df0e18c..0000000 --- a/Rakefile +++ /dev/null @@ -1,7 +0,0 @@ -require "sinatra/activerecord/rake" - -namespace :db do - task :load_config do - require "./config/environment.rb" - end -end diff --git a/config/environment.rb b/config/environment.rb index fd78f1c..a7e40b9 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -8,9 +8,6 @@ # we can set the default layout name to use and sinatra # will look for that file set(:erb, :layout => :application_layout) - - # setup a database connection - set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"}) end configure :development do @@ -34,4 +31,7 @@ config.pryrc = :full; end AppdevSupport.init + + # setup a database connection + set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"}) end From 147dfc6599d06e473a0b64e8c2db96aaf41a9239 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 15:27:25 -0800 Subject: [PATCH 02/11] add production DB configuration --- config/environment.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/environment.rb b/config/environment.rb index a7e40b9..cf0bba1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -35,3 +35,8 @@ # setup a database connection set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"}) end + +configure :production do + # setup a database connection + set(:database, {adapter: "postgresql", database: ENV["DATABASE_URL"]}) +end From 0da82ae6062b371af5b133d85a967704b9b6bb7d Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 15:29:10 -0800 Subject: [PATCH 03/11] create tasks model --- db/development.sqlite3 | Bin 0 -> 12288 bytes db/migrate/create_tasks.rb | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 db/development.sqlite3 create mode 100644 db/migrate/create_tasks.rb diff --git a/db/development.sqlite3 b/db/development.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..7449ca76f33260c2d04b680816a89ea35162f277 GIT binary patch literal 12288 zcmeI#Jx{|h5C&koMKJNPWj%RH)rtkFGXX`YBK@GGL#E0kE<`kGo4AOz{8lD@1(%3Q zPzf=yRPRZ4a?aUNo=kUt7o^tEY*A#|(uFt^Qi@9=A%x`7s!TAMuH zO`F$a-wS;Ty{o{domw~7nd$J(*5*bYIgTUWvieM`%jdG58b9`{dQFk5(nL|3Tk~iN z8jX8>ZyeFBACWf+hrI!B>idI`216c`An1^)UZv Date: Sun, 11 Jun 2023 16:57:02 -0800 Subject: [PATCH 04/11] ready to try deployment --- config/environment.rb | 5 ----- db/development.sqlite3 | Bin 12288 -> 12288 bytes 2 files changed, 5 deletions(-) diff --git a/config/environment.rb b/config/environment.rb index cf0bba1..a7e40b9 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -35,8 +35,3 @@ # setup a database connection set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"}) end - -configure :production do - # setup a database connection - set(:database, {adapter: "postgresql", database: ENV["DATABASE_URL"]}) -end diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 7449ca76f33260c2d04b680816a89ea35162f277..9129ddc4b34b43553289c43b494604459a7bdb1f 100644 GIT binary patch delta 121 zcmZojXh@hK&B!!S#+i|6W5N=CHb(ya4E*~y3kq!I_qJzbV-OT}bWBT3NlP>`Ff!IP zFw-?OQZO*EGBvX@G1W7(FtsqYz%9eez`(%B|BZqF8_>Wv{9GK2%;KCSiN)E)0PfNp A82|tP delta 43 qcmZojXh@hK&B!=W#+i|EW5N=CCI*4cf(lRhCpL((@iG7boC^R0lM7V< From a889ec778332f5004de5f9b298f2d989138c47f3 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 17:00:21 -0800 Subject: [PATCH 05/11] ENV fetch DATABASE_URL --- config/environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environment.rb b/config/environment.rb index a7e40b9..7c22b0c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -33,5 +33,5 @@ AppdevSupport.init # setup a database connection - set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"}) + set(:database, {adapter: "sqlite3", database: ENV.fetch('DATABASE_URL', 'db/development.sqlite3')}) end From c66af0939e84dd4ae510c3334db589bf13bcac5d Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 17:13:27 -0800 Subject: [PATCH 06/11] ready to attempt fly deploy --- config/environment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/environment.rb b/config/environment.rb index 7c22b0c..2b861ae 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -8,6 +8,9 @@ # we can set the default layout name to use and sinatra # will look for that file set(:erb, :layout => :application_layout) + + # setup a database connection + set(:database, {adapter: "sqlite3", database: ENV.fetch('DATABASE_URL', 'db/development.sqlite3')}) end configure :development do @@ -31,7 +34,4 @@ config.pryrc = :full; end AppdevSupport.init - - # setup a database connection - set(:database, {adapter: "sqlite3", database: ENV.fetch('DATABASE_URL', 'db/development.sqlite3')}) end From 28d601e4bd947b7df9d67d3c4be8b5837eb4f534 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 17:34:08 -0800 Subject: [PATCH 07/11] update production database name, ready to fly deploy --- config/environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environment.rb b/config/environment.rb index 2b861ae..5315a1d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -10,7 +10,7 @@ set(:erb, :layout => :application_layout) # setup a database connection - set(:database, {adapter: "sqlite3", database: ENV.fetch('DATABASE_URL', 'db/development.sqlite3')}) + set(:database, {adapter: "sqlite3", database: ENV.fetch('DATABASE_LOCATION', 'db/development.sqlite3')}) end configure :development do From 57a0a23633055ee7ce6d461a78c48176fd147fe3 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 18:21:13 -0800 Subject: [PATCH 08/11] fly launch --- .dockerignore | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ fly.toml | 14 ++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..31a778a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,46 @@ +# flyctl launch added from .gitignore +# See https://help.github.com/articles/ignoring-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 +# /db/*.sqlite3-journal +db/*.sqlite3-* + +# Ignore all logfiles and tempfiles. +log/* +tmp/* +!log/.keep +!tmp/.keep + +# Ignore uploaded files in development. +storage/* +!storage/.keep + +public/assets +**/.byebug_history + +# Ignore master key for decrypting credentials and more. +config/master.key + +# Ignore dotenv files +.env* + +**/.rbenv-gemsets +**/examples.txt +**/whitelist.yml +**/grades.yml +**/cloud9_plugins.sh +**/appdev +**/node_modules +**/package-lock.json +**/core.chrome* +**/.theia/.ltici_apitoken.yml +**/.vscode/.ltici_apitoken.yml +fly.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..562ef1a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +ARG RUBY_VERSION=3.2.1 +FROM ruby:$RUBY_VERSION-slim as base + +# Rack app lives here +WORKDIR /app + +# Update gems and bundler +RUN gem update --system --no-document && \ + gem install -N bundler + + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential + +# Install application gems +COPY Gemfile* . +RUN bundle install + + +# Final stage for app image +FROM base + +# Run and own the application files as a non-root user for security +RUN useradd ruby --home /app --shell /bin/bash +USER ruby:ruby + +# Copy built artifacts: gems, application +COPY --from=build /usr/local/bundle /usr/local/bundle +COPY --from=build --chown=ruby:ruby /app /app + +# Copy application code +COPY --chown=ruby:ruby . . + +# Start the server +EXPOSE 8080 +CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "--port", "8080"] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..230ca83 --- /dev/null +++ b/fly.toml @@ -0,0 +1,14 @@ +# fly.toml app configuration file generated for sinatra-task-list-v2 on 2023-06-11T18:21:07-08:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "sinatra-task-list-v2" +primary_region = "sea" + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 From d28f3f5285e4740c115f04014bbf1a3a98850387 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 18:21:34 -0800 Subject: [PATCH 09/11] dockerignore dev db --- .dockerignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.dockerignore b/.dockerignore index 31a778a..a51b880 100644 --- a/.dockerignore +++ b/.dockerignore @@ -44,3 +44,6 @@ config/master.key **/.theia/.ltici_apitoken.yml **/.vscode/.ltici_apitoken.yml fly.toml + +# ignore your local database +db/development.sqlite3 From 074ea4ffbf22859f1751f821c5440fc427030f25 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 18:22:09 -0800 Subject: [PATCH 10/11] fly.toml volume production db --- fly.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fly.toml b/fly.toml index 230ca83..8662aa1 100644 --- a/fly.toml +++ b/fly.toml @@ -12,3 +12,10 @@ primary_region = "sea" auto_stop_machines = true auto_start_machines = true min_machines_running = 0 + +[mounts] + source = "production_db" + destination = "/app/production_db" + +[env] + DATABASE_LOCATION = "/app/production_db/production.sqlite3" From 746be159d46a75a0a62811c7da1e22849898ecf0 Mon Sep 17 00:00:00 2001 From: Ben Purinton Date: Sun, 11 Jun 2023 18:28:50 -0800 Subject: [PATCH 11/11] works --- fly.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fly.toml b/fly.toml index 8662aa1..18574dd 100644 --- a/fly.toml +++ b/fly.toml @@ -15,7 +15,7 @@ primary_region = "sea" [mounts] source = "production_db" - destination = "/app/production_db" + destination = "/app/db/production_db" [env] - DATABASE_LOCATION = "/app/production_db/production.sqlite3" + DATABASE_LOCATION = "/app/db/production_db/production.sqlite3"