Skip to content

Instantly share code, notes, and snippets.

@allthingsclowd
Created January 24, 2017 19:37
Show Gist options
  • Select an option

  • Save allthingsclowd/cce69acf7c82a20b739824397e81476f to your computer and use it in GitHub Desktop.

Select an option

Save allthingsclowd/cce69acf7c82a20b739824397e81476f to your computer and use it in GitHub Desktop.
Fujitsu K5 Demo Stack that deploys PHP-CMSimple Application
heat_template_version: 2013-05-23
# Author: Graham Land
# Date: 24/01/2017
# Website: https//allthingscloud.eu
# Purpose: Template to demonstrate the basic format/usage of HOT template to deploy a PHP_CMSimple Server
description: PHP_CMSimple Demo Server
# Input parameters
parameters:
ubuntuimage:
type: string
label: Image name or ID
description: Image to be used for server. Please use an Ubuntu based image.
default: "Ubuntu Server 14.04 LTS (English) 01"
public_net:
type: string
label: external network ID az1
description: Public network
default: "d730db50-0e0c-4790-9972-1f6e2b8c4915"
flavor:
type: string
label: Flavor
description: Type of instance (flavor) to be used
default: "P-1"
default-sshkey:
type: string
label: Key name
description: Name of key-pair to be used for compute instance
default: "demostack"
web_tier_network:
type: string
label: Web Tier L2 Network
description: Web Tier Network to attach instance to.
default: "WEB-NET"
web_tier_cidr:
type: string
label: Private network name or ID
description: Network to attach instance to.
default: "172.16.20.0/24"
web_tier_pool_start:
type: string
label: web_tier_network dhcp pool start address
description: Start of DHCP range
default: "172.16.20.10"
web_tier_pool_end:
type: string
label: web_tier_network dhcp pool end address
description: End of DHCP range
default: "172.16.20.49"
web_static_ip:
type: string
label: web server static ip address
description: static ip for instance
default: "172.16.20.50"
az:
type: string
label: Availability Zone
description: Region AZ to use
default: "uk-1b"
externalrouter:
type: string
label: web tier router
description: Router with external access for global ip allocation
default: "bc9db0d3-25d2-4adf-8624-91b8331945d7"
# K5 Infrastructure resources to be built
resources:
# Create the web tier network
web_tier_net:
type: OS::Neutron::Net
properties:
availability_zone: { get_param: az }
name: { get_param: web_tier_network }
# Create a new web tier subnet on the web tier network
web_tier_subnet:
type: OS::Neutron::Subnet
depends_on: web_tier_net
properties:
availability_zone: { get_param: az }
name: WEB_SUBNET
network_id: { get_resource: web_tier_net }
cidr: { get_param: web_tier_cidr }
gateway_ip: "172.16.20.1"
allocation_pools:
- start: { get_param: web_tier_pool_start }
end: { get_param: web_tier_pool_end }
host_routes: []
dns_nameservers:
- "8.8.8.8"
# Create a port for the web server interface, assign an ip address
web_server_static_port:
type: OS::Neutron::Port
depends_on: [ web_tier_subnet, web_security_group ]
properties:
availability_zone: { get_param: az }
network_id: { get_resource: web_tier_net }
security_groups: [{ get_resource: web_security_group }]
fixed_ips:
- subnet_id: { get_resource: web_tier_subnet }
ip_address: "172.16.20.50"
# Allocate a floating/global ip address
web_floating_ip:
type: OS::Neutron::FloatingIP
depends_on: [web_server_static_port]
properties:
availability_zone: { get_param: az }
floating_network_id: { get_param: public_net }
# Assign a floating/global ip address to the fixed server ip address
web_floating_ip_association:
type: OS::Neutron::FloatingIPAssociation
depends_on: [ web_floating_ip ]
properties:
floatingip_id: { get_resource: web_floating_ip }
port_id: { get_resource: web_server_static_port }
# Connect an interface on the web tier network's subnet to the external network router
web_router_interface:
type: OS::Neutron::RouterInterface
depends_on: [web_tier_subnet]
properties:
router_id: { get_param: externalrouter }
subnet_id: { get_resource: web_tier_subnet }
# Create a security group
web_security_group:
type: OS::Neutron::SecurityGroup
properties:
description: Add security group rules for server
name: "WEB-SG"
rules:
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 22
port_range_max: 22
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 80
port_range_max: 80
- remote_ip_prefix: 0.0.0.0/0
protocol: icmp
# Add Web Server
# Create a data volume for use with the server
data_vol:
type: OS::Cinder::Volume
properties:
availability_zone: { get_param: az }
description: Data volume
name: "web-data-vol"
size: 3
volume_type: "M1"
# Create a system volume for use with the server
sys-vol:
type: OS::Cinder::Volume
properties:
availability_zone: { get_param: az }
name: "web-boot-vol"
size: 3
volume_type: "M1"
image : { get_param: ubuntuimage }
# Build a server using the system volume defined above
server:
type: OS::Nova::Server
depends_on: [ web_floating_ip_association ]
properties:
key_name: { get_param: default-sshkey }
image: { get_param: ubuntuimage }
flavor: { get_param: flavor }
admin_user: ubuntu
block_device_mapping: [{"volume_size": "3", "volume_id": {get_resource: sys-vol}, "delete_on_termination": True, "device_name": "/dev/vda"}]
name: "WEB"
user_data_format: RAW
user_data:
str_replace:
template: |
#cloud-config
apt_update: true
packages:
- nginx
- php5-fpm
- php5-mysql
- php5-mcrypt
- php5-gd
- php5-curl
- git
write_files:
- path: /etc/nginx/sites-available/default
content: |
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?q=$uri&$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
- path: /var/www/html/info.php
content: |
<?php
phpinfo();
?>
- path: /tmp/format-disks
permissions: '0700'
content: |
#!/bin/bash
voldata_id=%voldata_id%
voldata_dev="/dev/disk/by-id/virtio-$(echo ${voldata_id} | cut -c -20)"
mkfs.ext4 ${voldata_dev}
mkdir -pv /mnt/appdata
echo "${voldata_dev} /mnt/appdata ext4 defaults 1 2" >> /etc/fstab
mount /mnt/appdata
runcmd:
- /tmp/format-disks
- mkdir -p /var/www/html
- cp /usr/share/nginx/html/index.html /var/www/html/
- sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php5/fpm/php.ini
# Ensure backwards compatible with 14.04
- file=/etc/nginx/fastcgi.conf; if [ ! -f "$file" ]; then ln -s /etc/nginx/fastcgi_params "$file"; fi
- service nginx restart
- cd /root
- git clone https://github.com/fujitsuk5/K5-Cloud-Foundry-Example-Apps.git
- cp -r /root/K5-Cloud-Foundry-Example-Apps/PHP_CMSimple/* /var/www/html/
- cd /var/www/html/
- chown -R www-data:www-data *
params:
"%voldata_id%": { get_resource: data_vol }
message: "Installation Complete"
networks:
- port: { get_resource: web_server_static_port }
# Attach previously defined data-vol to the server
attach_vol_web:
type: OS::Cinder::VolumeAttachment
depends_on: [ data_vol, server ]
properties:
instance_uuid: {get_resource: server}
mountpoint: "/dev/vdb"
volume_id: {get_resource: data_vol}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment