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?
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:
When the catalog appears, click Cloud Foundry Apps in the list on the left:
Our example app is a node app, so click SDK for Node.js in the middle of the screen:
Give your app a name:
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:
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:
Scroll down to the bottom and click the Enable button in the Continuous delivery box:
On the continuous delivery toolchain page, scroll down to the bottom. Make sure you specify that this is a new 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:
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:
In the tab that opens, you'll see the details of the repo:
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:
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:
You'll see the status for the build and deploy stages:
Finally, go back to the Getting Started page and click Visit App URL at the top:
You'll see this scintillating 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 pushto your repo.
Clone the repo
Let's return to your local machine to start cloning the repo. For this
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:
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:
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:
After saving the updated file, do the usual
git commit, and
git push sequence:
Within seconds of the
git push, the build stage of the
delivery pipeline should be running in the browser:
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:
When deployment is done, you can click on the URL of the app and see your changes:
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.