| copyright |
|
||
|---|---|---|---|
| lastupdated | 2017-10-02 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:codeblock: .codeblock} {:pre: .pre}
{: #tutorial}
The following end-to-end tutorial walks you through the steps to create a project from a Microservice Basic Starter. Use these starters to build a microservice backend for Node, Java, or Python with a choice of web frameworks. Steps include installing prerequisite tools, building and running the project locally and deploying to the cloud.
{: #before-you-begin}
Ensure that you install the prerequisite developer tools {: new_window}.
{: #create-devex}
Create a project in the {{site.data.keyword.Bluemix}} {{site.data.keyword.dev_console}}:
-
From the Starter Kits
page in the {{site.data.keyword.dev_console}}, select a Starter Kit based on your chosen language. For example, for a Node.js application, go to Express.js Microservice and click Select Starter Kit.
-
Enter your project name. For this tutorial, use
MicroserviceProject. -
Enter a unique hostname, such as your initials plus
-devhost. For example:abc-devhostThis hostname will be used for your project's route. For ex:
abc-devhost.mybluemix.net -
Select your language platform. For this tutorial, use
Node.js. -
Click Create Project.
{: #add-services}
-
Select your project in the Projects page.
-
Click Add Service.
-
Select the kind of service you want. For this tutorial, select Data > Next > Cloudant NoSQL DB > Next.
-
Enter your service name and click Create.
{: #add-toolchain}
Enabling a toolchain is a valuable option as it creates a team-based development environment for your project. When you create a toolchain, the App Service will provision a Git repository, where you can view source code, clone your project and create/manage issues. You will also have access to a dedicated Gitlab environment and a continuous Delivery Pipeline that is customized to the deployment platform you choose-- Cloud Foundry or Kubernetes.
Continuous delivery is enabled for some applications. You may want to enable continuous delivery to automate builds, tests, and deployments through the Delivery Pipeline, GitHub, and more.
-
Select your project in the Projects page.
-
Click Create Toolchain.
-
Select a deployment method. You may choose to either:
-
Deploy using Cloud Foundry, where you do not need to manage the underlying infrastructure.
-
Deploy to a Kubernetes Cluster. Provision a cluster of hosts, called worker nodes, to deploy and manage highly available application containers. You may create a cluster or deploy to an existing cluster.
-
{: #generate-code}
If you created a toolchain in the optional step above, a git repository will have been created for your project. Follow these steps to access your repo:
-
Select your project in the Projects page.
-
Click View Toolchain.
-
Click the Git card under the heading CODE to open your repository, where you can view source code and clone your project.
Alternatively, if a toolchain is not enabled, you can access your code by downloading the source directly from the App Service.
-
Select your project in the Projects page.
-
Click Download Code to download your project archive.
{: #code}
Begin working with your downloaded project:
-
Expand the archived file.
-
Navigate to the new project directory.
-
Use the {{site.data.keyword.dev_cli_notm}} to proceed.
{: #build-run}
Add your own code, build, and run the project. You can run the application locally on your host system if you install the necessary build tools, or by using the available container support in the {{site.data.keyword.dev_cli_notm}}.
- To build the project in your current project directory, enter the following command:
bx dev build
{: codeblock}
- To run the project in your current project directory, enter the following command:
bx dev run
{: codeblock}
- You can access the application by using
curlon your server:
curl http://localhost:3000
{: codeblock}
{: #deploy}
To deploy your project to Cloud Foundry, enter the following command:
bx dev deploy
{: codeblock}
To deploy your project to a Kubernetes cluster, enter the following command:
bx dev deploy --target <container>
{: codeblock}
This step will deploy your application to the Cloud. Once the application is deployed, you should see a URL similar to abc-devhost.mybluemix.net. Visit this URL in your browser.
If you chose to create a DevOps toolchain, you may view your toolchain:
-
Select your project in the Projects page.
-
Click View Toolchain. This gives you access to:
-
Create and manage issues for your project in Git.
-
View your generated code in Git.
-
Access an Eclipse-based Web IDE.
-
View your delivery pipeline where you can kick off builds, manage deployment and view logs and history.
-
{: #hot-reload} (Optional)
Hot-reload is a popular development practice where the application runtime updates upon code change by triggering rebuild (when necessary) and restart automatically.
- Run hot-reload with container:
bx dev shell run-dev
{: codeblock}
Open project at http://localohst:3000 in your browser.
- Run hot-reload with NPM script.
npm run dev
{: codeblock}
Open project at http://localohst:3000 in your browser.