3. Cloudify - Hello World Server

With Cloudify, we can deploy cloud applications through either the CLI or the Cloudify Manager. The Cloudify Manager is a dedicated environment for managing your cloud applications, handle blueprints, plugins and deployments.

In this tutorial, we will use a Docker image with the community edition of the Cloudify Manager to deploy an Hello World server locally on your computer.

Table of Contents:


Prerequisites

Note: This tutorial is tested with Cloudify 5.0.0

Warm Up

  • Open a terminal and start the Docker container containing the Cloudify Manager. The first time, this command will download the Docker container. Depending on your internet connection, this may require few minutes to complete.
sudo docker run --name cfy_manager_local -d --restart unless-stopped -v /sys/fs/cgroup:/sys/fs/cgroup:ro --tmpfs /run --tmpfs /run/lock --security-opt seccomp:unconfined --cap-add SYS_ADMIN -p 80:80 -p 8000:8000 cloudifyplatform/community-cloudify-manager-aio

Unable to find image 'cloudifyplatform/community-cloudify-manager-aio:latest' locally
latest: Pulling from cloudifyplatform/community-cloudify-manager-aio
7dc0dca2b151: Pull complete
36419b0b9a07: Pull complete
7e325147c43b: Pull complete
afc559a28010: Pull complete
d829f4717ec9: Pull complete
3a89461e4bbe: Pull complete
2934663eea88: Pull complete
4d20f997804e: Pull complete
90c089034ae9: Pull complete
Digest: sha256:c6c6fe90f28d1584936af9348a14ed3c8798dd5ea915352635d8a7b62c6e47f7
Status: Downloaded newer image for cloudifyplatform/community-cloudify-manager-aio:latest
352924eb411ec95e1b13c12cdb15b93257aeea56fb1a6d354436d33bf06364f9
  • We can connect to the Cloudify Manager inside the Docker container from the Cloudify CLI. First, we have to create a user profile in the Cloudify CLI. We will contact the manager at 127.0.0.1, use the admin-admin access credentials and the default tenant.
cfy profiles use 127.0.0.1 -u admin -p admin -t default_tenant

Attempting to connect to 127.0.0.1 through port 80, using http (SSL mode: False)...
Initializing profile 127.0.0.1...
Initialization completed successfully
Using manager 127.0.0.1 with port 80

  • Before start using the manager, we should check whether the profile was successfully created.
cfy profiles list

Listing all profiles...

Profiles:
+------------+------------+------------------+----------------+----------+--------------+----------+--------------+-----------+---------------+------------------+
|    name    | manager_ip | manager_username | manager_tenant | ssh_user | ssh_key_path | ssh_port | kerberos_env | rest_port | rest_protocol | rest_certificate |
+------------+------------+------------------+----------------+----------+--------------+----------+--------------+-----------+---------------+------------------+
| *127.0.0.1 | 127.0.0.1  |      admin        | default_tenant |           |              |    22    |    False       |      80    |      http     |                  |
+------------+------------+------------------+----------------+----------+--------------+----------+--------------+-----------+---------------+------------------+

  • Now we can send commands to the Cloudify Manager through the Cloudify CLI. This means that (CFY) commands are now sent to the Cloudify Manager, not executed locally. We can check that the Cloudify Manager is running by retrieving its status.
cfy status

Retrieving manager services status... [ip=127.0.0.1]

Services:
+-------------------------------+---------+
|            service            |  status |
+-------------------------------+---------+
| Management Worker              | running |
| AMQP-Postgres                  | running |
| Cloudify Console               | running |
| RabbitMQ                       | running |
| PostgreSQL                     | running |
| Webserver                      | running |
| Manager Rest-Service           | running |
+-------------------------------+---------+

Deploy

  • To deploy the Hello World blueprint, we use the install command giving as argument the (url of the) zip containing the blueprint.
cfy install https://github.com/cloudify-examples/local-simple-python-webserver-blueprint/archive/master.zip

https://github.com/cloudify-examples/local-simple-python-webserver-blueprint/archive/master.zip
Downloading https://github.com/cloudify-examples/local-simple-python-webserver-blueprint/archive/master.zip to /tmp/tmpee_aHH...
Uploading blueprint /tmp/tmpJCjKKe/local-simple-python-webserver-blueprint-master/blueprint.yaml...
 blueprint.yaml |######################################################| 100.0%
