Skip to content

Latest commit

 

History

History
129 lines (93 loc) · 8.36 KB

create-deploy-cli.md

File metadata and controls

129 lines (93 loc) · 8.36 KB
copyright lastupdated
years
2018
2018-12-04

{:new_window: target="_blank"}
{:shortdesc: .shortdesc}
{:screen: .screen}
{:codeblock: .codeblock}
{:pre: .pre} {:tip: .tip} {:note: .note}

Creating and deploying apps by using the CLI

{: #developing}

You can use the {{site.data.keyword.cloud}} command line interface (CLI) to create and deploy your app.

You can either create a starter app from scratch or cloud-enable your existing app code. {: note}

Before you begin

{: #prereqs}

You must install the {{site.data.keyword.cloud_notm}} CLI, the {{site.data.keyword.dev_cli_notm}} 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

{: #create}

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

  1. Run the ibmcloud dev create command in the directory of your choice.
  2. Select Backend Service / Web App as the application 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, using Cloud Foundry option to create a DevOps toolchain. You might need to set up SSH keys to complete this step.
  7. Enter a unique host name, for example, abc-devhost. This host name is your app's route, abc-devhost.cloud.ibm.com.

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

Generating deployment and cloud enablement assets

{: #byoc}

This option can be used if you already have an existing codebase and want to generate deployment and cloud enablement assets for a single microservice or web app by using ibmcloud dev enable. Note that this command is in Beta, and not all languages and/or app structures are supported. The following instructions illustrate how to use this functionality with a sample repository, but the steps are roughly the same for your own codebase.

  1. Log in to {{site.data.keyword.cloud_notm}} by running ibmcloud login then target an org and space.
  2. Clone the Hello World sample app by running the following command in the directory of your choice.
git clone https://github.com/IBM-Cloud/node-helloworld.git

{: codeblock}

  1. Navigate to the directory where you cloned the sample app, and run the ibmcloud dev enable command.
  2. Select to continue without committing changes for now (if necessary).
  3. Select to continue when you're prompted to proceed with the Node language that is detected.
  4. Select the resource group that you want to use (if necessary).
  5. Select the option to create a new {{site.data.keyword.cloud_notm}} app that is linked to this Git repository. See Important Notes for details.
  6. Don't add services for now.
  7. Wait a few seconds for the operations to complete.
  8. Once completed, you can manually merge the deployment and cloud enablement files that are saved to the app directory. Any new files marked .merge should be merged by using git diff or a similar tool.

Important Notes

  • If you've already created an {{site.data.keyword.cloud_notm}} app by using the {{site.data.keyword.cloud_notm}} console, follow steps 2 - 5 in the previous section in your app directory. For step 6, you can select the option to connect your local code to an existing app.
  • You can also choose to only generate deployment and cloud enablement files without connecting to an {{site.data.keyword.cloud_notm}} app by running ibmcloud dev enable --no-create.
  • To manually configure a toolchain and deployment files, follow this guide. This can be useful if you're trying to configure a Continuous Delivery toolchain for more than one interrelated web apps or microservices.
  • If your existing codebase isn't already in a Git repository, follow steps 2 - 5 in the previous section in your app directory. For step 6, you can select the option create a new {{site.data.keyword.cloud_notm}} app and deploy it to a DevOps toolchain (which has a newly created GitLab repository).

Building your app and running it locally

{: #build-run}

Regardless of which option you used to create your app, you can now build it and run it locally.

  1. Navigate to your application directory, 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 running locally at http://localhost:3000 or a similar URL.
  5. Press the Ctrl+C keys to stop your app.

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

Adding a service and modify the code

{: #add-service}

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

  1. Run the ibmcloud dev edit command.
  2. Follow the prompts to create and connect a new data-related service to your app, such as {{site.data.keyword.cloudant_short_notm}}. You might need to select a region and plan for the service.
  3. You can choose to manually merge the configuration files that are saved to your app directory when you create the service. Or you can skip this step for now.
  4. Make a change in your code. For example, modify the /public/index.html file or a similar file. If you're using the sample ExpressJS application, you can change the Congratulations! string to something like Hello World!.
  5. Save any files that you modified.

Deploying to {{site.data.keyword.cloud_notm}}

{: #deploy}

You can deploy your {{site.data.keyword.cloud_notm}} app in one of two ways, depending on how your app is configured.

Deploying your app by using a DevOps toolchain

If you haven't yet created a DevOps toolchain for your app and your app isn't yet in a Git repository, you can run the ibmcloud dev edit command. Follow the prompts for "Configure DevOps" and deploy to a new toolchain (and create a new GitLab repository).

Once you've created a DevOps toolchain for your app, deploying a new build is as simple as committing and pushing your code to the repository in your toolchain.

  1. Run the git add . command.
  2. Run the git commit -m "made changes" command to commit changes.
  3. Run the git push origin master command to push to the master branch.
  4. View the DevOps toolchain for your app from the {{site.data.keyword.cloud_notm}} console. You can view toolchain details from the App Details screen in the {{site.data.keyword.cloud_notm}} console by running the ibmcloud dev console command from the app directory.
  5. View the pipeline within the toolchain to verify that a new build started.

Manually deploying your app

You can manually deploy your app by using the deploy command. For example, use the following steps to manually deploy your app to Kubernetes.

  1. Ensure that you created a Kubernetes cluster.
  2. Run the ibmcloud dev deploy -t container command.
  3. When prompted, confirm the cluster and container image name to use.
  4. Wait a few minutes for the deployment to complete.

Viewing your app

{: #view}

  1. To view the URL of your app that's running on {{site.data.keyword.cloud_notm}}, run the ibmcloud dev view command.
  2. To view details about your app's credentials, services, and toolchain from the {{site.data.keyword.cloud_notm}} console, run the ibmcloud dev console command.

To report issues or provide feedback, you can use the {{site.data.keyword.cloud_notm}} Tech's Slack - #developer-tools channel - Request team access here.