-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen_eb_config
executable file
·68 lines (59 loc) · 2.3 KB
/
gen_eb_config
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
require 'yaml'
eval File.read("#{ARGV[0]}/.deploy_vars")
filename = '.elasticbeanstalk/config.yml'
data = {
"global" => {
"application_name" => EB_APP_NAME || raise('EB_APP_NAME missing'),
"default_ec2_keyname" => AWS_EC2_KEYNAME || raise('AWS_EC2_KEYNAME missing'),
"default_platform" => 'docker',
"default_region" => AWS_REGION || raise('AWS_REGION missing'),
"workspace_type" => "Application"
}
}
File.open(filename, "wb+") { |f| f.write data.to_yaml }
def create_file_with_content(ebext_name, output_file, content)
setup_ebextension_command(ebext_name, %Q[echo "#{content}" > #{output_file}])
end
def setup_ebextension_command(ebext_name, command)
filename = ".ebextensions/#{ebext_name}.config"
data = {
"container_commands" => {
"01_execute" => {
"command" => command,
"ignoreErrors" => "false"
}
}
}
# default to 81 https://ruby-doc.org/stdlib-2.7.1/libdoc/psych/rdoc/Psych.html#method-c-dump
File.open(filename, "wb+") { |f| f.write Psych.dump(data, :line_width => 150) }
end
create_file_with_content('machine-identification', '/home/ec2-user/machine-id', ARGV[2])
begin
create_file_with_content('ssh-authorized-keys', '/home/ec2-user/.ssh/authorized_keys', Object.const_get("EB_#{ARGV[1].upcase}_SSH_KEYS"))
rescue NameError
puts "SSH Keys for stage: #{ARGV[1]} not found, skipping..."
end
## setup_ebextension_command('install_mysqlclient', "apt update && apt install mysql-client")
command = %q[if [ \"\$1\" = \"bash\" ]
then
cmd=\"bash\"
elif [ \"\$1\" = \"db:migrate\" ]
then
cmd=\"bundle exec rails db:migrate\"
elif [ \"\$1\" = \"db\" ]
then
cmd=\"bundle exec rails db -p\"
else
cmd=\"bundle exec rails c\"
fi
echo \"executing \$cmd on container\"
sudo docker exec -it \$(sudo docker container ls | tail -n 1 | awk {'print \$1'}) \$cmd]
create_file_with_content('create_docker_jump', '/home/ec2-user/jumpin', command)
app_name_parts = EB_APP_NAME.split(/_/)
figlet_content = "#{`toilet "#{app_name_parts.shift}" -w 200`}\n"
figlet_content += "#{`toilet "#{app_name_parts.join(' ')} #{ARGV[1]}" -w 200`}\n"
create_file_with_content('motd_override', '/etc/motd', figlet_content.gsub(/"/, '\"'))
create_file_with_content('motd_override2', '/etc/update-motd.d/10eb-banner',
"cat << EOF\n"+figlet_content.gsub(/"/, '\"')+"\nEOF"
)