Last active
December 11, 2015 05:49
-
-
Save krimdomu/4555039 to your computer and use it in GitHub Desktop.
Using Amazon to create dev machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
use Rex::Commands::Cloud; | |
use Rex::Commands::SimpleCheck; | |
use Rex::Commands::SCM; | |
use Rex::Commands::Iptables; | |
my $access_key = "your-access-key"; | |
my $secret_access_key = "your-secret-key"; | |
set cloud => service => "Amazon"; | |
set cloud => auth => $access_key, $secret_access_key; | |
set cloud => region => "ec2.eu-west-1.amazonaws.com"; | |
set user => "root"; | |
set private_key => "/home/jan/.ssh/brownbag.pem"; | |
set public_key => "/home/jan/.ssh/brownbag.pub"; | |
set -keyauth; | |
set repository => "devrepo", | |
url => 'https://svn.reposerver.tld/mysvn', | |
type => "subversion", | |
username => 'myuser', | |
password => "svn-passsword"; | |
task prepare => sub { | |
my $param = shift; | |
install package => [qw/ | |
httpd | |
php | |
php-mysql | |
mysql-server | |
/]; | |
file "/etc/php.d/timezone.ini", | |
content => "date.timezone = 'Europe/Berlin'\n", | |
on_change => sub { | |
service httpd => "restart"; | |
}; | |
rmdir "/var/www/html"; | |
co(); | |
setup(); | |
if($param->{name}) { | |
my $server = Rex::get_current_connection()->{server}; | |
my ($instance) = grep { $_->{name} eq $param->{name} } cloud_instance_list; | |
say "Forum ist jetzt auf http://$server erreichbar."; | |
} | |
}; | |
task co => sub { | |
checkout "devrepo", | |
path => "/var/www/html"; | |
chown "apache", "/var/www/html", | |
recursive => 1; | |
}; | |
task setup => sub { | |
service mysqld => ensure => "started"; | |
service httpd => ensure => "started"; | |
run "mysql -e 'drop schema phpbb'"; | |
run "mysql -e 'create schema phpbb'"; | |
run "mysql phpbb < /var/www/html/db/brownbag.sql"; | |
iptables -F; | |
file "/var/www/html/config.php", | |
content => template('@config.php', | |
user => "root", | |
password => "", | |
host => "", | |
); | |
}; | |
environment dev => sub { | |
before prepare => sub { | |
my ($server, $server_ref, $param) = @_; | |
if($param->{"create-vm"}) { | |
my $vol_id = cloud_volume create => { size => 1, zone => "eu-west-1a", }; | |
print "vol_id: $vol_id\n"; | |
my $instance = cloud_instance create => { | |
image_id => "ami-5187bb25", | |
name => $param->{name}, | |
key => "brownbag", | |
volume => $vol_id, | |
zone => "eu-west-1a", | |
type => "m1.large", | |
}; | |
print "Waiting for SSH to come up."; | |
while( ! is_port_open ($instance->{ip}, 22) ) { | |
print "."; | |
sleep 1; | |
} | |
sleep 10; | |
$$server_ref = $instance->{ip}; | |
} | |
}; | |
}; | |
1; | |
__DATA__ | |
@config.php | |
<?php | |
// phpBB 3.0.x auto-generated configuration file | |
// Do not change anything in this file! | |
$dbms = 'mysqli'; | |
$dbhost = '<%= $::host %>'; | |
$dbport = ''; | |
$dbname = 'phpbb'; | |
$dbuser = '<%= $::user %>'; | |
$dbpasswd = '<%= $::password %>'; | |
$table_prefix = 'phpbb_'; | |
$acm_type = 'file'; | |
$load_extensions = ''; | |
@define('PHPBB_INSTALLED', true); | |
// @define('DEBUG', true); | |
// @define('DEBUG_EXTRA', true); | |
?> | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment