Skip to content

Commit

Permalink
Merge pull request #25 from Shipyrd/remove-litestack
Browse files Browse the repository at this point in the history
Remove litestack and test out solid_cable instead
  • Loading branch information
nickhammond committed May 29, 2024
2 parents 9bfe4a1 + 83640ef commit a73bed5
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 69 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ gem "dotenv-rails"
gem "puma", ">= 5.0"
gem "propshaft"
gem "importmap-rails"
gem "turbo-rails"
gem "turbo-rails", github: "hotwired/turbo-rails" # for broadcasts_refreshes support
gem "stimulus-rails"
gem "jbuilder"
gem "bootsnap", require: false
gem "litestack"
gem "solid_cable"
gem "sqlite3"

group :development, :test do
Expand All @@ -35,6 +35,7 @@ end
group :test do
gem "minitest-spec-rails"
gem "capybara"
gem "launchy"
gem "mocha"
gem "selenium-webdriver"
gem "webdrivers"
Expand Down
43 changes: 18 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/hotwired/turbo-rails.git
revision: e376852bfb273f69f4ebb54cf516b99fcbaa7acb
specs:
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -95,6 +104,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (5.0.0)
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
Expand Down Expand Up @@ -140,18 +150,11 @@ GEM
guard (>= 2.0.0)
guard-compat (~> 1.0)
standardrb
hanami-router (0.6.2)
hanami-utils (~> 0.7)
http_router (~> 0.11)
hanami-utils (0.9.2)
hashdiff (1.1.0)
hotwire-livereload (1.3.1)
actioncable (>= 6.0.0)
listen (>= 3.0.0)
railties (>= 6.0.0)
http_router (0.11.2)
rack (>= 1.0.0)
url_mount (~> 0.2.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
Expand All @@ -167,17 +170,13 @@ GEM
activesupport (>= 5.0.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
launchy (3.0.1)
addressable (~> 2.8)
childprocess (~> 5.0)
lint_roller (1.1.0)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
litestack (0.4.2)
erubi
hanami-router
oj
rack
sqlite3
tilt
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -219,8 +218,6 @@ GEM
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
oj (3.16.3)
bigdecimal (>= 3.0)
parallel (1.24.0)
parser (3.3.0.2)
ast (~> 2.4.1)
Expand Down Expand Up @@ -316,6 +313,8 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shellany (0.0.1)
solid_cable (0.3.0)
rails (< 9)
sqlite3 (1.7.0-aarch64-linux)
sqlite3 (1.7.0-arm64-darwin)
sqlite3 (1.7.0-x86_64-linux)
Expand All @@ -340,17 +339,10 @@ GEM
railties (>= 6.0.0)
stringio (3.1.0)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
url_mount (0.2.1)
rack
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -393,19 +385,20 @@ DEPENDENCIES
hotwire-livereload (~> 1.2)
importmap-rails
jbuilder
litestack
launchy
minitest-spec-rails
mocha
propshaft
pry
puma (>= 5.0)
rails (~> 7.1.2)
selenium-webdriver
solid_cable
sqlite3
standard
standard-rails
stimulus-rails
turbo-rails
turbo-rails!
web-console
webdrivers
webmock
Expand Down
3 changes: 2 additions & 1 deletion app/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class Application < ApplicationRecord
has_many :deploys, dependent: :destroy, foreign_key: :service, primary_key: :key, inverse_of: "application"
has_many :destinations, dependent: :destroy

broadcasts
broadcasts_refreshes # For broadcasting on the index before there's an application record
broadcasts # For broadcasting deploys as they come in

validates :key, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.find_or_create_performer(username)
user
end

# TODO: Queue with a lite service?
# TODO: Queue this
def populate_avatar_url
url = URI("https://api.github.com/users/#{username}")
user_info = JSON.parse(Net::HTTP.get(url))
Expand Down
2 changes: 1 addition & 1 deletion app/views/applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<% application.destinations.each do |destination| %>
<%= form.fields_for :destinations, destination do |d| %>
<fieldset>
<legend><%= d.object.name %></h3></legend>
<legend><%= d.object.name %></legend>

<div>
<%= d.label :branch %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/applications/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<div class="w-full">
<%= turbo_refreshes_with method: :morph, scroll: :preserve %>
<%= turbo_stream_refresh_tag %>
<%= turbo_stream_from :applications %>

<div id="applications" class="w-full">
<% if notice.present? %>
<p class="notice" id="notice"><%= notice %></p>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<%= favicon_link_tag "favicon.png" %>
<%= javascript_importmap_tags %>
<%= hotwire_livereload_tags if Rails.env.development? %>
<%= yield :head %>
</head>

<body>
Expand Down
14 changes: 10 additions & 4 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
default: &default
adapter: solid_cable
silence_polling: true
polling_interval: 1
keep_messages_around_for: 60.minutes

development:
adapter: litecable
<<: *default

test:
adapter: test
adapter: inline

staging:
adapter: litecable
<<: *default

production:
adapter: litecable
<<: *default
31 changes: 3 additions & 28 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
# `Litesupport.root.join("data.sqlite3")` stores
# application data in the path `./db/#{Rails.env}/data.sqlite3`
#
# `Litesupport.root(env).join(path)` stores
# application data in the path `./db/#{env}/#{path}`
#
# idle_timeout should be set to zero, to avoid recycling sqlite connections
# and losing the page cache
#
default: &default
adapter: litedb
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
idle_timeout: 0
database: db/<%= Rails.env %>/data.sqlite3

development:
<<: *default
database: <%= Litesupport.root("development").join("data.sqlite3") %>
database: db/development/data.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= Litesupport.root("test").join("data.sqlite3") %>

# Warning: Make sure your production database path is on a persistent
# volume, otherwise your application data could be deleted between deploys.
#
# You may also set the Litesupport.root in production via the
# `LITESTACK_DATA_PATH` environment variable.
production:
<<: *default
database: <%= Litesupport.root("production").join("data.sqlite3") %>

4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")

# Use a different cache store in production.
config.cache_store = :litecache
# config.cache_store = :litecache

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :litejob
# config.active_job.queue_adapter = :litejob
# config.active_job.queue_name_prefix = "shipyrd_production"

# config.action_mailer.perform_caching = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# This migration comes from solid_cable (originally 20240103034713)
class CreateSolidCableMessage < ActiveRecord::Migration[7.1]
def change
create_table :solid_cable_messages, if_not_exists: true do |t|
t.text :channel
t.text :payload

t.timestamps

t.index :created_at
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions test/system/applications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@ class ApplicationsTest < ApplicationSystemTestCase

it "points to setup instructions" do
visit basic_auth_url(root_url, @api_key.token)
visit root_url

assert_text "Waiting for a deploy to start..."
assert_link "Setup instructions", href: "https://github.com/shipyrd/shipyrd"

create(
:deploy,
service_version: "potato@123456",
command: :deploy,
status: "pre-deploy",
version: "123456",
performer: "Nick",
commit_message: "Deploying the potato"
)

assert_text "potato"
assert_text "pre-deploy"
assert_text "by Nick"
assert_text "Deploying the potato"
end
end

Expand Down Expand Up @@ -73,20 +89,24 @@ class ApplicationsTest < ApplicationSystemTestCase
@application = create(
:deploy,
service_version: "potato@123456",
destination: "production"
command: :deploy,
destination: "production",
status: "pre-connect"
).application

visit basic_auth_url(root_url, @api_key.token)
visit root_url
sleep(1) # TODO: Turbo page navigation isn't refreshing properly with Capybara state

click_on "Edit this application", match: :first
click_link "Edit this application"

fill_in "Name", with: @application.name
fill_in "Repository URL", with: @application.repository_url

within_fieldset "production" do
fill_in "Branch", with: "main"
fill_in "URL", with: "https://production.com"
end

click_on "Update"

assert_text "Application was successfully updated"
Expand Down

0 comments on commit a73bed5

Please sign in to comment.