Yes, I get it. Cloud is the new standard. The new normal. For me, the excitement of getting applications out on SAP Cloud Platform NEO has throughout 2017 been mixed with a fear of not really understanding Cloud Foundry and all the concepts surrounding it. One of the hurdles to tackle is containerization of solutions. Is it important? Yes. Allowing your stuff to be deployed into a Cloud Foundry environment as a prepacked box with all stickers, labels and content all in one go sounds quite clever.
Former Members keynote at SAP TechEd this year set the course even clearer, with the announcement that SAP has joined the Cloud Native Computing Foundation (CNCF), and will steer the container ship towards Kubernetes. As of now, Cloud Foundry supports Docker containers (through Diego).
After reading fascinating blogs by Matthias Steiner, I decided it’s time to catch up and get some hands on with container based development for SAP Cloud Platform. For me, and I’m sure a lot of you will relate, this has been pure theory so far. This blog describes my learning experience. I know that a lot of my colleagues at NTT Data Business Solutions will try this out as well – so this one is for you (hence the branding).
Let’s deploy a container to SAP Cloud Platform CF using Docker Hub and GitHub
This is what I will do and describe in this blog:
- Clone a simple code project using GitHub.
- Link GitHub and Docker Hub.
- Build the project in a container on Docker Hub using automatic build.
- Deploy the container to SAP Cloud Platform Cloud Foundry.
- Run the application.
- A GitHub account and some code.
- A Docker Hub account.
- An SAP Cloud Platform Cloud Foundry trial account.
- The Cloud Foundry command line interface plugin on your computer.
No investment needed other than your time!
Let’s get going!
First of all, sign up/logon to GitHub.
The next we need is some code that we ultimately will push to the cloud. If you are not familiar with everything required to create a docker container, you can follow these steps to import an existing project. Click the plus and “import repository”:
Use the following repository: https://github.com/shuuse/helloNTTData and give your repository a name. I will use HelloDocker, and if you are lazy you should do the same, as it will can copy paste some code later:
This is a good point to explore the files and code that you just copied.
Moving on.. The next step is to sign up and logon to hub.docker.com in order to link it to your GitHub account.
Once you have logged on to Docker Hub, go to “Create Automated Build” in the top menu.
You will see a big, fat GitHub icon, so go ahead and click it in order to link your GitHub account with your Docker Hub account. Accept the threats and complete the linking. Once the accounts talk to each other, you should be able to see your GitHub repositories in Docker. Pick the repository you just created HelloDocker:
Fill in the name (HelloDocker) and a description. Make sure you set the visibility to “public”, that way you don’t have to mess with authentication:
When you click “Create”, you’ll get a nice confirmation/overview page. Go to the tab “Build Settings”. Make sure that the checkbox for automatic build is on. This will make the container rebuild every time you update your git repository. Then trigger the first build:
If you go to the tab “Build Details”, you can follow the build process in detail. But let’s just assume that everything goes according to plan.
The next thing you need is an SAP Cloud Platform Trial account on Cloud Foundry. I have faith in you to do that on your own, there are plenty of guides and it’s also quite self-explanatory. Start here and click “Cloud Foundry Trial”. Choose the Europe-AWS edition, unless you’re in an experimental mood.
Next, download the Cloud Foundry command line interface (CLI) tool here. Install it and open up a command line window on your computer. Test that the CLI works by typing the command “CF”. The result should look something like this:
Set your api using the following command:
cf api https://api.cf.eu10.hana.ondemand.com
Logon using the following command:
Great! You should be logged in. Now, it’s time to get the container and push it to your dev space on SAP Cloud Platform. The following command will get your latest build. Replace my docker username with your own:
cf push HelloDocker --docker-image shuuse/hellodocker:latest
The command line tool will do it’s magic. If successful, you will get a summary like this:
Meanwhile, switch over to the Cloud Platform. You should see an application appearing:
Open the details by clicking it’s name. There you can reduce the resource consumption (5MB for both memory and disk should be fine – restart it afterwards) and click the link to test if it works:
Viola! There it is, running like a charm. And, remember, as you set the automatic build flag in Docker Hub, there will be a new build version every time you commit to GitHub. That doesn’t automatically update your application on Cloud Foundry. For that you should run the CF push command that we did a few steps ago.
Containers are cool.
We have seen how you can use GitHub to create contents for a Docker container, and how we can link Docker Hub to automatically build your container. Then we pushed the container onto a SAP Cloud Platform trial account using the Cloud Foundry command line interface tool.
Thanks for taking part in my learning experience! I hope it was useful, and that it will inspire you to share your findings as well.