Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Added optional removal of scm files
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Rzegocki committed Apr 25, 2016
1 parent 9f8615f commit 82b25ec
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -101,6 +101,10 @@ you don't need to provide them here. Currently only `git` is supported.
* **Supported values:** `git`
* **Default:** `git`
* SCM used by the cookbook to clone the repo.
* `app['scm']['remove_scm_files']`
* **Supported values:** `true`, `false`
* **Default:** `true`
* If set to true, all SCM leftovers (like `.git`) will be removed.
* `app['scm']['repository']`
* Repository URL
* `app['scm']['revision']`
Expand Down
5 changes: 5 additions & 0 deletions attributes/default.rb
Expand Up @@ -21,6 +21,11 @@
nginx::http_stub_status_module
)

# scm
## common

default['defaults']['scm']['remove_scm_files'] = true

# appserver
## common

Expand Down
3 changes: 2 additions & 1 deletion libraries/drivers_scm_base.rb
Expand Up @@ -26,7 +26,8 @@ def raw_out
end

def out_defaults
base = JSON.parse((node['deploy'][app['shortname']]['scm'] || {}).to_json, symbolize_names: true)
base = node['defaults']['scm'].to_h.symbolize_keys
base = base.merge(JSON.parse((node['deploy'][app['shortname']]['scm'] || {}).to_json, symbolize_names: true))
defaults.merge(base).merge(scm_provider: adapter.constantize)
end

Expand Down
2 changes: 1 addition & 1 deletion libraries/drivers_scm_git.rb
Expand Up @@ -5,7 +5,7 @@ class Git < Drivers::Scm::Base
adapter Chef::Provider::Git
allowed_engines :git
packages :git
output filter: [:scm_provider, :repository, :revision, :enable_submodules, :ssh_wrapper]
output filter: [:scm_provider, :repository, :revision, :enable_submodules, :ssh_wrapper, :remove_scm_files]
defaults enable_submodules: true, ssh_wrapper: '/tmp/ssh-git-wrapper.sh'

def before_deploy(context)
Expand Down
4 changes: 2 additions & 2 deletions recipes/deploy.rb
Expand Up @@ -40,7 +40,7 @@
symlinks(node['defaults']['deploy']['symlinks'].merge(deploy[:symlinks] || {}))

scm.out.each do |scm_key, scm_value|
send(scm_key, scm_value)
send(scm_key, scm_value) if respond_to?(scm_key)
end

[appserver, webserver].each do |server|
Expand Down Expand Up @@ -69,7 +69,7 @@
directory File.join(release_path, '.git') do
recursive true
action :delete
end
end if scm.out[:remove_scm_files]

run_callback_from_file(File.join(release_path, 'deploy', 'before_restart.rb'))
end
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/node.rb
Expand Up @@ -64,6 +64,9 @@ def node(override = {})
create_dirs_before_symlink: %w(tmp public config ../../shared/cache ../../shared/assets),
purge_before_symlink: %w(log tmp/cache tmp/pids public/system public/assets)
},
scm: {
remove_scm_files: true
},
appserver: {
adapter: 'unicorn',
worker_processes: 8
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/libraries/drivers_scm_git_spec.rb
Expand Up @@ -91,7 +91,8 @@
revision: 'master',
repository: 'git@git.example.com:repo/project.git',
enable_submodules: false,
ssh_wrapper: 'ssh-wrap'
ssh_wrapper: 'ssh-wrap',
remove_scm_files: true
)
end

Expand Down

0 comments on commit 82b25ec

Please sign in to comment.