From 5d844f334cbb63c64f657d15eb22e80474f7a367 Mon Sep 17 00:00:00 2001 From: Luke Roy Date: Tue, 20 Feb 2024 10:26:46 +0100 Subject: [PATCH] add Examples for blog Signed-off-by: Luke Roy --- github-action-workflows/README.md | 6 +++++ github-action-workflows/my-ce-app/app.js | 22 ++++++++++++++++ .../my-ce-app/deploy-ce-app.yml | 23 +++++++++++++++++ .../my-ce-app/package.json | 5 ++++ .../my-ce-py-func/__main__.py | 11 ++++++++ .../my-ce-py-func/deploy-ce-py-func.yml | 25 +++++++++++++++++++ .../my-ce-py-func/requirements.txt | 1 + 7 files changed, 93 insertions(+) create mode 100644 github-action-workflows/README.md create mode 100644 github-action-workflows/my-ce-app/app.js create mode 100644 github-action-workflows/my-ce-app/deploy-ce-app.yml create mode 100644 github-action-workflows/my-ce-app/package.json create mode 100644 github-action-workflows/my-ce-py-func/__main__.py create mode 100644 github-action-workflows/my-ce-py-func/deploy-ce-py-func.yml create mode 100644 github-action-workflows/my-ce-py-func/requirements.txt diff --git a/github-action-workflows/README.md b/github-action-workflows/README.md new file mode 100644 index 00000000..3988a2e5 --- /dev/null +++ b/github-action-workflows/README.md @@ -0,0 +1,6 @@ +# Source Code for the IBM Cloud Code Engine: Deploying Apps, Jobs and Functions using GitHub Actions Blog post + +This folder contains the source code used in the [IBM Cloud Code Engine: Deploying Apps, Jobs and Functions using GitHub Actions](https://community.ibm.com/community/user/blogs/luke-roy/2024/02/12/ibm-cloud-code-engine-deploying-apps-jobs-and-func) Blog Post. + +- [App](github-action-workflows/my-ce-app) +- [Python Function](github-action-workflows/my-ce-py-func) \ No newline at end of file diff --git a/github-action-workflows/my-ce-app/app.js b/github-action-workflows/my-ce-app/app.js new file mode 100644 index 00000000..b29a4294 --- /dev/null +++ b/github-action-workflows/my-ce-app/app.js @@ -0,0 +1,22 @@ +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."); + }); +}); \ No newline at end of file diff --git a/github-action-workflows/my-ce-app/deploy-ce-app.yml b/github-action-workflows/my-ce-app/deploy-ce-app.yml new file mode 100644 index 00000000..a83141f9 --- /dev/null +++ b/github-action-workflows/my-ce-app/deploy-ce-app.yml @@ -0,0 +1,23 @@ +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' \ No newline at end of file diff --git a/github-action-workflows/my-ce-app/package.json b/github-action-workflows/my-ce-app/package.json new file mode 100644 index 00000000..9dca061d --- /dev/null +++ b/github-action-workflows/my-ce-app/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "express": "^4.17.1" + } +} \ No newline at end of file diff --git a/github-action-workflows/my-ce-py-func/__main__.py b/github-action-workflows/my-ce-py-func/__main__.py new file mode 100644 index 00000000..6deb0a0e --- /dev/null +++ b/github-action-workflows/my-ce-py-func/__main__.py @@ -0,0 +1,11 @@ +from lorem_text import lorem + +def main(params): + words = 10 + + return { + "headers": { + "Content-Type": "text/plain;charset=utf-8", + }, + "body": lorem.words(words), + } \ No newline at end of file diff --git a/github-action-workflows/my-ce-py-func/deploy-ce-py-func.yml b/github-action-workflows/my-ce-py-func/deploy-ce-py-func.yml new file mode 100644 index 00000000..fddee62c --- /dev/null +++ b/github-action-workflows/my-ce-py-func/deploy-ce-py-func.yml @@ -0,0 +1,25 @@ +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' \ No newline at end of file diff --git a/github-action-workflows/my-ce-py-func/requirements.txt b/github-action-workflows/my-ce-py-func/requirements.txt new file mode 100644 index 00000000..a56f726d --- /dev/null +++ b/github-action-workflows/my-ce-py-func/requirements.txt @@ -0,0 +1 @@ +lorem-text \ No newline at end of file