This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(framework): "hanami.rb" support added
Resolves #43
- Loading branch information
Showing
13 changed files
with
181 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
module Drivers | ||
module Framework | ||
class Hanami < Drivers::Framework::Base | ||
adapter :hanami | ||
allowed_engines :hanami | ||
output filter: [ | ||
:migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command | ||
] | ||
packages debian: 'zlib1g-dev', rhel: 'zlib-devel' | ||
|
||
def raw_out | ||
assets_command = node['deploy'][app['shortname']]['framework']['assets_precompilation_command'] || | ||
'/usr/local/bin/bundle exec hanami assets precompile' | ||
migration_command = node['deploy'][app['shortname']]['framework']['migration_command'] || | ||
'/usr/local/bin/bundle exec hanami db migrate' | ||
|
||
super.merge( | ||
deploy_environment: { 'HANAMI_ENV' => globals[:environment], 'DATABASE_URL' => database_url }, | ||
assets_precompilation_command: assets_command, | ||
migration_command: migration_command | ||
) | ||
end | ||
|
||
def configure(context) | ||
build_env(context) | ||
end | ||
|
||
def deploy_before_restart(context) | ||
link_env(context) | ||
assets_precompile(context) if out[:assets_precompile] | ||
end | ||
|
||
private | ||
|
||
def build_env(context) | ||
deploy_to = deploy_dir(app) | ||
env = environment | ||
|
||
context.template File.join(deploy_to, 'shared', 'config', ".env.#{globals[:environment]}") do | ||
owner node['deployer']['user'] | ||
group www_group | ||
source 'dot_env.erb' | ||
variables environment: env | ||
end | ||
end | ||
|
||
def link_env(context) | ||
deploy_to = deploy_dir(app) | ||
env_name = globals[:environment] | ||
|
||
context.link File.join(deploy_to, 'current', ".env.#{env_name}") do | ||
to File.join(deploy_to, 'shared', 'config', ".env.#{env_name}") | ||
ignore_failure true | ||
end | ||
end | ||
|
||
def assets_precompile(context) | ||
output = out | ||
deploy_to = deploy_dir(app) | ||
env = environment.merge('HOME' => node['deployer']['home']) | ||
|
||
context.execute 'assets:precompile' do | ||
command output[:assets_precompilation_command] | ||
user node['deployer']['user'] | ||
cwd File.join(deploy_to, 'current') | ||
group www_group | ||
environment env | ||
end | ||
end | ||
|
||
def database_url | ||
database_url = "sqlite://db/#{app['shortname']}_#{globals[:environment]}.sqlite" | ||
|
||
Array.wrap(options[:databases]).each do |db| | ||
next unless db.applicable_for_configuration? | ||
|
||
database_url = | ||
"#{db.out[:adapter]}://#{db.out[:username]}:#{db.out[:password]}@#{db.out[:host]}/#{db.out[:database]}" | ||
|
||
database_url = "sqlite://#{db.out[:database]}" if db.out[:adapter].start_with?('sqlite') | ||
end | ||
|
||
database_url | ||
end | ||
|
||
def environment | ||
app['environment'].merge(out[:deploy_environment]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
describe Drivers::Framework::Hanami do | ||
it 'receives and exposes app and node' do | ||
driver = described_class.new(aws_opsworks_app, node) | ||
|
||
expect(driver.app).to eq aws_opsworks_app | ||
expect(driver.node).to eq node | ||
expect(driver.options).to eq({}) | ||
end | ||
|
||
it 'returns proper out data' do | ||
expect(described_class.new(aws_opsworks_app, node).out).to eq( | ||
assets_precompile: true, | ||
assets_precompilation_command: '/usr/local/bin/bundle exec hanami assets precompile', | ||
deploy_environment: { | ||
'HANAMI_ENV' => 'staging', 'DATABASE_URL' => 'sqlite://db/dummy_project_staging.sqlite' | ||
}, | ||
migration_command: '/usr/local/bin/bundle exec hanami db migrate', | ||
migrate: false | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters