ec2launcher 1.0.16 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.17
2
+
3
+ * Added support to substitute the application name and environment name in pre/post commands.
4
+
1
5
  ## 1.0.16
2
6
 
3
7
  * Added support for custom paths to ruby, gem, chef-client and knife executables.
data/lib/ec2launcher.rb CHANGED
@@ -698,6 +698,16 @@ module EC2Launcher
698
698
  new_env
699
699
  end
700
700
 
701
+ # Given a string containing a command to run, replaces any inline variables.
702
+ # Supported variables include:
703
+ # * @APPLICATION@ - name of the application
704
+ # * @ENVIRONMENT@ - name of the environment
705
+ #
706
+ # @return [String] command with variables replaced
707
+ def substitute_command_variables(cmd)
708
+ cmd.gsub(/@APPLICATION@/, @application.name).gsub(/@ENVIRONMENT@/, @environment.name)
709
+ end
710
+
701
711
  # Validates all settings in an application file
702
712
  #
703
713
  # @param [String] filename name of the application file
@@ -767,8 +777,8 @@ module EC2Launcher
767
777
 
768
778
  # pre-commands, if necessary
769
779
  unless @environment.precommands.nil? || @environment.precommands.empty?
770
- precommands = @environment.precommands.join("\n")
771
- user_data += "\n" + precommands
780
+ commands = @environment.precommands.collect {|cmd| substitute_command_variables(cmd) }
781
+ user_data += "\n" + commands.join("\n")
772
782
  end
773
783
 
774
784
  user_data += "\n"
@@ -806,12 +816,16 @@ module EC2Launcher
806
816
  user_data += " 2>&1 > /var/log/cloud-startup.log"
807
817
 
808
818
  # Add extra requested commands to the launch sequence
819
+ unless @options.commands.nil?
820
+ commands = @environment.commands.collect {|cmd| substitute_command_variables(cmd) }
821
+ user_data += "\n" + commands.join("\n")
822
+ end
809
823
  @options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
810
824
 
811
825
  # Post commands
812
826
  unless @environment.postcommands.nil? || @environment.postcommands.empty?
813
- postcommands = @environment.postcommands.join("\n")
814
- user_data += "\n" + postcommands
827
+ commands = @environment.postcommands.collect {|cmd| substitute_command_variables(cmd) }
828
+ user_data += "\n" + commands.join("\n")
815
829
  end
816
830
  user_data
817
831
  end
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.0.16"
5
+ VERSION = "1.0.17"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: