Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions content/authors/luke-roy-ibm/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Luke Roy"
text: "Cloud Sofware Engineer @ IBM Cloud Code Engine"
# Social Media Links
links:
- github: "https://github.com/Luke-Roy-IBM"
- linkedin: "https://www.linkedin.com/in/luke-roy-758a29196/"
---

Welcome to my blog post feed.
Binary file added content/authors/luke-roy-ibm/avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: "Creating a IBM Cloud Code Engine Function Code Bundle FROM scratch"
date: 2025-08-04
description: "Creating a IBM Cloud Code Engine Function Code Bundle FROM scratch"
tags: ["serverless", "code engine", "functions"]
draft: false
authors: ["luke-roy-ibm"]
---

Have you ever wanted to create a Code Engine Function code bundle that runs as a Python or Node.js function on [IBM Cloud Code Engine](https://www.ibm.com/products/code-engine), without relying on the Code Engine CLI to build it?

This guide walks you through a manual method to create a Code Bundle, giving you more control over the build process. While this approach is not encouraged as it can lead to unexplained behaviours it’s ideal for experienced developers who need flexibility in how their functions are packaged and deployed.

**Important**: Ensure you run all commands in an **amd64/Linux environment** using the correct runtime version for your function. Refer to the [Code Engine Function Runtimes documentation](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime) for supported versions. You should also have a IBM Cloud account and be familiar with IBM Cloud Code Engine and [IBM Cloud Container Registry](https://www.ibm.com/products/container-registry).

## Step-by-Step Guide
## 1. Prepare your source code

You can create either a Python or Node.js function for IBM Cloud Code Engine. Example source code for both runtimes is available in the following GitHub repositories:

- [Python code bundle](https://github.com/IBM/CodeEngine/tree/main/helloworld-samples/function-codebundle-python)
- [Node.JS code bundle](https://github.com/IBM/CodeEngine/tree/main/helloworld-samples/function-codebundle-nodejs)

Typically, you would use the Code Engine CLI to build and deploy your function in a single step. For example:

### For Python:
```bash
$ ibmcloud ce fn create -n lorem-python -runtime python-3.11 --build-source .
```


### For Node.JS:
```bash
$ ibmcloud ce fn create -n lorem-node -runtime nodejs-20 --build-source .
```

After running one of these commands, your function is automatically built, deployed, and ready to invoke via the generated URL — no additional steps required.
However, in this guide, we’ll manually perform the build and packaging steps. This approach gives you deeper insight and greater control over how your function is constructed and deployed.

## 2. Installing Dependencies for Your Function

Once you’ve created your source code files `__main__.py` and `requirements.txt` for Python, or `main.js` and `package.json` for Node.js you can proceed to install any additional dependencies required by your function. Ensure you are in the directory where your source code is.

### For Python:
Set up a virtual environment and install the dependencies listed in your `requirements.txt` file. This will create a `virtualenv` directory containing all the necessary packages:
```bash
$ virtualenv virtualenv
$ source virtualenv/bin/activate
$ pip install -r requirements.txt
```
### For Node.js:
Use npm to install the dependencies defined in your `package.json`. This will generate a `node_modules` directory:
```bash
$ npm install
```
These steps ensure that all runtime dependencies are downloaded and ready for packaging into your Code Engine function.
## 3. Packaging and Publishing Your Function Code and Dependencies

With your source code and dependencies ready, the next step is to bundle everything into a .tar.gz archive. This archive will later be added to a container image for deployment.

### For Python:
Include your code `__main__.py`, dependencies `requirements.txt`, and the virtual environment directory `virtualenv`:
```bash
$ tar -czf myfuncbundle.tar.gz __main__.py requirements.txt virtualenv
```
### For Node.js:
Include your `main.js`, `package.json`, and the `node_modules` directory:
```bash
$ tar -czf myfuncbundle.tar.gz main.js package.json node_modules
```
Now that your code and dependencies are bundled in a tar.gz , the final step is to create a container image that can be stored in a container registry — specifically, the IBM Cloud Container Registry in this case.
This image will contain a single layer with your function. Note that this is not an executable container, it simply holds the function code for Code Engine to extract and run.

Create a file named `Dockerfile` with the following content.

**Dockerfile:**
```dockerfile
FROM scratch
ADD myfuncbundle.tar.gz .
```
Build the image and push it to IBM Cloud Container Registry using the following commands. Replace mynamespace with your actual IBM Cloud Container Registry namespace:

```bash
$ docker build -t us.icr.io/mynamespace/myfuncbundle .
$ docker push us.icr.io/mynamespace/myfuncbundle
```
Once pushed, this image can be referenced when creating/updating your function in Code Engine.

## 4. Deploying Your Function with a Custom Code Bundle

With your function code bundle pushed to the IBM Cloud Container Registry, you’re ready to create/update your function using the Code Engine CLI. Instead of building from source, you’ll reference your pre-packaged code bundle stored in the registry.

### For Python:
```bash
$ ibmcloud ce function create --name myfunc --runtime python-3.11 --code-bundle us.icr.io/mynamespace/myfuncbundle
````

### For Node.JS:
```bash
$ ibmcloud ce function create --name myfunc --runtime nodejs-20 --code-bundle us.icr.io/mynamespace/myfuncbundle
```
Be sure to replace mynamespace with your actual IBM Cloud Container Registry namespace.

This command creates your function on IBM Cloud Code Engine, using your custom bundle as the source. Once created, the function is ready to be invoked via its generated URL.
## Summary

By manually creating a Code Engine function bundle, you’ve unlocked a deeper understanding of how IBM Cloud Code Engine handles function packaging and deployment. This method gives you full control over your function dependencies and build, process — ideal for advanced use cases or custom CI/CD pipelines. However, for most scenarios, it is strongly recommended to use the Code Engine CLI, which simplifies the process and ensures compatibility with the platform’s evolving features. While the manual approach is powerful, the CLI remains the most reliable and supported way to build and deploy your functions. Happy coding — and may your functions run fast and fault-free!
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: "IBM Cloud Code Engine: Deploying Apps, Jobs and Functions using GitHub Actions"
date: 2024-02-23
description: "Deploying Apps, Jobs and Functions using GitHub Actions"
tags: ["serverless", "code engine", "github actions"]
draft: false
authors: ["luke-roy-ibm"]
---

## Introduction:
In the dynamic world of cloud computing, efficient deployment pipelines are a crucial part of a seamless development process. IBM [Code Engine](https://www.ibm.com/products/code-engine), a fully managed serverless offering, stands out by simplifying the deployment and running of Applications, Jobs, and Functions in the cloud at scale, eliminating the need for users to manage the underlying infrastructure.

To elevate the users development experience and workflow, we've introduced a dedicated GitHub Action designed to simplify the deployment process for GitHub users leveraging GitHub Actions as their CI/CD pipeline.

The GitHub Action `ibm/code-engine-github-action` empowers Code Engine users to seamlessly build and deploy applications, jobs, and functions directly from their GitHub repositories without the need to first manually build the program that they want to deploy or run multiple cli commands. This integration enhances the overall development lifecycle, providing a streamlined and automated approach to deploying and managing Code Engine resources.

## Getting Started
To get started, ensure that the GitHub Actions feature is enabled for your repository. While GitHub Actions are enabled by default for public repositories, users with private repositories may need to enable it from the Actions tab. All workflow configurations are stored within the `.github/workflows` directory, making it easily accessible for users to customize and manage their deployment pipelines.

To use the `ibm/code-engine-github-action` GitHub Action you will also need to create an API Key ([see the docs](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui)) and save it as a secret for your repository (Settings -> Secrets and variables > Actions). In this example the secret is called `IBM_IAM_API_KEY`.

After you have prepared your repository we can get started with two simple examples: the first on how to deploy a Code Engine App and the second one how to deploy a Code Engine Python Function.

## Deploying an App
Create a directory `my-ce-app` containing the source code you want to deploy to Code Engine. Inside the `my-ce-app` directory create the following files which make up a simple NodeJS Web Server.

[app.js](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-app/app.js)
```javascript
const express = require("express");
const app = express();
const port = 8080;
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get("/", (req, res) => {
res.setHeader("Content-Type", "application/json");
res.status(200).send(JSON.stringify({ body: "Hello from Node" }));
});
const server = app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
process.on("SIGTERM", () => {
console.info("SIGTERM signal received.");
server.close(() => {
console.log("Http server closed.");
});
});
```

[package.json](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-app/package.json)
```json
{
"dependencies": {
"express": "^4.17.1"
}
}
```
Next, inside of the `.github/workflows` create the following GitHub Action workflow YAML called `deploy-ce-app.yml`. The workflow called `Deploy App to Code Engine` is executed when a push occurs against the `main` branch of the repository. Initially it checks out the repository. In the next step, the `ibm/code-engine-github-action` will be used to deploy the application (component: app) to Code Engine. It uses Code Engine's push feature so we don't need to create the container image ourselves. The deployment will be directed to the project `MY-PROJECT` within your default resource group in the `Frankfurt` region (`eu-de`). The application will be named `my-ce-node-app`, utilizing the content of the `my-ce-app` directory as the source code used for the build step. For more information about Code Engine Push see the [Code Engine Build Docs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-build-config-local).

[deploy-ce-app.yml](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-app/deploy-ce-app.yml)
```yaml
name: Deploy App to Code Engine
on:
push:
branches:
- main
jobs:
app:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Deploy Application to Code Engine
uses: ibm/code-engine-github-action@v1
with:
api-key: ${{ secrets.IBM_IAM_API_KEY }}
region: 'eu-de'
project: 'MY-PROJECT'
component: 'app'
name: 'my-ce-app'
build-source: './my-ce-app'
```
Now, whenever changes are pushed into the `main` branch the Github Action is run and your Code is built and deployed to Code Engine always keeping your Application up to date with your latest changes.

## Deploying a Python Function
Create a directory `my-ce-py-func` containing your function source code you want to deploy to Code Engine. Inside the `my-ce-py-func` directory create the following files which make up a simple python function.

[__main__.py](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-py-func/__main__.py)
```python
from lorem_text import lorem

def main(params):
words = 10
return {
"headers": {
"Content-Type": "text/plain;charset=utf-8",
},
"body": lorem.words(words),
}
```

[requirements.txt](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-py-func/requirements.txt)
```
lorem-text
```
Like the Application example inside of the `.github/workflows` create the following GitHub action Workflow YAML called `deploy-ce-py-func.yml` The workflow called `Deploy Python Function to Code Engine` is executed when a push occurs against the `main` branch of the repository. The `ibm/code-engine-github-action` will be used to deploy the Python Function (component: fn) to Code Engine. The deployment will be directed to the project `MY-PROJECT` within your default resource group in the `Frankfurt` region (eu-de). The Function will be named `my-ce-py-fn`, utilizing the content of the `my-ce-py-func` directory as the source code.

[deploy-ce-py-func.yml](https://github.com/IBM/CodeEngine/blob/main/github-action-workflows/my-ce-py-func/deploy-ce-py-func.yml)

```yaml
name: Deploy Python Function to Code Engine
on:
push:
branches:
- main
jobs:
fn-py:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Deploy Python Function to Code Engine
uses: ibm/code-engine-github-action@v1
with:
api-key: ${{ secrets.IBM_IAM_API_KEY }}
region: 'eu-de'
project: 'MY-PROJECT'
component: 'fn'
runtime: python-3.11
name: 'my-ce-py-fn'
build-source: './my-ce-py-func'
```

## Conclusion
In this blog, we learned how to create Applications and Functions and automatically deploy them to [IBM Cloud Code Engine] using GitHub Actions as a CI/CD solution. The Code Engine enables developers to effortlessly enhance their development workflows by leveraging a fully managed serverless solution. The workflows depicted above powered by `ibm/codeengine-github-action` simplify and enhance your deployment process and experience.

Now its up to you! To get started, head on over to [IBM Cloud Code Engine](https://www.ibm.com/products/code-engine) and register for a new account or login to an existing IBM Cloud account and begin your serverless journey with Code Engine. Run your Applications, Jobs or Functions in the Cloud at scale. The documentation, additional information and examples can be found at the included links.

- [Code Engine](https://cloud.ibm.com/codeengine/overview)
- [Code Engine Docs](https://cloud.ibm.com/codeengine/overview)
- [Example Code](https://github.com/IBM/CodeEngine)
- [Code Engine Github Action](https://github.com/marketplace/actions/code-engine-github-action)
- [Example Source Code](https://github.com/IBM/CodeEngine/tree/main/github-action-workflows)
Loading
Loading