DEV Community

Cover image for Code Engine - A developers dream!
Liam Conroy Hampton
Liam Conroy Hampton

Posted on • Edited on

Code Engine - A developers dream!

Code Engine? What is Code Engine? This is a slick new tool that IBM Cloud has released into Beta. It takes your already containerised app OR source code (that's right, it takes both), and then deploys that into the wild. This is literally a developers dream. You code it, they deploy it. It really is that simple. Look, I'll show you the only steps you need to take..

1) Sign into IBM Cloud or create an IBM Cloud account
2) Write some code and put it into GitHub OR containerise your application and store it in a container registry - literally anywhere you want
3) Link up Code Engine and watch that puppy deploy

As always, I will be using a Golang application for this tutorial as that's my favourite flavour but you can use anything you like.

Before we start, you need to get an API key set up. Follow these easy steps:

Login or Sign up for a free IBM Cloud account and then head to Manage -> Access (IAM) -> View All of your API keys -> Create an IBM Cloud API key

Give the key a name and description and MAKE A NOTE OF THE KEY. You will not see this key again and you need it later.

Now for the juicy stuff.

Head to the search bar and type in Code Engine and select the catalogue option as shown below
search bar

code engine home

Now let's be real, playing with containers is great but not everyone knows how to containerise their app or know the ins and outs of containerisation. Since lots of developers just deliver code, we will select the option to "Run your source code". All this needs is a github link and Code Engine does the heavy lifting here.

run your source code

Select this option and click on "Start creating ->"

Next you will be prompted to select "Application" or "Job".

  • Application - A project you intend to keep alive, such as a HTTP server
  • Job - A block of code you intend to run to completion, such as a function

For this tutorial, we are going to select "Application" as we want to make a HTTP server. Beneath that option, you will be promped to create a project. A project is what houses this deployed application. Click on "Create" and fill in the details on the panel that pops out and then click "Create" to make the project (shown below).

application vs job

create project

Now we can carry on with the application. Give it a name, select "Source Code" because that's what we are using, specify the .git repository url and then click on "Specify build details" - this is the most important part.

build details

A window will pop out and the details will be pre-configured - only change these if you need to specify something other than the root of the directory and a different branch.

more build details

Next, on the "Strategy" stage you will be asked how you would like this built. Dockerfile or Cloud Native Buildpack? This might seem a bit confusing but fear not, this is just how you want the code to be bundled up and run. For ease, we will just leave it pre-configured as the Dockerfile.

strategy build details

Finally, the output stage. If you do not already have a container registry / repository in place you need to set one up. This is just so that Code Engine has a place to store the built image of your source code.

It might look a little garish and something like this

output stage

Click on "Add" to add a registry and you will the be presented with a bunch of fields to fill out that look like this..

add regisrty

Now, lets take a second to walk through these bits

  1. Registry name - This is the name you will identify the registry with, you can choose whatever you like. As seen above I have chosen "http-project-registry"
  2. Registry server - The eagle eyed reader might have noticed that this project is based on a server in Dallas. At the point of writing this, Code Engine is in beta meaning Dallas is the only available deployment location. I am using IBM Cloud container registry so my sever address is us.icr.io. You can choose Dockerhub or any other container registry.
  3. Password - If you are not using IBM Cloud container registry, you will need to provide your user/password. If you ARE using IBM Cloud container registry like me, you will only be prompted for the password as the "Username" is pre-filled. Remeber that API I asked you to make earlier? - that API key goes in here as the password.
  4. Email - This is optional, I haven't put it in but there is no harm in specifying a valid email address.

Click "Add" and you will then get a pop out that looks similar to the one below. You may have to enter a repository name if this is your first project. You can call this anything you like.

output stage complete

Click on "Done" and then click on "Deploy".

Wait for the applicaiton to be built and deployed. Click on "Application URL" to view the deployed application.

deployed application

.. And just like that, you have a cloud native application built from raw source code. As I said earlier, you just need to focus on pushing your code and let Code Engine do the rest!

Now close the browser tab / window that is running the application. Have you spotted anything weird in the project window? There might be some lag to this but you might notice you have "0 instances" running.

0 instances

This is just another one of those cool perks where you would only pay for what you use on a larger project. Under the covers, Code Engine uses Knative which has this awesome feature of being able to scale down to 0 if no traffic is being received. Checkout the Knative docs to read more about this!

Disclaimer

At the time of writing this, Code Engine is in beta so you may experience fluctuating behaviour and projects are kept alive for only 7 days.

If you have any questions or want to see more content like this, feel free to reach out!

GitHub
Twitter
Instagram
LinkedIn

Top comments (0)