Download the application code and deploy to Bluemix
In this section, you download the application code. Then, you deploy it by using the Bluemix CLI.
-
- Return to the sample application GitHub repository at http://github.com/ibmecod/nodejs-cloudant.
- Click Clone or download.
- If you have installed Git on your workstation, copy the Git URL and use the command
git clone
to copy the repository to your workstation:
git clone https://github.com/ibmecod/nodejs-cloudant.git
- Otherwise, use the Download ZIP link and unzip the project to a new folder or directory on your workstation.
- If you have installed Git on your workstation, copy the Git URL and use the command
- Open a terminal and set the current directory to the application code directory. The
package.json
andmanifest.yml
files will be in this directory. - Log in to your Bluemix region with one of the following commands:
- Return to the sample application GitHub repository at http://github.com/ibmecod/nodejs-cloudant.
bx login -a https://api.ng.bluemix.net // US South
bx login -a https://api.eu-gb.bluemix.net // United Kingdom
bx login -a https://api.eu-de.bluemix.net // Germany
bx login -a https://api.au-syd.bluemix.net // Sydney
- Enter the email and password that you used to log in to the Bluemix web UI. If prompted, select the organization and space that you want to work in.
- Before you deploy the application, create a Cloudant database service instance. View the available services in the Bluemix catalog by running the bx
service offerings
command. This command takes a little while to run because it collects all catalog entries.
cloudantNoSQLDB Lite, Standard* Cloudant NoSQL DB is a fully managed data layer designed for modern web and mobile applications that leverages a flexible JSON schema. Cloudant is built upon and compatible with Apache CouchDB and accessible through a secure HTTPS API, which scales as your application grows. Cloudant is ISO27001 and SOC2 Type 1 certified, and all data is stored in triplicate across separate physical nodes in a cluster for HA/DR within a data center.
$ bx service offerings
Invoking 'cf marketplace'...
Getting services from marketplace in org bluemixuser / space dev as [email protected]
...
cloudamqp lemur, bunny*, panda*, rabbit*, tiger*, ape*, hippo* Managed HA RabbitMQ servers in the cloud
cloudautomationmanager Standard Provision cloud infrastructure and applications in multiple cloud providers.
…
$ - Create an instance of the Cloudant NoSQL database with this command:
$ bx service create cloudantNoSQLDB Lite myCloudantDB
where:cloudantNoSQLDB
is the name of the service in the catalog.Lite
is the desired service plan. The Lite plan provides a free NoSQL database for nonproduction use.myCloudantDB
is the name to assign to the service instance. This name needs to be unique only within the Cloud Foundry space. If you assign a different name, use that name in the commands later in this lab.
- Push the application to Bluemix by entering the following command. Change the application name
favapp-tor-0517
in the example to a customized name with your initials and date.
$ bx app push favapp-tor-0517 -c "node app.js" -m 128M --no-manifest --no-start
where:-
-c "node app.js"
is the command to start the application.
-
-m 128M
allocates 128M memory to the application.
-
--no-manifest
tells the CLI to ignore the manifest file in the current directory, which allows you to bind the service that was just created to the app.
--no-start
tells Bluemix not to automatically start the application after upload.
You don’t want the application to start automatically because it needs a database to run. You must link the Cloudant database instance to the application before you start the application. In Cloud Foundry, the action of linking is described as binding the service instance.
-
- Bind the service to the application:
$ bx service bind favapp-tor-0517 myCloudantDB
where:favapp-tor-0517
: change this to the name of your application.myCloudantDB
is the name of the service instance you created. If you changed this name previously, be sure to use the correct name.
- Start the application by running the following command. Substitute the name of your application. The terminal will display the stream output from the build of the application and deployment to Bluemix. The output will end with a status report.
$ bx app start favapp-tor-0517
...
requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: favapp-tor-0517.mybluemix.net
last uploaded: Sun May 14 03:33:16 UTC 2017
stack: unknown
buildpack: SDK for Node.js(TM) (node.js-6.9.5, buildpack-v3.12-20170505-0656)
state since cpu memory disk details
#0 running 2017-05-13 08:35:34 PM 0.0% 33.8M of 128M 82.2M of 1G - Refresh your Bluemix dashboard. You will see the deployed app. You can click the hostname shown under Route to launch the app in a new browser tab.