Getting started with your migration from Heroku to Code Engine
Welcome Heroku users to IBM Cloud® Code Engine.
Code Engine is a fully managed, serverless platform that runs your containerized workloads. Code Engine even builds container images for you from your source code. The Code Engine experience is designed so that you can focus on writing code and not on the infrastructure that is needed to host it.
Code Engine was designed with the following key goals in mind.
- Focus on your code. Code Engine provides a simplified developer experience. No need to learn about or manage the underlying infrastructure.
- Support the modern runtime characteristics, such as autoscaling, scaling to zero when idle, and seamless integration with managed services and security.
- Support all your Cloud-native based applications, whether they are 12-factor apps, event-driven functions, or run-to-completion batch-jobs. If it can be containerized, Code Engine can run it.
- Pay for only the resources that you actually use.
If you are coming from a Heroku background, many of these features sound familiar. However, Code Engine also includes some new capabilities that allow you to go beyond even what Heroku offers, including applications that can scale to zero and incur no charges. In addition, Code Engine requires a Pay-as-you-Go account that includes a free tier. So, after you're past the syntactical difference of the user experience, you and your applications will feel right at home in Code Engine.
Objectives
- Learn the similarities between Code Engine and Heroku.
- Learn the general process of deploying apps in Code Engine.
- Deploy an application from code on your local system with Code Engine.
Prerequisites
Before you can get started with Code Engine, you need to set up your account and install the CLI.
-
All Code Engine users are required to have a Pay-as-you-Go account.
-
While you can use Code Engine through the console, the examples in this documentation focus on the command line. Therefore, you must install the Code Engine CLI.
ibmcloud plugin install code-engine
For more information, see setting up the Code Engine CLI. For more information about the CLI, see Code Engine CLI reference.
Comparing Heroku and Code Engine terminology
Before you get started with deploying apps in Code Engine, learn the basics about Code Engine. The following table describes some high-level terminology differences between Cloud Foundry and Code Engine.
Heroku | Code Engine | Description |
---|---|---|
N/A | Resource group and projects | A grouping of workloads. The specific choice of which workload goes into each grouping is defined by the user. "Resource groups" are an IBM Cloud concept, while "projects" are Code Engine specific. Projects provide a level of isolation between workloads. See Managing projects. |
Dynos | Containers | A dyno is a light-weight container that runs your Heroku code and is managed for you. In Code Engine, the underlying containers are based on Kubernetes and are automatically managed for you. |
Application | Application (app) | A workload that responds to HTTP requests from a REST API, a web page request, or an event, for example. Code Engine requires that applications include the HTTP server as part of the code. Code Engine applications automatically scale (up
and down) based on the incoming load. You can configure the minimum and maximum scale if needed. By default, the application listens on port 8080. You can override this behavior by using the console or with the CLI --port flag. See Working with apps in Code Engine. |
N/A | Job or batch job | A job runs one or more instances of your executable code in parallel. Unlike applications, which handle HTTP requests, jobs are designed to run one time and exit. When you create a job, you can specify workload configuration information that is used each time that the job is run. See Working with jobs and job runs. |
heroku create and git push heroku main or heroku container:push web |
app create |
The process of creating an application. With Heroku, you create an app and then push your code to it. Your code is build and deployed in that single step. With Code Engine, you can pull a container image from an image repository, build your source code from a repository such as GitHub, or pull your code from a local file on your system, all from a single command. You can build code based on a Dockerfile or that use a Paketo buildpack. You can build from a single step in the CLI as well as from the Code Engine console. See Planning your build. |
Custom domains | Custom domain mapping | Both services allow you to define and manage external URLs to your workloads. Code Engine provides support for custom domains mappings from the console. You can also add custom domains through IBM Cloud Internet Services or any other domain provider of your choice. |
For more terms and capabilities for Code Engine, see Learn about Code Engine.
Log in to IBM Cloud
Follow these steps to log in to your IBM Cloud account and target a resource group.
-
Log in to the IBM Cloud CLI.
ibmcloud login
-
Target a resource group by running the following command. To get a list of your resource groups, run
ibmcloud resource groups
.ibmcloud target -g <resource_group>
Example output
Targeted resource group default
Creating a project
A Code Engine "project" groups related workloads into a logical collection. You can group workloads into different projects based on whatever criteria that makes sense to you, for example, company organization structure, dependencies between the workloads, or development versus test versus production environments. You can then configure access to these projects. Keep in mind that workloads within a single project share a private network and are isolated within the security boundary of the project. All workloads within a project can talk to each other freely without concern of being seen by workloads outside of the cluster. If workloads in different projects want to communicate with each other, then the communication must either use the internet or an internal IBM private network. For more information, see Options for visibility for a Code Engine application.
Create a project in Code Engine called sample-proj
.
ibmcloud ce project create --name sample-proj
Example output
Creating project 'sample-proj'...
ID for project 'sample-proj' is 'abcdabcd-abcd-abcd-abcd-abcd12e3456f7'.
Waiting for project 'sample-proj' to be active...
Now selecting project 'sample-proj'.
OK
Notice that your project is also selected for context, so all subsequent application-related commands are within the scope of this new sample-proj
project.
Deploying your application
This sample application pulls code from the sample GitHub repository. This code is a simple Push your code to Code Engine by using the application create
command. You must provide a name for your application and the location of the source code. The following example creates an application called myapp
that uses the buildpack
strategy and provides the location for the
source code in the current directory (.
).
ibmcloud ce app create --name myapp --build-source https://github.com/IBM/heroku-to-code-engine
Example output
Creating application 'myapp'...
Packaging files to upload from source path '.'...
Submitting build run 'myapp-run-220999-210706331'...
Creating image 'private.us.icr.io/ce--6ef04-khxrbwa0lci/app-myapp:220418-0207-askql'...
Waiting for build run to complete...
Build run status: 'Running'
Build run completed successfully.
Run 'ibmcloud ce buildrun get -n myapp-run-220000-210706331' to check the build run status.
Waiting for application 'myapp' to become ready.
Configuration 'myapp' is waiting for a Revision to become ready.
Ingress has not yet been reconciled.
Waiting for load balancer to be ready.
Run 'ibmcloud ce application get -n myapp' to check the application status.
OK
https://myapp.abcdbwa0lci.us-south.codeengine.appdomain.cloud
And that's it. You now have an internet-facing application. The code in the application itself is the same as what is used for a Heroku application, it's just the Code Engine commands that are slightly different.
Let's take a deeper look at the previous app create
command. Notice that the output of the app create
command provides information about the progression of the build run before the
app is created and deployed.
- Code Engine receives a request to create an application from source code (instead of pulling directly from an image).
- Code Engine checks for an IAM service ID and API key that is associated with the selected project. This service ID must be authorized to read and write to IBM Cloud Container Registry. If no service ID exists, Code Engine creates one for you. Note that this service ID is used for subsequent Code Engine build requests that are run from the same project.
- This example builds code from a public GitHub repository (
--build-source https://github.com/IBM/heroku-to-code-engine
). The source code is packed into an archive file and uploaded to a managed namespace within the IBM Cloud Container Registry instance in your account. Note that you can target only IBM Cloud Container Registry for your local builds. For more information about IBM Container Registry, including information about quota limits and access, see Getting started with IBM Cloud Container Registry. - Code Engine builds your source code into an image. The source image is created in the same namespace as your source archive file.
- After the build completes, your application is deployed. You can access your application from the provided URL.
With Code Engine, you automatically get many of the same features as Heroku, such as autoscaling and blue-green roll-out of updates, but you'll also enjoy the benefits of newer features such as scaling down-to-zero, ensuring that you are not charged if your application is not active.
Want to learn more about your options for building your source code? See the application create
and the job create
commands.
Want to learn more about applications and jobs? See Working with apps in Code Engine and Working with jobs and jobruns.
Clean up
After you finish this tutorial, you can clean up the resources that you created with the following commands.
Delete your application
ibmcloud ce app delete --name myapp
When you delete your app, the associated build files are also deleted.
Lastly, delete the images that the build created from IBM Cloud Container Registry.
- Navigate to Registry in the IBM Cloud console.
- Find the archive and the image that are associated with your application by searching for your application name.
- Select the archive and image and delete.
Video transcript
Hi, my name is JJ Asghar and I'm a developer advocate for IBM Cloud. Recently, you might have heard about Heroku changing their policy on free - the free tier. It's causing a challenge for a lot of developers out there so I want to take a handful of moments here to show you how you can migrate from Heroku to Code Engine from IBM Cloud in just a handful of steps. So let's go ahead and start playing around with it and see how quickly you can actually make your system work.
So first thing first, if you haven't seen it this is the actual line inside the official blog from Heroku, starting on November 28, 2022, we plan to stop free - offering the free product plans and plan on shutting down the free dynos and data services. We'll be sending out a series of email communications to affected users. This is challenging for a lot of beginner beginner web applications. I know for a fact personally I used Heroku when I first started back in the day so this is a pretty large hit for a lot of people and I want to show you how easy it is to convert from Heroku to Code Engine.
So first thing first, let's actually see a nice little application I've created. If I go ahead and bring up my application here, we have a nice little flask app. If you don't know what python is or flask is, it's a it's a format for python to be able to run an application on a standard port. So let's say we have this application; it says “Hello World!”. I've already deployed it and we can check out right here We have our amazing production app at heroku.com. It says “hello world” and we want to go ahead and change it. We wanted to update it so I'm going to go ahead and quickly update it to “Hello Moving from Heroku to Code Engine”.
Let’s go ahead and come out of it. git add .
git commit -m “update hello line”
. Then I'm going to go ahead and push and just like you would normally do to push code to Heroku. I want to show you that this is the exact
same process inside of Code Engine. What we'll do is, we'll create a new … we'll log in to IBM Cloud first and then from there we'll create a new project and then we'll go ahead and deploy it to see that it works.
So there we go, we've gone ahead and deployed it to Heroku first ,just to make sure that we all have our working code and I go ahead and reload this and there we go we're moving from Heroku to Code Engine so we know our code works. This is great.
So now actually let's get Code Engine as part of this, so first thing first, we need to IBM Cloud log in. So I'm going to go ahead and log in to IBM Cloud. If you haven't set up IBM Cloud video or if you haven't set up your IBM Cloud account, if you look above, me you should see a link to it, which I will put into the video.
I'll go ahead and copy my name here and then I'll take my password, log in just fine, which is great to see, perfect. And now what I'll do is ibmcloud ce project create —name amazing product production app
. So this create our nice,
little… Target first. I’ll get my default resource group and then I'll go ahead and create the project. There we go. Should only take a moment - perfect. Now you can change your name to whatever you like. This is just a catch-all for your
project, which is useful. Then I will take the next command, which is ibmcloud ce app create —name pythonbackend — build-source . —strategy build packs
Now because I already have a requirements.txt, this will be, this application is smart enough to figure out, “hey it's a python application! So let's go ahead and build it!", which is nice. So as you can see, it's taking step one here.
It's running the build, which is good. It creates a nice, private image for us too, which is useful. It takes a couple moments. There we go and now we see that if we wanted to do this with no wait, which is the -nw
, we can actually
put this into the background and wait for it to come up and then we can check it via this build run get
the actual name. Being that we're going to be looking at this live, we'll go ahead and do this here.
Perfect! So now I go ahead and open up the this URL here and it came over here and as you can see
“hello moving from Heroku to Code Engine”
And that's it. I took the exact same code I did from Heroku. I created a new project and then I created an application and I just pushed it and it just worked so imagine what you can do with that for yourself. This shows the power that is Code Engine and on a free tier it is truly free - just like Heroku was or will be or was will won't be in the future. Code Engine is free forever, which is great and hopefully, it'll make your life a little easier.
Thanks so much for watching and if you have any questions, my Twitter handle is @jjasghar or you're more than welcome to email me at awesome@ibm.com. My job is to be a personable nerd so never hesitate to reach out.
Thanks so much.
Bye y'all.