Class: Aemninja::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/aemninja.rb

Constant Summary collapse

ROOT_PATH =
".aemninja"
CONFIG_PATH =
File.join(ROOT_PATH, "config")
ENVIRONMENTS_PATH =
File.join(CONFIG_PATH, "environments")
ENVIRONMENT_CONFIG_FILE_LOCAL =
File.join(ENVIRONMENTS_PATH, "local.rb")
ENVIRONMENT_CONFIG_FILE_STAGING =
File.join(ENVIRONMENTS_PATH, "staging.rb")
ENVIRONMENT_CONFIG_FILE_PRODUCTION =
File.join(ENVIRONMENTS_PATH, "production.rb")

Instance Method Summary collapse

Instance Method Details

#deploy!(package, environment = 'local') ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/aemninja.rb', line 111

def deploy!(package, environment='local')

  # Read Environment from Config File
  #host = "localhost:4503"
  #user = "admin"
  #password = "admin"


  # Do It
  if File.exists?(package)
     if File.file?(package)
      #puts 'deploy package ' + package +  ' to ' + environment

      package_without_path = Aemninja::Helpers::remove_path_from package
      stripped_pkg = Aemninja::Helpers::remove_path_and_version_from package

      puts "--------------------------------------------------------"
      puts "Deployment to \'#{environment}\' environment"
      puts "--------------------------------------------------------"
      puts
      puts "Configuration: .aemninja/config/environments/#{environment}.rb"
      puts

      require "./.aemninja/config/environments/#{environment}.rb"

      Aemninja.configuration.instances.each do |key, array|
        host = array[:host]
        user = array[:user]
        password = array[:password]

        puts
        puts key.to_s + " [" + host + "]"

        # puts "host: " + host
        # puts "user: " + user
        # puts "password: " + password

        installed_package_name = Aem::is_package_installed? host, user, password, stripped_pkg

        if installed_package_name != nil
          print  "  uninstall " + installed_package_name + " from " + host
          rc = Aem::uninstall host, user, password, installed_package_name
          if rc == true
            puts "   OK"
          else
            puts "   FAILED"
          end

          print "  delete " + installed_package_name + " from " + host
          rc = Aem::delete host, user, password, installed_package_name
          if rc == true
            puts "   OK"
          else
            puts "   FAILED"
          end

        else
          puts "  Package " + package_without_path + " not found on " + host + ". Skipping uninstall."
        end

        print "  install " + package + " to " + host
        rc = Aem::install host, user, password, package
        if rc == true
            puts "   OK"
          else
            puts "   FAILED"
          end
      end



     else
       Aemninja::Errors::not_a_file(package)
     end
  else
    Aemninja::Errors::does_not_exist(package)
  end

exit 0
end

#init!Object



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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/aemninja.rb', line 43

def init!
  if File.directory? ROOT_PATH
    Aemninja::Errors::already_initialized(ROOT_PATH)
  end

  Aemninja::Helpers::create_directory ROOT_PATH
  Aemninja::Helpers::create_directory CONFIG_PATH
  Aemninja::Helpers::create_directory ENVIRONMENTS_PATH

  Aemninja::Helpers::create_file ENVIRONMENT_CONFIG_FILE_LOCAL
  open(ENVIRONMENT_CONFIG_FILE_LOCAL, 'w') do |f|
    f.puts 'Aemninja.configure do |config|'
    f.puts '  config.instances = {'
    f.puts '    author: { host: "localhost:4502", user: "admin", password: "admin"},'
    f.puts '    publish: { host: "localhost:4503", user: "admin", password: "admin"}'
    f.puts '  }'
    f.puts 'end'
  end


  Aemninja::Helpers::create_file ENVIRONMENT_CONFIG_FILE_STAGING
  open(ENVIRONMENT_CONFIG_FILE_STAGING, 'w') do |f|
    f.puts 'Aemninja.configure do |config|'
    f.puts '  config.instances = {'
    f.puts '    author: { host: "localhost:4502", user: "admin", password: "admin"},'
    f.puts '    publish: { host: "localhost:4503", user: "admin", password: "admin"}'
    f.puts '  }'
    f.puts 'end'
  end

  Aemninja::Helpers::create_file ENVIRONMENT_CONFIG_FILE_PRODUCTION
  open(ENVIRONMENT_CONFIG_FILE_PRODUCTION, 'w') do |f|
    f.puts 'Aemninja.configure do |config|'
    f.puts '  config.instances = {'
    f.puts '    author: { host: "localhost:4502", user: "admin", password: "admin"},'
    f.puts '    publish: { host: "localhost:4503", user: "admin", password: "admin"}'
    f.puts '  }'
    f.puts 'end'
  end

  exit 0

end

#list!(environment = 'local') ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/aemninja.rb', line 87

def list!(environment='local')
  puts "--------------------------------------------------------"
  puts "Deployment to \'#{environment}\' environment"
  puts "--------------------------------------------------------"
  puts
  puts "Configuration: .aemninja/config/environments/#{environment}.rb"
  puts

  require "./.aemninja/config/environments/#{environment}.rb"

  Aemninja.configuration.instances.each do |key, array|
    host = array[:host]
    user = array[:user]
    password = array[:password]

    puts
    puts key.to_s + " [" + host + "]"

    Aem::list host, user, password

  end
end

#no_valid_commandObject



192
193
194
# File 'lib/aemninja.rb', line 192

def no_valid_command
  Aemninja::Usage.commands
end