Contents


Working with cloned git repos in the IBM Cloud

Once you've cloned a git repo from developerWorks Code Patterns, how can you use that cloned repo in your own IBM Cloud project?

Comments

developerWorks Code Patterns are complete projects that include git repos to get you started with various technologies. This tutorial shows you how to take a cloned git repo and tie it to the delivery pipeline for your own app running in the IBM Cloud. We'll go through a complete example, starting with a new Cloud Foundry app and then cloning a git repo. Next, we'll configure the cloned repo to work with the new app, and wrap things up by making sure any change that's pushed to the cloud from the cloned repo automatically triggers the delivery pipeline of the app.

Create a Cloud Foundry app

We'll start by setting up a new app at the IBM Cloud console. Go to the console and click the Create button to create a Cloud Foundry app:

The Create button on the IBM Cloud console

The Create button on the IBM Cloud console

When the catalog appears, click Cloud Foundry Apps in the list on the left:

The Cloud Foundry Apps tab

Our example app is a node app, so click SDK for Node.js in the middle of the screen:

The SDK for Node.js catalog item

The SDK for Node.js catalog item

Give your app a name:

Naming the new Cloud Foundry app

Naming the new Cloud Foundry app

Next, click the Create button in the lower right-hand corner of the screen. As always, your app name has to be unique across the IBM Cloud. You'll get an error message if the name you choose already exists.

In a minute or two, you'll see the Getting Started page:

The Getting Started page for your new app

The Getting Started page for your new app

Notice that there's a spinning circle next to the word "Starting" in the upper right. The Visit App URL link is disabled for now. When your app is deployed, you'll see a solid green circle, the status "Running," and the Visit App URL link will be active.

Add a continuous delivery toolchain

That's all you need to do to create your new app. Now it's time to set up a git repo for the app. This requires a continuous delivery toolchain. That's what comes next.

To get started, click the Overview tab on the left:

The Overview button

Scroll down to the bottom and click the Enable button in the Continuous delivery box:

Enabling a continuous delivery pipeline

Enabling a continuous delivery pipeline

On the continuous delivery toolchain page, scroll down to the bottom. Make sure you specify that this is a new repo:

Specifying a new git repo

Specifying a new git repo

Take the defaults for everything else, click Create, and the cloud side of things will be all set up. You should see the Toolchain page:

The Toolchain             page

The Toolchain page

To tie your local repo to the cloud, you need to get the URL of the repo you just created. Open the Code / Git box in the middle of the Toolchain page in a new browser tab:

The git repository box on the toolchain page

In the tab that opens, you'll see the details of the repo:

The repo                 overview page

The repo overview page

In the middle of the page, copy the HTTPS URL of the repo. (You'll need to click the drop-down on the left to select HTTPS instead of SSL.) When the URL appears, click the Copy icon:

Copying the                 URL of the git repo

Copying the URL of the git repo

To watch everything work, open the delivery pipeline page for demonstration purposes. When you do a git push later, the delivery pipeline page will show you what's happening as your updated code goes through the build and deploy stages. Click on the Delivery Pipeline tile to open the page:

The Delivery Pipeline        tile

You'll see the status for the build and deploy stages:

The build and deploy stages of the toolchain

The build and deploy stages of the toolchain

Finally, go back to the Getting Started page and click Visit App URL at the top:

The Visit App URL link

The Visit App URL link

You'll see this scintillating page:

The original Hello World page

The original Hello World page

Before you leave the cloud, here's where things stand:

  • You have a new Cloud Foundry app that's up and running. It displays a simple web page.
  • You have a git repo and a continuous delivery pipeline associated with your Cloud Foundry app.
  • You have the delivery pipeline open in a browser tab so you can watch the build and deploy stages happen whenever you do a git push to your repo.

Clone the repo

Let's return to your local machine to start cloning the repo. For this example, clone https://github.com/DougTidwell/dWSimpleApp:

The github repo we'll clone

The github repo we'll clone

Note: when you clone this repo, be sure to read all the Terms and Conditions in the README file.

Clone the repo and change to the directory that contains the cloned code:

The git command to clone the repo

The git command to clone the repo

Tie the repo to the Cloud Foundry app

Now you need to point the cloned repo to the app in your IBM Cloud account. Otherwise, any changes you try to push will go back to the original repo. Here are the commands:

  • git remote remove origin
  • git remote add origin [followed by the URL of your repo in the cloud, not the URL of the original repo]
  • git push -u origin --all
  • and finally, git push -u origin --tags

Your results should look something like this:

Git commands to change the origin of the repo

Git commands to change the origin of the repo

Note: This last command isn't necessary if the git repo you cloned doesn't have any tags, but it's included here for completeness. If you don't have any tags, running this command won't make any difference.

Test it out

Everything should be all set up now. To make sure everything works, edit the index.html file in the cloned repo on your machine. To make things obvious, change the heading on the page:

The updated code you'll push to the IBM Cloud

The updated code you'll push to the IBM Cloud

After saving the updated file, do the usual git add, git commit, and git push sequence:

Pushing the file to the repo associated with our Cloud Foundry app

Pushing the file to the repo associated with our Cloud Foundry app

Within seconds of the git push, the build stage of the delivery pipeline should be running in the browser:

The build stage of the delivery pipeline

The build stage of the delivery pipeline

Notice that the comment from the git commit command shows up in the UI. If the build stage completes successfully, the toolchain moves on to the deploy stage:

The deploy stage                of the delivery pipeline

The deploy stage of the delivery pipeline

When deployment is done, you can click on the URL of the app and see your changes:

The updated Hello World page

The updated Hello World page

Summary

The goal of all the sample code we have here at developerWorks is to help you build the next great app. Git repos are great ways to package code, but by default they stay tied to their original source when you clone them. Using the techniques in this article, you can clone any git repo you like and connect it to the continuous delivery toolchain of an app running in the IBM Cloud.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing
ArticleID=1052057
ArticleTitle=Working with cloned git repos in the IBM Cloud
publish-date=11202017