Commit 942a634a3532f3bc7e89bad78fd48be7e8c2fc5b

Authored by Antonio Terceiro
1 parent 0f470404

Remove IP addresses from main configuration file

This way we can use the exact same nodes.yaml against different
deployment sites (e.g. development, staging, production).
README.md
... ... @@ -14,13 +14,16 @@ For development
14 14  
15 15 ## Configuration parameters
16 16  
17   -For development, all configuration parameters are defined in the file
18   -`nodes.yaml`.
  17 +All configuration parameters are defined in `nodes.yaml`, with exception of IP
  18 +addresses, which are defined in different files:
19 19  
20   -For production, create a new file based on `nodes.yaml`, e.g.
21   -`prod.yaml`.
  20 +- for development, the IP addresses of the Vagrant VMs are defined in
  21 + ips.development.yaml.
22 22  
23   -Todos os parâmetros de configuração estão definidos no arquivo nodes.yaml
  23 +- for production, you need to create a new file called `ips.production.yaml`
  24 +
  25 +You will probably not need to change nodes.yaml unless you are developing the
  26 +deployment process.
24 27  
25 28 ## Deploy
26 29  
... ... @@ -49,13 +52,13 @@ $ rake converge:$server # deploys only $server
49 52 * TODO: document SSH configuration
50 53  
51 54 ```bash
52   -$ rake NODES=prod.yaml # deploys all servers
53   -$ rake nodes NODES=prod.yaml # lists all servers
54   -$ rake converge:$server NODES=prod.yaml # deploys only $server
  55 +$ rake SPB_ENV=production # deploys all servers
  56 +$ rake nodes SPB_ENV=production # lists all servers
  57 +$ rake converge:$server SPB_ENV=production # deploys only $server
55 58 ```
56 59  
57   -You can also do `export NODES=prod.yaml` in your shell and omit the
58   -`NODES=prod.yaml` parameter in the `rake` calls.
  60 +You can also do `export SPB_ENV=production` in your shell and omit it in the
  61 +`rake` calls.
59 62  
60 63 See the output of `rake -T` for other tasks.
61 64  
... ...
Rakefile
1 1 require 'chake'
2 2  
  3 +$SPB_ENV = ENV.fetch('SPB_ENV', 'development')
  4 +$SPB_IPS = "ips.#{$SPB_ENV}.yaml"
  5 +
  6 +ips = YAML.load_file($SPB_IPS)
  7 +$nodes.each do |node|
  8 + node.data['peers'] = ips
  9 +end
  10 +
  11 +task :console do
  12 + require 'pry'
  13 + binding.pry
  14 +end
  15 +
3 16 task :test do
4 17 sh './test/run_all'
5 18 end
... ... @@ -7,7 +20,7 @@ end
7 20 task :default => :test
8 21  
9 22 file 'ssh_config.erb'
10   -file '.ssh_config' => ['nodes.yaml', 'ssh_config.erb'] do |t|
  23 +file '.ssh_config' => ['nodes.yaml', $SPB_IPS,'ssh_config.erb'] do |t|
11 24 require 'erb'
12 25 template = ERB.new(File.read('ssh_config.erb'))
13 26 File.open(t.name, 'w') do |f|
... ...
Vagrantfile
... ... @@ -13,7 +13,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
13 13 config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy]
14 14 end
15 15  
16   - ips = YAML.load_file('nodes.yaml').first[1]['peers']
  16 + ips = YAML.load_file('ips.development.yaml')
17 17  
18 18 config.vm.define 'database' do |database|
19 19 database.vm.network 'private_network', ip: ips['database']
... ...
ips.development.yaml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +integration: 10.10.10.2
  2 +email: 10.10.10.3
  3 +social: 10.10.10.4
  4 +database: 10.10.10.5
  5 +reverseproxy: 10.10.10.6
  6 +
... ...
nodes.yaml
... ... @@ -15,41 +15,27 @@ vagrant@integration:
15 15 lists_hostname: listas.softwarepublico.dev
16 16 lists_admin: paulo@softwarelivre.org
17 17 relay_hostname: relay.softwarepublico.dev
18   - peers: &PEERS
19   - integration: 10.10.10.2
20   - email: 10.10.10.3
21   - social: 10.10.10.4
22   - database: 10.10.10.5
23   - reverseproxy: 10.10.10.6
24 18 vagrant@email:
25 19 run_list:
26 20 - role[server]
27 21 - role[email_server]
28 22 config:
29 23 <<: *CONFIG
30   - peers:
31   - <<: *PEERS
32 24 vagrant@social:
33 25 run_list:
34 26 - role[server]
35 27 - role[social_server]
36 28 config:
37 29 <<: *CONFIG
38   - peers:
39   - <<: *PEERS
40 30 vagrant@database:
41 31 run_list:
42 32 - role[server]
43 33 - role[database_server]
44 34 config:
45 35 <<: *CONFIG
46   - peers:
47   - <<: *PEERS
48 36 vagrant@reverseproxy:
49 37 run_list:
50 38 - role[server]
51 39 - role[reverse_proxy_server]
52 40 config:
53 41 <<: *CONFIG
54   - peers:
55   - <<: *PEERS
... ...
test/ip_helper.sh
... ... @@ -4,7 +4,7 @@
4 4 # curl http://$reverseproxy
5 5 # nmap -p 5423 $database
6 6 #
7   -# Each node in the `peers:` entry in nodes.yaml will have its own variable
  7 +# Each entry in ips.${SPB_ENV}.yaml will have its own variable
8 8 #
9 9  
10   -eval $(sed -E '/[0-9]{1,3}\./!d; s/^ *//; s/: */=/' ${ROOTDIR:-/vagrant}/nodes.yaml)
  10 +eval $(sed -E '/[0-9]{1,3}\./!d; s/^ *//; s/: */=/' ${ROOTDIR:-.}/ips.${SPB_ENV:-development}.yaml)
... ...