diff --git a/applications/mysql/mysql-start.sh b/applications/mysql/mysql-start.sh new file mode 100644 index 0000000..b48fb7e --- /dev/null +++ b/applications/mysql/mysql-start.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +echo "****************************************************************" +echo "Restarting MYSQL" +echo "****************************************************************" +systemctl restart mysql.service diff --git a/applications/mysql/mysql.sh b/applications/mysql/mysql.sh new file mode 100644 index 0000000..af9c03f --- /dev/null +++ b/applications/mysql/mysql.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Stop Script on Error +set -e + +# For Debugging (print env. variables into a file) +printenv > /var/log/colony-vars-"$(basename "$BASH_SOURCE" .sh)".txt + +apt-get update -y + +# Preparing MYSQL for silent installation +export DEBIAN_FRONTEND="noninteractive" +echo "mysql-server mysql-server/root_password password $DB_PASS" | debconf-set-selections +echo "mysql-server mysql-server/root_password_again password $DB_PASS" | debconf-set-selections + + +# Installing MYSQL +apt-get install mysql-server -y +#apt-get install mysql-client -y + + +# Setting up local permission file +mkdir /home/pk; +bash -c "cat >> /home/pk/my.cnf" < /var/log/colony-vars-"$(basename "$BASH_SOURCE" .sh)".txt + +# Update packages and Upgrade system +echo "****************************************************************" +echo "Updating System" +echo "****************************************************************" +apt-get update -y + + +echo "****************************************************************" +echo "Installing python" +echo "****************************************************************" +sudo apt install -y software-properties-common +sudo add-apt-repository ppa:deadsnakes/ppa +sudo apt update -y +sudo apt install -y python3.8 +sudo apt install -y python3-pip +echo python3 --version + +python3 -m pip install -U numpy --user +python3 -m pip install -U setuptools --user +python3 -m pip install -U Flask --user + +echo "*********************************************" +# echo "last try for python installation" +# sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget +# cd /tmp +# wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz +# tar -xf Python-3.8.3.tgz +# cd python-3.8.3 +# sudo make altinstall +# sudo make install +# echo python --version +# echo python3 --version + +echo "****************************************************************" +echo "Installing Nginx" +echo "****************************************************************" +sudo apt update -y +sudo apt install -y nginx +sudo service nginx start + +cd /etc/nginx/sites-available +cat << EOF > default +server { + listen 3001; + server_name *.com; + # root /var/www/sample-api; + location / { + proxy_pass http://localhost:5000; + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection keep-alive; + proxy_set_header Host \$host; + proxy_cache_bypass \$http_upgrade; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + } +} +EOF + +echo 'sites available modified' + +sudo nginx -s reload + +echo 'reload successful' +echo "****************************************************************" +echo "Installing Nginx compleated" +echo "****************************************************************" + + +echo "****************************************************************" +echo '==> Extract api artifact to /var/sample-api' +echo "****************************************************************" +echo $ARTIFACTS_PATH + +mkdir $ARTIFACTS_PATH/drop +tar -xvf $ARTIFACTS_PATH/sample-api-*.tar.gz -C $ARTIFACTS_PATH/drop/ + +echo $ARTIFACTS_PATH +echo "*********************artifacts copied to root**********************************" +mkdir /var/sample-api/ + +# tar -xvf $ARTIFACTS_PATH/drop/sample-api-* -C /var/sample-api + +echo "**********************copy(scp) to certain folder**************" +# tar -xzvf latest.tar.gz +rsync -av $ARTIFACTS_PATH/drop/sample-api-* /var/sample-api/ + +echo "*********************artifacts copied to root**********************************" + +echo 'RELEASE_NUMBER='$RELEASE_NUMBER >> /etc/environment +echo 'API_BUILD_NUMBER='$API_BUILD_NUMBER >> /etc/environment +echo 'API_PORT='$API_PORT >> /etc/environment +source /etc/environment + +echo "********************Initialization finished*********************" + + +echo '******Start api/script**************************' +echo python3 --version +python3 --version + +# python3 sample-api.py +python3 /var/sample-api/sample-api-0.0.1/src/example/sample-api.py +echo '******End api/Script ***********************************' + +# echo '==> Installing NPM and PM2' +# apt-get update +# apt install curl -y +# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash +# nvm --version + +# npm install -g pm2 + +# echo '==> Start our api and configure as a daemon using pm2' +# pm2 start /var/sample-api/sample-api-0.0.1/src/example/sample-api.py +# pm2 save +# chattr +i /root/.pm2/dump.pm2 + +# echo '==> END our api and configure as a daemon using pm2' diff --git a/applications/sample-api/sample-api.yaml b/applications/sample-api/sample-api.yaml new file mode 100644 index 0000000..bfdc316 --- /dev/null +++ b/applications/sample-api/sample-api.yaml @@ -0,0 +1,52 @@ +spec_version: 1 +kind: application +inputs: +- PORT: 3000 +- API_PORT: 3001 +- AZURE_VM_SIZE: Basic_A1 +- AWS_INSTANCE_TYPE: t2.micro +- RELEASE_NUMBER: none +- API_BUILD_NUMBER: none + +infrastructure: + connectivity: + internal: + - port_info: + port: $PORT + ingress-healthcheck: + healthy-threshold: 5 + interval: 30 + path: / + status-codes: 200-299 + timeout: 2 + unhealthy-threshold: 2 + compute: + spec: + azure: + vm_size: $AZURE_VM_SIZE + aws: + instance_type: $AWS_INSTANCE_TYPE + +configuration: + start: + script: sample-api-command.sh + initialization: + script: sample-api.sh + healthcheck: + wait_for_ports: $API_PORT + timeout: 360 + +source: + image: + docker_image: + - name: ubuntu + tag: 18.04 + ami: + - id: ami-09e67e426f25ce0d7 + region: us-east-1 + username: ubuntu + os_type: linux + +debugging: + connection_protocol: SSH + diff --git a/applications/wordpress/wordpress.sh b/applications/wordpress/wordpress.sh new file mode 100644 index 0000000..94cb193 --- /dev/null +++ b/applications/wordpress/wordpress.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Stop Script on Error +set -e + +# For Debugging (print env. variables into a file) +printenv > /var/log/colony-vars-"$(basename "$BASH_SOURCE" .sh)".txt + +# Update packages and Upgrade system +echo "****************************************************************" +echo "Updating System" +echo "****************************************************************" +apt-get update -y + + +echo "****************************************************************" +echo "Installing Apache" +echo "****************************************************************" +apt-get install apache2 apache2-utils -y +systemctl enable apache2 +systemctl start apache2 + + +echo "****************************************************************" +echo "Installing PHP Modules" +echo "****************************************************************" +apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd -y + + + +echo "****************************************************************" +echo "Installing Wordpress" +echo "****************************************************************" +wget -c http://wordpress.org/latest.tar.gz +tar -xzvf latest.tar.gz +rsync -av wordpress/* /var/www/html/ +chown -R www-data:www-data /var/www/html/ +chmod -R 755 /var/www/html/ +rm /var/www/html/index.html + + +echo "****************************************************************" +echo "Configuring database access" +echo "****************************************************************" +cd /var/www/html || exit +mv wp-config-sample.php wp-config.php + +sed -i "s/database_name_here/$DB_NAME/g" wp-config.php +sed -i "s/username_here/$DB_USER/g" wp-config.php +sed -i "s/password_here/$DB_PASS/g" wp-config.php +sed -i "s/localhost/$DB_HOSTNAME/g" wp-config.php + +systemctl restart apache2.service \ No newline at end of file diff --git a/applications/wordpress/wordpress.yaml b/applications/wordpress/wordpress.yaml new file mode 100644 index 0000000..87ace7e --- /dev/null +++ b/applications/wordpress/wordpress.yaml @@ -0,0 +1,73 @@ +# +# This application file defines how to deploy and +# configure a Wordpress application +# +--- +spec_version: 1 +kind: application + +# These inputs are used by the initialization script to +# configure the connectivity to the database +# In the script we update the connectivity details which +# are located in /var/www/html/wp-config.php +inputs: + - DB_USER + - DB_PASS + - DB_NAME + - DB_HOSTNAME +infrastructure: + # Specify the compute requirement for this app + # if we don't specify anything the default will be used + compute: + spec: + aws: + instance_type: t2.medium + azure: + vm_size: Basic_A2 + + # Port 80 will be opened externally to receive web requests + connectivity: + external: + - port_info: + port: 80 + ingress-healthcheck: + healthy-threshold: 5 + interval: 30 + path: /wp-includes/images/blank.gif + status-codes: 200-299 + timeout: 5 + unhealthy-threshold: 2 + +# This is a clean Ubuntu server image that will be +# used to create a new EC2 instance in the defined AWS region +source: + os_type: linux + image: + ami: + - id: ami-03ef731cc103c9f09 + region: us-east-1 + username: ubuntu + azure_image: + - urn: Canonical:UbuntuServer:16.04-LTS:latest + username: adminuser + docker_image: + - tag: 16.04 + name: ubuntu + +configuration: + # The initialization script is intended to install + # app prerequisite and initialize the OS + # This script installs wordpress on a clean Ubuntu OS. + initialization: + script: wordpress.sh + # This command restarts the Apache server after the initialization completes + start: + command: > + systemctl restart apache2.service + # To validate the installation, we wait to see that the ports are available + healthcheck: + wait_for_ports: ALL + timeout: 1500 + +debugging: + connection_protocol: SSH \ No newline at end of file diff --git a/artifacts/sample-api.tar.gz b/artifacts/sample-api.tar.gz new file mode 100644 index 0000000..f6698df Binary files /dev/null and b/artifacts/sample-api.tar.gz differ diff --git a/blueprints/WordPress Basic Stack(AWS).yaml b/blueprints/WordPress Basic Stack(AWS).yaml new file mode 100644 index 0000000..62473b3 --- /dev/null +++ b/blueprints/WordPress Basic Stack(AWS).yaml @@ -0,0 +1,33 @@ +--- +spec_version: 1 +kind: blueprint + +metadata: + description: LAMP WordPress stack (Linux, Apache, MySQL, PHP) + +clouds: + - AWS: us-east-1 + +# These are the blueprint parameters and their default values. +# The values can be changed when creating a sandbox based on this +# blueprint. +inputs: + - DB_USER: root # Used to define the db admin account + - DB_PASS: + display_style: masked + description: please set the root database password + default_value: 12345 # Used to define the db admin password + - DB_NAME: wordpress_demo # DB_NAME - a target database name + +# These are the applications that will be deployed in this blueprint +applications: + - mysql: # One instance of mysql (see: applications/mysql/mysql.yaml) + input_values: + - DB_USER: $DB_USER + - DB_PASS: $DB_PASS + - DB_NAME: $DB_NAME + depends_on: + - mysql + +debugging: + bastion_availability: enabled-on \ No newline at end of file diff --git a/blueprints/promotions-manager-all-aws-dev.yaml b/blueprints/promotions-manager-all-aws-dev.yaml index 7414a33..2798c53 100644 --- a/blueprints/promotions-manager-all-aws-dev.yaml +++ b/blueprints/promotions-manager-all-aws-dev.yaml @@ -5,7 +5,7 @@ metadata: All in one deployment of our promotions manager clouds: - - AWS: eu-west-1 + - AWS: us-east-1 artifacts: - promotions-manager-ui: artifacts/latest/promotions-manager-ui.master.tar.gz @@ -21,7 +21,7 @@ inputs: applications: - promotions-manager-ui: - #target: vm1 + target: vm1 #instance: 3 input_values: - PORT: $PORT @@ -31,7 +31,7 @@ applications: # - promotions-manager-api - promotions-manager-api: - #target: vm1 + target: vm1 input_values: - API_PORT: $API_PORT - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE @@ -41,7 +41,7 @@ applications: - mongodb: - #target: vm1 + target: vm1 input_values: - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE diff --git a/blueprints/promotions-manager-all-aws-loadtest.yaml b/blueprints/promotions-manager-all-aws-loadtest.yaml index 8a2491f..6eb39ab 100644 --- a/blueprints/promotions-manager-all-aws-loadtest.yaml +++ b/blueprints/promotions-manager-all-aws-loadtest.yaml @@ -5,7 +5,7 @@ metadata: All in one deployment of our promotions manager clouds: - - AWS: eu-west-1 + - AWS: us-east-1 artifacts: - promotions-manager-ui: artifacts/latest/promotions-manager-ui.master.tar.gz @@ -21,8 +21,8 @@ inputs: applications: - promotions-manager-ui: - #target: vm1 - #instances: 3 + target: vm1 + instances: 1 input_values: - PORT: $PORT - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE @@ -31,7 +31,7 @@ applications: # - promotions-manager-api - promotions-manager-api: - #target: vm1 + target: vm1 input_values: - API_PORT: $API_PORT - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE @@ -41,7 +41,7 @@ applications: - mongodb: - #target: vm1 + target: vm1 input_values: - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE diff --git a/blueprints/promotions-manager-all-aws.yaml b/blueprints/promotions-manager-all-aws.yaml index 7414a33..ee8e5df 100644 --- a/blueprints/promotions-manager-all-aws.yaml +++ b/blueprints/promotions-manager-all-aws.yaml @@ -5,7 +5,7 @@ metadata: All in one deployment of our promotions manager clouds: - - AWS: eu-west-1 + - AWS: us-east-1 artifacts: - promotions-manager-ui: artifacts/latest/promotions-manager-ui.master.tar.gz diff --git a/blueprints/sample-api-aws.yaml b/blueprints/sample-api-aws.yaml new file mode 100644 index 0000000..cc7c1f2 --- /dev/null +++ b/blueprints/sample-api-aws.yaml @@ -0,0 +1,32 @@ +spec_version: 1 +kind: blueprint +metadata: + description: > + sample api deployment blueprint + +clouds: + - AWS: us-east-1 + +artifacts: + - sample-api: artifacts/sample-api/sample-api-0.0.1.tar.gz + +inputs: +- PORT: 3000 +- API_PORT: 3001 +- AWS_INSTANCE_TYPE: t2.micro +- RELEASE_NUMBER: none +- API_BUILD_NUMBER: none + +applications: + - sample-api: + # target: vm1 + instances: 1 + input_values: + - API_PORT: $API_PORT + - AWS_INSTANCE_TYPE: $AWS_INSTANCE_TYPE + - RELEASE_NUMBER: $RELEASE_NUMBER + - API_BUILD_NUMBER: $API_BUILD_NUMBER + +debugging: + availability: on + diff --git a/images/wordpress-logo.png b/images/wordpress-logo.png new file mode 100644 index 0000000..b5c9f4c Binary files /dev/null and b/images/wordpress-logo.png differ