-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·53 lines (43 loc) · 1.51 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
require 'fileutils'
FILES = %w[
.docker.env
DEVELOPMENT.DOCKER.md
bin
config
development.docker
docker-compose.yml
]
HELP_MESSAGE = <<-HLP
Usage: ../docker-rails-development/install
Run this script to copy Docker files into current directory
HLP
if ARGV.include?('-h') || ARGV.include?('--help')
puts HELP_MESSAGE
exit
end
source_directory = File.dirname File.expand_path __FILE__
destination_directory = Dir.pwd
if destination_directory == source_directory
puts "Error: doesn't make sense to copy files into the same directory"
puts HELP_MESSAGE
exit 1
end
# Copy files
source_paths = FILES.map { |file_name| File.join source_directory, file_name }
FileUtils.cp_r source_paths, destination_directory, verbose: true
# Copy docker-sync.yml
# Set project name in container name in docker-sync.yml
# Generating project name like Docker Compose does:
# https://github.com/docker/compose/blob/520f5d0fdece26862c622c33007775400a9b9000/compose/cli/command.py#L132
project_name = File.basename(Dir.getwd).downcase.gsub(/[^-_a-z0-9]/, '')
template_path = File.join source_directory, 'docker-sync.yml.erb'
template = File.read template_path
rendered = template.gsub '<%= project_name %>', project_name
destination_path = File.join destination_directory, 'docker-sync.yml'
unless File.exist? destination_path
File.write destination_path, rendered
puts "Rendered #{template_path} to #{destination_path}"
else
puts "Skipping #{destination_path}, it already exists"
end