zhangtbj / CodeEngine

Samples for using Code Engine

Home Page:https://cloud.ibm.com/codeengine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Samples for IBM Cloud Code Engine

This repository contains samples for how to use IBM Cloud Code Engine.

These samples are designed such that they should be able to be fully built and used by anyone. Unless otherwise noted the overall pattern that will be followed is:

  • a build script shows how each container image used in the sample is built. By default, the script will push the image to the ibmcom namespace on DockerHub, so to use this yourself you'll need to set the REGISTRY environment variable to your own registry and/or namespace. Also, you MUST use a registry that allows for anonymous/public downloads of your images, since as of now (to keep the scripts simple) they do not deal with private registry access tokens by default.
    • However, if you do decide to push your images into a registry that is private, you'll need to modify the run scripts to specify the --registry-secret option on the app and job creation commands to point to your secret that includes the registry credentials.
  • a run script will execute the sample. Most will also include logic to verify the output to ensure everything is working as expected. As with build, it will default to using the ibmcom container images, so to use your own you'll need to set the REGISTRY environment variable. This means that you should be able to just execute run without running build first, and it'll just use the pre-built images from ibmcom.
    • invoking run clean should clean up from any previous execution without re-running the sample.

Most samples will try to be relatively small to focus on one particular task so that it can be re-used easily and integrated into a larger use-case.

It is assumed that the following are installed:

It is also assumed that you have a Code Engine project already created and selected, e.g.:

$ ibmcloud ce project create --name demos

Samples

Apps

  • hello
    Very basic "hello world!" type of application written in Node.js. Start here!
  • helloworld
    Similar to hello except this is written in golang and adds a few bells-n-whistles to allow you to control what it does when invoked.
  • bind-app
    This will create an instance of DB2 in the IBM Cloud and then ask Code Engine to bind it to an Application so we can access it from the App. The credentials, etc. will be injected into the App via environment variables.
  • cecli
    Show how to invoke the Code Engine CLI from within an App. This can be used to then start additional Code Engine resources (Apps/Jobs) dynamically. Same logic could be used in Batch Jobs.
  • sessions
    Starts a stateful application that scales based on load. The state is kept in an instance of Redis, also running within Code Engine. Demonstrates the use of non-http components and private networking between components.
  • websocket Shows how to interact with an Application via WebSockets.

Batch Jobs

  • job
    This will create a Batch Job that will print basic debugging information to the logs, and then show those logs. It'll create the Batch Job with and without a Job definition to show both options.
  • app-n-job
    This will use the same image for both an Application and a Batch Job. Just to show that it's possible.
  • app2job
    This will show how to submit a Job from an Application based on an incoming HTTP request to the Application.
  • bind-job
    This will create an instance of DB2 in the IBM Cloud and then ask Code Engine to bind it to a Batch Job so we can access it from the Job. The credentials, etc. will be injected into the Job via environment variables.
  • job2app
    This will demostrate how to create a simple Batch Job and how to have it communicate with an Application running within the same project.

Source-to-Image

  • s2i-buildpacks
    This will show how to use the source-to-image feature of Code Engine to build an Application from a git repo (using a Buildpack), push it to a private registry, and then deploy an Application using that image.
  • s2i-dockerfile
    This will show how to use the source-to-image feature of Code Engine to build an Application from a git repo (using a Dockerfile), push it to a private registry, and then deploy an app using that image.

Eventing

  • ping
    This will show how to setup a simple Ping(cron) Event Source and send its events to an Application.
  • cos-event
    This will show how to setup a COS Event Source and send its events to an Application.
  • cos2cos
    This will show how you can use eventing to monitor changes in a Cloud Object Storage bucket, and then act on those changes by processing any new files in the bucket and then uploading a new object into a secondary bucket. It can also get Ping (cron) events to periodically check for missed files.

Misc

  • configmaps-env
    Shows how to define and inject a ConfigMap as environment variables into an Application.
  • configmaps-vol
    Shows how to define and inject a ConfigMap as a volume into an Application.
  • secrets-env
    Shows how to define and inject a Secret as environment variables into an Application.
  • secrets-vol
    Shows how to define and inject a Secret as a volume into an Application.

Resources

You may also open issues and PRs in the repository too.

About

Samples for using Code Engine

https://cloud.ibm.com/codeengine

License:Apache License 2.0


Languages

Language:Shell 52.1%Language:Go 25.0%Language:Python 16.0%Language:Dockerfile 3.6%Language:HTML 2.5%Language:JavaScript 0.8%