Skip to content

Commit

Permalink
Add stack & accessors to Filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
wayt committed Jul 29, 2024
1 parent 2c4aec5 commit b0da329
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/jobs/shipit/cache_deploy_spec_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def perform(stack)

commands = Commands.for(stack)
commands.with_temporary_working_directory(commit: stack.commits.reachable.last) do |path|
stack.update!(cached_deploy_spec: DeploySpec::FileSystem.new(path, stack.environment))
stack.update!(cached_deploy_spec: DeploySpec::FileSystem.new(path, stack))
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/models/shipit/deploy_spec/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class FileSystem < DeploySpec
include BundlerDiscovery
include KubernetesDiscovery

def initialize(app_dir, env)
attr_reader :stack

def initialize(app_dir, stack)
@app_dir = Pathname(app_dir)
@env = env
@env = stack.environment
@stack = stack
super(nil)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/shipit/ephemeral_commit_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run
self.status = 'running'
commands = StackCommands.new(stack)
commands.with_temporary_working_directory(commit: commit) do |directory|
deploy_spec = DeploySpec::FileSystem.new(directory, stack.environment)
deploy_spec = DeploySpec::FileSystem.new(directory, stack)
capture_all(build_commands(deploy_spec.dependencies_steps, chdir: directory))
capture_all(build_commands(deploy_spec.review_checks, chdir: directory))
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/shipit/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def duration
end

def spec
@spec ||= DeploySpec::FileSystem.new(working_directory, stack.environment)
@spec ||= DeploySpec::FileSystem.new(working_directory, stack)
end

def enqueue
Expand Down
4 changes: 2 additions & 2 deletions lib/shipit/stack_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def fetched?(commit)

def fetch_deployed_revision
with_temporary_working_directory(commit: @stack.commits.reachable.last) do |dir|
spec = DeploySpec::FileSystem.new(dir, @stack.environment)
spec = DeploySpec::FileSystem.new(dir, @stack)
outputs = spec.fetch_deployed_revision_steps!.map do |command_line|
Command.new(command_line, env: env, chdir: dir).run
end
Expand All @@ -59,7 +59,7 @@ def fetch_deployed_revision

def build_cacheable_deploy_spec
with_temporary_working_directory(recursive: false) do |dir|
DeploySpec::FileSystem.new(dir, @stack.environment).cacheable
DeploySpec::FileSystem.new(dir, @stack).cacheable
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/shipit/task_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(task)
end

def deploy_spec
@deploy_spec ||= DeploySpec::FileSystem.new(@task.working_directory, @stack.environment)
@deploy_spec ||= DeploySpec::FileSystem.new(@task.working_directory, @stack)
end

def install_dependencies
Expand Down
9 changes: 6 additions & 3 deletions test/models/deploy_spec_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Shipit
class DeploySpecTest < ActiveSupport::TestCase
setup do
@app_dir = '/tmp/'
@spec = DeploySpec::FileSystem.new(@app_dir, 'env')
@stack = shipit_stacks(:shipit)
@spec = DeploySpec::FileSystem.new(@app_dir, @stack)
@spec.stubs(:load_config).returns({})
end

Expand Down Expand Up @@ -287,7 +288,8 @@ class DeploySpecTest < ActiveSupport::TestCase
end

test '#gemspec gives the path of the repo gemspec if present' do
spec = DeploySpec::FileSystem.new('foobar/', 'production')
# spec = DeploySpec::FileSystem.new('foobar/', 'production')
spec = DeploySpec::FileSystem.new('foobar/', @stack)
Dir.expects(:[]).with('foobar/*.gemspec').returns(['foobar/foobar.gemspec'])
assert_equal 'foobar/foobar.gemspec', spec.gemspec
end
Expand All @@ -309,7 +311,8 @@ class DeploySpecTest < ActiveSupport::TestCase
end

test '#setup_dot_py gives the path of the repo setup.py if present' do
spec = DeploySpec::FileSystem.new('foobar/', 'production')
# spec = DeploySpec::FileSystem.new('foobar/', 'production')
spec = DeploySpec::FileSystem.new('foobar/', @stack)
assert_equal Pathname.new('foobar/setup.py'), spec.setup_dot_py
end

Expand Down
15 changes: 10 additions & 5 deletions test/models/shipit/deploy_spec/file_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class DeploySpec
class FileSystemTest < ActiveSupport::TestCase
test 'deploy.pre calls "exit 1" if there is a bare shipit file and Shipit is configured to ignore' do
Shipit.expects(:respect_bare_shipit_file?).returns(false).at_least_once
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, 'env')
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
deploy_spec.expects(:read_config).never
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
Expand All @@ -18,7 +19,8 @@ class FileSystemTest < ActiveSupport::TestCase

test 'deploy.pre does not call "exit 1" if Shipit is not configured to do so' do
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, 'env')
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_yaml))
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
Expand All @@ -29,7 +31,8 @@ class FileSystemTest < ActiveSupport::TestCase
test 'Shipit.respect_bare_shipit_file? has no effect if the file is not a bare file' do
[true, false].each do |obey_val|
Shipit.expects(:respect_bare_shipit_file?).returns(obey_val).at_least_once
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, 'env')
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.env.yml').at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_yaml))
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
Expand All @@ -40,7 +43,8 @@ class FileSystemTest < ActiveSupport::TestCase

test '#load_config does not error if the file is empty' do
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, 'env')
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.env.yml').at_least_once
deploy_spec.expects(:read_config).at_least_once.returns(false)
loaded_config = deploy_spec.send(:cacheable_config)
Expand All @@ -49,7 +53,8 @@ class FileSystemTest < ActiveSupport::TestCase

test '#load_config does not error if there is no "deploy" key' do
Shipit.expects(:respect_bare_shipit_file?).returns(false).at_least_once
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, 'env')
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
deploy_spec.expects(:read_config).never
loaded_config = deploy_spec.send(:load_config)
Expand Down

0 comments on commit b0da329

Please sign in to comment.