diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a51b880 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,49 @@ +# 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 + +# ignore your local database +db/development.sqlite3 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/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 diff --git a/db/development.sqlite3 b/db/development.sqlite3 new file mode 100644 index 0000000..cdfce7e Binary files /dev/null and b/db/development.sqlite3 differ diff --git a/db/migrate/create_tasks.rb b/db/migrate/create_tasks.rb new file mode 100644 index 0000000..9c5a048 --- /dev/null +++ b/db/migrate/create_tasks.rb @@ -0,0 +1,8 @@ +require 'sinatra/activerecord' +require './config/environment' + +ActiveRecord::Migration.create_table :tasks do |t| + t.string :name + t.text :description + t.timestamps +end diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..020e40d --- /dev/null +++ b/fly.toml @@ -0,0 +1,14 @@ +# fly.toml app configuration file generated for sinatra-task-list on 2023-06-09T21:40:50Z +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "sinatra-task-list" +primary_region = "sea" + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0