Commit 2ffce5b6 authored by Giuliano Taffoni's avatar Giuliano Taffoni
Browse files

heat

parent 762d11ba
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
heat_template_version: 2013-05-23

description: Simple template to deploy a single compute instance

parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for compute instance
    default: CentOS 7.4 x86_64
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used
    default: m1.medium
  key:
    type: string
    label: Key name
    description: Name of key-pair to be used for compute instance
    default: taffoni_rsa
  private_network:
    type: string
    label: Private network name or ID
    description: Network to attach instance to.
    default: oats_net

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - network: { get_param: private_network }
      user_data: |
        #!/bin/sh
        echo "Hello, World!"
      user_data_format: RAW

outputs:
  instance_name:
    description: Name of the instance
    value: { get_attr: [my_instance, name] }
  instance_ip:
    description: IP address of the instance
    value: { get_attr: [my_instance, first_address] }
+13 −0
Original line number Diff line number Diff line
heat_template_version: 2013-05-23

description: Simple template to deploy a single compute instance

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: cirros-0.3.3-x86_64
      flavor: m1.small
      key_name: my_key
      networks:
        - network: private-net
+40 −0
Original line number Diff line number Diff line
heat_template_version: 2013-05-23

description: Simple template to deploy a single compute instance

parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for compute instance
    default: cirros-0.3.3-x86_64
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used
    default: m1.small
  key:
    type: string
    label: Key name
    description: Name of key-pair to be used for compute instance
    default: my_key
  private_network:
    type: string
    label: Private network name or ID
    description: Network to attach instance to.
    default: private-net

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - network: { get_param: private_network }

outputs:
  instance_ip:
    description: IP address of the instance
    value: { get_attr: [my_instance, first_address] }
+47 −0
Original line number Diff line number Diff line
heat_template_version: 2013-05-23
 
description: Simple template to deploy a single compute instance
 
parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for compute instance
    default: cirros-0.3.3-x86_64
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used
    default: m1.small
  key:
    type: string
    label: Key name
    description: Name of key-pair to be used for compute instance
    default: my_key
  private_network:
    type: string
    label: Private network name or ID
    description: Network to attach instance to.
    default: private-net
 
resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - network: { get_param: private_network }
      user_data: |
        #!/bin/sh
        echo "Hello, World!"
      user_data_format: RAW
 
outputs:
  instance_name:
    description: Name of the instance
    value: { get_attr: [my_instance, name] }
  instance_ip:
    description: IP address of the instance
    value: { get_attr: [my_instance, first_address] }
+145 −0
Original line number Diff line number Diff line
heat_template_version: 2013-05-23

description: This template deploys a Flasky single instance server with a SQLite database.

parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for the server. Please use an Ubuntu based image.
    default: trusty-server-cloudimg-amd64
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used on the compute instance.
    default: m1.small
  key:
    type: string
    label: Key name
    description: Name of key-pair to be installed on the compute instance.
    default: my_key
  private_network:
    type: string
    label: Private network name or ID
    description: Private network to attach server to.
    default: private-net
  gmail_username:
    type: string
    label: Gmail account username
    description: Username of the Gmail account to use for notifications.
  gmail_password:
    type: string
    label: Gmail account password
    description: Password of the Gmail account to use for notifications.
    hidden: true

resources:
  flask_secret_key:
    type: OS::Heat::RandomString
    properties:
      length: 32
      sequence: lettersdigits

  flasky_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - network: { get_param: private_network }
      user_data_format: RAW
      user_data:
        str_replace:
          params:
            __gmail_username__: { get_param: gmail_username }
            __gmail_password__: { get_param: gmail_password }
            __flask_secret_key__: { get_attr: [flask_secret_key, value] }
          template: |
            #!/bin/bash -ex

            # install dependencies
            apt-get update
            apt-get -y install build-essential python python-dev python-virtualenv nginx supervisor git

            # create a flasky user to run the server process
            adduser --disabled-password --gecos "" flasky

            # clone flasky from github
            cd /home/flasky
            git clone https://github.com/miguelgrinberg/flasky-first-edition.git
            mv flasky-first-edition flasky
            cd flasky

            # Write configuration file
            cat >.env <<EOF
            FLASK_CONFIG=heroku
            SECRET_KEY=__flask_secret_key__
            DATABASE_URL=sqlite:////home/flasky/flasky/appdb.sqlite
            MAIL_USERNAME=__gmail_username__
            MAIL_PASSWORD=__gmail_password__
            FLASKY_ADMIN=__gmail_username__@gmail.com
            SSL_DISABLE=1
            EOF

            # create a virtualenv and install dependencies
            virtualenv venv
            venv/bin/pip install -r requirements/prod.txt
            venv/bin/pip install gunicorn==18.0

            # create database
            venv/bin/python manage.py deploy

            # make the flasky user the owner of the application
            chown -R flasky:flasky ./

            # configure supervisor to run a private gunicorn web server, and
            # to autostart it on boot and when it crashes
            # stdout and stderr logs from the server will go to /var/log/flasky
            mkdir /var/log/flasky
            cat >/etc/supervisor/conf.d/flasky.conf <<EOF
            [program:flasky]
            command=/home/flasky/flasky/venv/bin/gunicorn -b 127.0.0.1:8000 -w 4 --chdir /home/flasky/flasky --log-file - manage:app
            user=flasky
            autostart=true
            autorestart=true
            stderr_logfile=/var/log/flasky/stderr.log
            stdout_logfile=/var/log/flasky/stdout.log
            EOF
            supervisorctl reread
            supervisorctl update

            # configure nginx as the front-end web server with a reverse proxy
            # rule to the gunicorn server
            cat >/etc/nginx/sites-available/flasky <<EOF
            server {
                listen 80;
                server_name _;
                access_log /var/log/nginx/flasky.access.log;
                error_log /var/log/nginx/flasky.error.log;
                location / {
                    proxy_pass http://127.0.0.1:8000;
                    proxy_redirect off;
                    proxy_set_header Host \$host;
                    proxy_set_header X-Real-IP \$remote_addr;
                    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
                }
                location /static {
                    alias /home/flasky/flasky/static;
                }
                location /favicon.ico {
                    alias /home/flasky/flasky/favicon.ico;
                }
            }
            EOF
            rm -f /etc/nginx/sites-enabled/default
            ln -s /etc/nginx/sites-available/flasky /etc/nginx/sites-enabled/
            service nginx restart

outputs:
  instance_name:
    description: Name of the instance
    value: { get_attr: [flasky_instance, name] }
  instance_ip:
    description: The IP address of the deployed instance
    value: { get_attr: [flasky_instance, first_address] }
Loading