Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running DB migrations with fly ssh console #3

Open
wants to merge 4 commits into
base: bp-test-fly-database-deployment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ gem 'puma', '~> 5.0'

# use active record
gem 'sinatra-activerecord'
# use rake
gem "rake"

group :development do
gem 'better_errors'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ DEPENDENCIES
i18n
pry
puma (~> 5.0)
rake
rspec
rspec-html-matchers
sinatra
Expand Down
7 changes: 0 additions & 7 deletions Rakefile

This file was deleted.

6 changes: 3 additions & 3 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +31,7 @@
config.pryrc = :full;
end
AppdevSupport.init

# setup a database connection
set(:database, {adapter: "sqlite3", database: "db/development.sqlite3"})
end
Binary file added db/development.sqlite3
Binary file not shown.
8 changes: 8 additions & 0 deletions db/migrate/create_tasks.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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