|
| 1 | +module Recipes |
| 2 | + class Deploy < Base |
| 3 | + |
| 4 | + def initialize(pathfinder, type: 'none') |
| 5 | + if !%w(cloud66 docker none).include?(type) |
| 6 | + fail 'none, docker or cloud66 are the only allowed options for deploy recipe' |
| 7 | + end |
| 8 | + super(pathfinder) |
| 9 | + @type = type |
| 10 | + end |
| 11 | + |
| 12 | + def init_file |
| 13 | + case @type |
| 14 | + when 'docker' then docker_config_files |
| 15 | + when 'cloud66' then cloud66_config_files |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + private |
| 20 | + |
| 21 | + def cloud66_config_files |
| 22 | + @template.add_file '.cloud66/bower.sh', |
| 23 | + relative_file_content('deploy/cloud66/bower.sh') |
| 24 | + @template.add_file '.cloud66/cache_permissions.sh', |
| 25 | + relative_file_content('deploy/cloud66/cache_permissions.sh') |
| 26 | + @template.add_file '.cloud66/deploy_hooks.yml', |
| 27 | + relative_file_content('deploy/cloud66/deploy_hooks.yml') |
| 28 | + end |
| 29 | + |
| 30 | + def docker_config_files |
| 31 | + @template.add_file 'docker/rails-env.conf', |
| 32 | + relative_file_content('deploy/docker/rails-env.conf') |
| 33 | + @template.add_file '.dockerignore', |
| 34 | + relative_file_content('deploy/docker/.dockerignore') |
| 35 | + @template.append_file 'README.md', |
| 36 | + relative_file_content('deploy/docker/README.md') |
| 37 | + add_file_and_replace_app_name('docker/fix_permissions.sh', |
| 38 | + 'deploy/docker/fix_permissions.sh') |
| 39 | + add_file_and_replace_app_name('Dockerfile', 'deploy/docker/Dockerfile') |
| 40 | + add_file_and_replace_app_name('docker/nginx.conf', 'deploy/docker/nginx.conf') |
| 41 | + end |
| 42 | + |
| 43 | + def add_file_and_replace_app_name(target_file, source_file) |
| 44 | + @template.add_file target_file, relative_file_content(source_file) |
| 45 | + @template.run "sed -i '' 's/app-name/#{@pathfinder.app_name}/g' #{target_file}" |
| 46 | + end |
| 47 | + |
| 48 | + end |
| 49 | +end |
0 commit comments