Blueprint uploaded. The blueprint's id is local-simple-python-webserver-blueprint-master
Creating new deployment from blueprint local-simple-python-webserver-blueprint-master...
Deployment created. The deployment's id is local-simple-python-webserver-blueprint-master
Executing workflow `install` on deployment `local-simple-python-webserver-blueprint-master` [timeout=900 seconds]
Deployment environment creation is pending...
2019-10-02 09:01:09.086  CFY <local-simple-python-webserver-blueprint-master> Starting 'create_deployment_environment' workflow execution
2019-10-02 09:01:09.089  CFY <local-simple-python-webserver-blueprint-master> Creating deployment work directory
2019-10-02 09:01:09.378  CFY <local-simple-python-webserver-blueprint-master> 'create_deployment_environment' workflow execution succeeded
2019-10-02 09:01:13.355  CFY <local-simple-python-webserver-blueprint-master> Starting 'install' workflow execution
2019-10-02 09:01:13.796  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Validating node instance before creation: nothing to do
2019-10-02 09:01:13.926  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Precreating node instance: nothing to do
2019-10-02 09:01:13.997  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Creating node instance
2019-10-02 09:01:14.370  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.create] Sending task 'script_runner.tasks.run'
2019-10-02 09:01:16.437  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.create] INFO: Downloaded install.py to /tmp/JT5VV/install.py
2019-10-02 09:01:16.537  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.create] INFO: Running WebServer locally on port: 8000
2019-10-02 09:01:16.540  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.create] INFO: Setting `pid` runtime property: 1175
2019-10-02 09:01:17.202  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.create] Task succeeded 'script_runner.tasks.run'
2019-10-02 09:01:17.219  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Node instance created
2019-10-02 09:01:17.536  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Configuring node instance: nothing to do
2019-10-02 09:01:17.630  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Starting node instance: nothing to do
2019-10-02 09:01:17.834  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Poststarting node instance: nothing to do
2019-10-02 09:01:18.084  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Node instance started
2019-10-02 09:01:18.463  CFY <local-simple-python-webserver-blueprint-master> 'install' workflow execution succeeded
Finished executing workflow install on deployment local-simple-python-webserver-blueprint-master
* Run 'cfy events list 38e3c1d8-186e-41dd-bb80-cdf8ef374569' to retrieve the execution events/logs
  • We can retrieve the list of the instances of the nodes we have just deployed. We can see that there is one node, that is the HTTP Web Server
cfy node-instances list

Listing all instances...

Node-instances:
+------------------------+------------------------------------------------+---------+-----------------+---------+------------+----------------+------------+
|           id           |               deployment_id                    | host_id |      node_id    |  state  | visibility |  tenant_name   | created_by |
+------------------------+------------------------------------------------+---------+-----------------+---------+------------+----------------+------------+
| http_web_server_7qpr3r | local-simple-python-webserver-blueprint-master |         | http_web_server | started |   tenant   | default_tenant |    admin   |
+------------------------+------------------------------------------------+---------+-----------------+---------+------------+----------------+------------+

Take note of the deployment_ID field value.

  • To check that the deployment actually succeeded, we can go to localhost:8000. The server should return the following page.

HelloWorld

Uninstall

  • We can now remove the Hello World blueprint to uninstall the web server. Use the deployment_ID values from the previous step.
cfy uninstall local-simple-python-webserver-blueprint-master

Executing workflow `uninstall` on deployment `local-simple-python-webserver-blueprint-master` [timeout=900 seconds]
2019-10-02 09:04:57.001  CFY <local-simple-python-webserver-blueprint-master> Starting 'uninstall' workflow execution
2019-10-02 09:04:57.270  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Stopping node instance
2019-10-02 09:04:57.597  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Validating node instance after deletion: nothing to do
2019-10-02 09:04:57.655  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Stopped node instance: nothing to do
2019-10-02 09:04:57.978  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Unlinking relationships
2019-10-02 09:04:58.257  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Relationships unlinked
2019-10-02 09:04:58.450  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Deleting node instance
2019-10-02 09:04:58.549  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.delete] Sending task 'script_runner.tasks.run'
2019-10-02 09:05:00.541  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.delete] INFO: Downloaded uninstall.py to /tmp/Z3FT0/uninstall.py
2019-10-02 09:05:00.632  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.delete] INFO: Running process PID: 1175
2019-10-02 09:05:00.632  LOG <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.delete] INFO: Python Webserver Terminated!
2019-10-02 09:05:00.978  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r.delete] Task succeeded 'script_runner.tasks.run'
2019-10-02 09:05:01.171  CFY <local-simple-python-webserver-blueprint-master> [http_web_server_7qpr3r] Deleted node instance
2019-10-02 09:05:01.563  CFY <local-simple-python-webserver-blueprint-master> 'uninstall' workflow execution succeeded
Finished executing workflow uninstall on deployment local-simple-python-webserver-blueprint-master
* Run 'cfy events list cdd6a867-8f7c-4d4c-93d1-21dbbba948eb' to retrieve the execution events/logs
Trying to delete deployment local-simple-python-webserver-blueprint-master...
Deployment deleted
Deleting blueprint local-simple-python-webserver-blueprint-master...
Blueprint deleted

  • We can delete the Cloudify CLI profile.
cfy profiles delete $(name of the profile)

Deleting profile 127.0.0.1...
Profile deleted
  • We can remove the Docker with the Cloudify Manager.
sudo docker rm -f cfy_manager_local

cfy_manager_local

Conclusion

In this tutorial, we used the Cloudify Manager to deploy a simple web server on our computer. Of course, this was just to familiarize with the framework and check that everything was ready and running. In other tutorials, we will see how to deploy the same Hello World example in an actual cloud service provider, AWS.

Last modified: 26 December 2019