June 18, 2019 By Nathan Hekman 4 min read

You can use the IBM Cloud command-line interface (CLI) to create applications, develop locally, and deploy to IBM Public Cloud. This tutorial will show you how.

Before you begin

You must install the IBM Cloud CLI, the IBM Cloud Developer Tools CLI plug-in, and other recommended plug-ins and tools. For more information, see “Getting started with the IBM Cloud CLI.”

Creating a starter app from scratch and deploying to a DevOps toolchain

Creating an app from scratch is useful if you don’t already have existing code to begin with and would like to start from a language or a framework starter template.

  1. Run the ibmcloud dev create command in the directory of your choice.
  2. Select Backend Service / Web App as the app type.
  3. Select Node as the language type.
  4. Select Node.js Web App with Express.js (Web App) as the starter kit to use.
  5. Enter a name for your app, and select the resource group that you want to use (if necessary). Don’t add services for now.
  6. Select the IBM DevOps, deploy to Cloud Foundry buildpacks option to create a DevOps toolchain. You might need to set up SSH keys to complete this step. If you set a passphrase for your SSH key, you are required to enter this code.
  7. Follow the remaining prompts:
    • Select a region for your toolchain.
    • Enter a name for the DevOps toolchain name.
    • Enter a name for the host name.

Creating the app and deploying to a toolchain takes a few seconds to complete.

Building your app and running it locally

You can now build your app and run it locally.

  1. Navigate to the app directory that was just created and ensure that Docker is running on your system.
  2. Run the ibmcloud dev build command to build your app.
  3. Run the ibmcloud dev run command to begin running your app locally.
  4. View your app that is running locally at http://localhost:3000 or a similar URL in a web browser. You should see the “Congratulations!” screen shown below.
  5. Press Ctrl+C to stop your app.

You can also use compound commands like ibmcloud dev build/run to sequentially issue a build followed by a run.

Adding a service and modifying the code

Now that your app can run locally, you can add a service and modify some code.

  1. Run the ibmcloud dev edit command from within the app directory. Select a resource group if prompted.
  2. Choose Manage services. Select Create a new service and add it to this application. From the Databases category, select Cloudant. If prompted, select a region and the Lite plan for the service. Once this service is added, you can select Return to the previous selection and Exit.
  3. You should see that several service enablement and configuration files were saved to your app directory after adding the service. Some of these files have conflicts which need to be merged manually. You can use diff or a similar tool to compare changes, then overwrite the original files with the *.merge files.
  4. Make a change in your code. For this tutorial, use a text editor to modify the /public/index.html file by changing the Congratulations! string to something like Hello World!.
  5. Save any files that you modified.

Deploying your app

You can deploy a new version of your app to IBM Cloud from the CLI in two ways—automatically via a DevOps toolchain (which should already be configured), or manually.

Automatically deploying your app

Since you have already deployed your app via a DevOps toolchain, deploying a new build is as simple as committing and pushing your code to the repository in your toolchain.

  1. Prepare the changes to be committed.

    git add .

  2. Commit the changes with a brief message.

    git commit -m "made changes"

  3. Push the commits on the master branch to the remote repository.

    git push origin master

  4. View the DevOps toolchain for your app from the IBM Cloud console in your web browser. To do this, run the ibmcloud dev edit command from within the app directory. Select a resource group if prompted.
  5. Select Configure continuous delivery, followed by Open the toolchain for your app in a browser.
  6. Click the Delivery Pipeline card within the toolchain to verify that the pipeline has been executed. You should see the stages of your pipeline running (shown below). Once all stages pass, your app should be deployed.

Manually deploying your app

While not required for this tutorial, you can manually deploy your app to IBM Cloud (Cloud Foundry or Kubernetes) by using the ibmcloud dev deploy  command by using the ibmcloud dev deploy command from within the app directory.

Viewing your app

  1. To view the URL of your app that’s running on IBM Cloud, run the ibmcloud dev view command from within the app directory. Select “n" if asked Is this a Kubernetes deployed application? This will open the running app URL in your default browser, and you should see something like the image below.
  2. To view details about your app’s credentials, services, and toolchain from the IBM Cloud console, run the ibmcloud dev console command.

That’s it! You’ve successfully created, developed, and deployed an application to IBM Public Cloud using the CLI.

Questions or comments?

For assistance, please submit questions to the author of this article. You can reach the development team in the #developer-tools channel of this Slack. You can request access to this Slack channel here.

Additional resources

Was this article helpful?

More from Cloud

A clear path to value: Overcome challenges on your FinOps journey 

3 min read - In recent years, cloud adoption services have accelerated, with companies increasingly moving from traditional on-premises hosting to public cloud solutions. However, the rise of hybrid and multi-cloud patterns has led to challenges in optimizing value and controlling cloud expenditure, resulting in a shift from capital to operational expenses.   According to a Gartner report, cloud operational expenses are expected to surpass traditional IT spending, reflecting the ongoing transformation in expenditure patterns by 2025. FinOps is an evolving cloud financial management discipline…

IBM Power8 end of service: What are my options?

3 min read - IBM Power8® generation of IBM Power Systems was introduced ten years ago and it is now time to retire that generation. The end-of-service (EoS) support for the entire IBM Power8 server line is scheduled for this year, commencing in March 2024 and concluding in October 2024. EoS dates vary by model: 31 March 2024: maintenance expires for Power Systems S812LC, S822, S822L, 822LC, 824 and 824L. 31 May 2024: maintenance expires for Power Systems S812L, S814 and 822LC. 31 October…

24 IBM offerings winning TrustRadius 2024 Top Rated Awards

2 min read - TrustRadius is a buyer intelligence platform for business technology. Comprehensive product information, in-depth customer insights and peer conversations enable buyers to make confident decisions. “Earning a Top Rated Award means the vendor has excellent customer satisfaction and proven credibility. It’s based entirely on reviews and customer sentiment,” said Becky Susko, TrustRadius, Marketing Program Manager of Awards. Top Rated Awards have to be earned: Gain 10+ new reviews in the past 12 months Earn a trScore of 7.5 or higher from…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters