Permalink
Fetching contributors…
Cannot retrieve contributors at this time
346 lines (323 sloc) 18.5 KB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "CloudFormation Template for single-instance PublicMapping DistrictBuilder",
"Parameters": {
"KeyName": {
"Description": "The EC2 Key Pair to allow SSH access to the instance",
"Type": "String"
},
"AdminUser": {
"Description": "The username of the system administrator of this DistrictBuilder installation",
"Type": "String"
},
"AdminEmail": {
"Description": "The email of the system administrator of this DistrictBuilder installation",
"Type": "String"
},
"AdminPassword": {
"Description": "The password of the system administrator of this DistrictBuilder installation",
"Type": "String",
"NoEcho": "TRUE"
}
},
"Mappings": {
"RegionMap": {
"us-east-1": {
"64": "ami-7539b41c"
},
"us-west-1": {
"64": "ami-26745463"
}
}
},
"Resources": {
"Ec2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": {
"Ref": "KeyName"
},
"ImageId": {
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"64"
]
},
"InstanceType": "m1.small",
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -ex\n",
"LOG=/var/log/instance.log\n",
"START=$(date +%s)\n",
"apt-get update", " &>> $LOG\n",
"apt-get -y install apache2 libapache2-mod-wsgi python-dev python-django python-lxml python-gdal python-rpy2 python-scipy python-psycopg2 python-setuptools postgresql-9.1-postgis tomcat6 tomcat6-admin gettext git gfortran python-dev g++", " &>> $LOG\n",
"easy_install pip", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "AptWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $START)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"APT packages installed.\",\"UniqueId\":\"AptWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"mkdir -p /projects/PublicMapping", " &>> $LOG\n",
"cd /projects/PublicMapping", " &>> $LOG\n",
"git clone git://github.com/PublicMapping/DistrictBuilder.git", " &>> $LOG\n",
"cd DistrictBuilder", " &>> $LOG\n",
"pip install -r requirements.txt", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "PipWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"PIP packages installed.\",\"UniqueId\":\"PipWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"mkdir -p /projects/PublicMapping/local/reports", " &>> $LOG\n",
"chown www-data:www-data /projects/PublicMapping/local/reports", " &>> $LOG\n",
"for f in django/publicmapping/locale/*; do chown www-data:www-data $f/LC_MESSAGES/*o; done", " &>> $LOG\n",
"su postgres -c \"createdb -E UTF8 -T template0 -l en_US.UTF-8 template_postgis\"", " &>> $LOG\n",
"su postgres -c \"psql -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql template_postgis\"", " &>> $LOG\n",
"su postgres -c \"psql -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql template_postgis\"", " &>> $LOG\n",
"echo -e '89a90\n> local all all md5' | patch /etc/postgresql/9.1/main/pg_hba.conf", " &>> $LOG\n",
"service postgresql restart", " &>> $LOG\n",
"cd /projects/PublicMapping/DistrictBuilder/sql", " &>> $LOG\n",
"su postgres -c \"psql -f publicmapping_db.sql\"", " &>> $LOG\n",
"cd /var/lib/tomcat6/webapps", " &>> $LOG\n",
"wget -q -O geoserver-2.0.2-war.zip 'http://downloads.sourceforge.net/project/geoserver/GeoServer/2.0.2/geoserver-2.0.2-war.zip?r=http%3A%2F%2Fgeoserver.org%2Fdisplay%2FGEOS%2FGeoServer%2B2.0.2&ts=1362073334&use_mirror=superb-dca2'", " &>> $LOG\n",
"unzip geoserver-2.0.2-war.zip", " &>> $LOG\n",
"mkdir /projects/PublicMapping/data", " &>> $LOG\n",
"cd /projects/PublicMapping/data", " &>> $LOG\n",
"wget -q --no-check-certificate -O VA_data.zip https://s3.amazonaws.com/districtbuilderdata/VA_data.zip", " &>> $LOG\n",
"mkdir -p /projects/PublicMapping/local/data", " &>> $LOG\n",
"cd /projects/PublicMapping/local/data", " &>> $LOG\n",
"unzip /projects/PublicMapping/data/VA_data.zip", " &>> $LOG\n",
"cd /var/lib/tomcat6/webapps/geoserver/WEB-INF/lib", " &>> $LOG\n",
"wget -q http://downloads.sourceforge.net/project/geoserver/GeoServer%20Extensions/2.0.2/geoserver-2.0.2-restconfig-plugin.zip", " &>> $LOG\n",
"unzip geoserver-2.0.2-restconfig-plugin.zip", " &>> $LOG\n",
"chown tomcat6:tomcat6 restconfig*", " &>> $LOG\n",
"cd /var/lib/tomcat6/webapps/geoserver/WEB-INF", " &>> $LOG\n",
"echo -e '5a6,10\n> <context-param>\n> <param-name>GEOWEBCACHE_CACHE_DIR</param-name>\n> <param-value>/var/lib/tomcat6/webapps/geoserver/data/gwc</param-value>\n> </context-param>\n> \n' | patch web.xml", " &>> $LOG\n",
"service tomcat6 restart", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "DataWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"DB cluster, map server initialized and copied sample data.\",\"UniqueId\":\"DataWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"cd /projects/PublicMapping/DistrictBuilder/docs/", " &>> $LOG\n",
"cp config.dist.xml config.xml", " &>> $LOG\n",
"echo -e '1191c1191\n< <Database name=\"YOUR-DATABASE-NAME\" user=\"publicmapping\" password=\"YOUR-DATABASE-PASSWORD\" host=\"OPTIONAL\"/>\n---\n> <Database name=\"publicmapping\" user=\"publicmapping\" password=\"publicmapping\" host=\"localhost\"/>\n1214c1214\n< <Admin user=\"ADMIN-USER-NAME\" email=\"ADMIN-EMAIL\" password=\"STRONG-PASSWORD\"/>\n---\n> <Admin user=\"", { "Ref": "AdminUser" }, "\" email=\"", { "Ref": "AdminEmail" }, "\" password=\"", { "Ref": "AdminPassword" }, "\"/>\n1240c1240\n< adminuser=\"GEOSERVER-ADMIN-USER\" adminpass=\"GEOSERVER-ADMIN-PASS\" maxfeatures=\"100\" \n---\n> adminuser=\"admin\" adminpass=\"geoserver\" maxfeatures=\"100\" ' | patch config.xml", " &>> $LOG\n",
"cd /projects/PublicMapping/DistrictBuilder/django/publicmapping", " &>> $LOG\n",
"./setup.py ../../docs/config.xsd ../../docs/config.xml -v2 -d", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "CfgWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"Configuration loaded.\",\"UniqueId\":\"CfgWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"./setup.py ../../docs/config.xsd ../../docs/config.xml -v2 -g0 -g1 -g2 -n1 -n2", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "ImportWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"Import & renest complete.\",\"UniqueId\":\"ImportWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"./setup.py ../../docs/config.xsd ../../docs/config.xml -v2 -V -G", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "GeoWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"Geo views & mapserver configuration complete.\",\"UniqueId\":\"GeoWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"./setup.py ../../docs/config.xsd ../../docs/config.xml -v2 -t -s", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "TplWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"Templates and static files configuration complete.\",\"UniqueId\":\"TplWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n",
"STEP=$(date +%s)\n",
"wget -q --no-check-certificate -O /etc/init.d/celeryd https://raw.github.com/ask/celery/master/contrib/generic-init.d/celeryd", " &>> $LOG\n",
"chmod a+x /etc/init.d/celeryd", " &>> $LOG\n",
"update-rc.d celeryd defaults", " &>> $LOG\n",
"cp /projects/PublicMapping/DistrictBuilder/docs/celeryd /etc/default", " &>> $LOG\n",
"mkdir /var/log/celery /var/run/celery", " &>> $LOG\n",
"chown www-data:www-data /var/log/celery /var/run/celery/", " &>> $LOG\n",
"service celeryd start", " &>> $LOG\n",
"SignalURL=\"", { "Ref": "AppWaitHandle" }, "\"\n",
"t0=$(expr $(date +%s) - $STEP)\n",
"t1=$(expr $(date +%s) - $START)\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\":\"SUCCESS\",\"Reason\":\"Initialization complete.\",\"UniqueId\":\"AppWait\",\"Data\":\"This step: '$t0'; cumulative: '$t1'\"}' $SignalURL", " &>> $LOG\n"
]
]
}
},
"SecurityGroups": [
{
"Ref": "InstanceSecurityGroup"
}
]
}
},
"InstanceSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable Access to web application via port 80, SSH access via port 22, map server via port 8080",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "8080",
"ToPort": "8080",
"CidrIp": "0.0.0.0/0"
}
]
}
},
"AptWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"PipWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"DataWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"CfgWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"ImportWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"GeoWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"TplWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"AppWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle",
"Properties": {}
},
"AptCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "Ec2Instance",
"Properties": {
"Handle": { "Ref": "AptWaitHandle" },
"Timeout": "2400"
}
},
"PipCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "AptCondition",
"Properties": {
"Handle": { "Ref": "PipWaitHandle" },
"Timeout": "2400"
}
},
"DataCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "PipCondition",
"Properties": {
"Handle": { "Ref": "DataWaitHandle" },
"Timeout": "2400"
}
},
"CfgCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "DataCondition",
"Properties": {
"Handle": { "Ref": "CfgWaitHandle" },
"Timeout": "600"
}
},
"ImportCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "CfgCondition",
"Properties": {
"Handle": { "Ref": "ImportWaitHandle" },
"Timeout": "43200"
}
},
"GeoCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "ImportCondition",
"Properties": {
"Handle": { "Ref": "GeoWaitHandle" },
"Timeout": "600"
}
},
"TplCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "GeoCondition",
"Properties": {
"Handle": { "Ref": "TplWaitHandle" },
"Timeout": "600"
}
},
"AppCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "TplCondition",
"Properties": {
"Handle": { "Ref": "AppWaitHandle" },
"Timeout": "43200"
}
}
},
"Outputs": {
"PublicIP": {
"Description": "The public IP of the instance.",
"Value": {
"Fn::GetAtt": [
"Ec2Instance",
"PublicIp"
]
}
},
"AptTime": {
"Value": { "Fn::GetAtt": [ "AptCondition", "Data" ]},
"Description": "The time required to install APT sources."
},
"PipTime": {
"Value": { "Fn::GetAtt": [ "PipCondition", "Data" ]},
"Description": "The time required to install PIP sources."
},
"DataTime": {
"Value": { "Fn::GetAtt": [ "DataCondition", "Data" ]},
"Description": "The time required to install Example Data, setup the database, setup the map server."
},
"CfgTime": {
"Value": { "Fn::GetAtt": [ "CfgCondition", "Data" ]},
"Description": "The time required to configure the application database."
},
"ImportTime": {
"Value": { "Fn::GetAtt": [ "ImportCondition", "Data" ]},
"Description": "The time required to import the application data."
},
"GeoTime": {
"Value": { "Fn::GetAtt": [ "GeoCondition", "Data" ]},
"Description": "The time required to configure spatial views and Geoserver."
},
"TplTime": {
"Value": { "Fn::GetAtt": [ "TplCondition", "Data" ]},
"Description": "The time required to load the default templates."
},
"AppTime": {
"Value": { "Fn::GetAtt": [ "AppCondition", "Data" ]},
"Description": "The time required to setup the application completely."
}
}
}