copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2022-05-12 |
getting started with ibm cloud code engine, code engine, ibm cloud code engine, jobs in code engine, apps in code engine, builds with code engine, {{site.data.keyword.codeenginefull_notm}}, building container image, source code |
codeengine |
{{site.data.keyword.attribute-definition-list}}
{: #getting-started}
{{site.data.keyword.codeenginefull}} is a fully managed, serverless platform that runs your containerized workloads, including web apps, micro-services, event-driven functions, or batch jobs. {{site.data.keyword.codeengineshort}} even builds container images for you from your source code. All these workloads can seamlessly work together because they are all hosted within the same Kubernetes infrastructure. The {{site.data.keyword.codeengineshort}} experience is designed so that you can focus on writing code and not on the infrastructure that is needed to host it. {: shortdesc}
First, learn about some key terms for {{site.data.keyword.codeengineshort}} and then get started with one of the following options.
{: #term-summary}
Before you get started, become familiar with some key terms for {{site.data.keyword.codeengineshort}}. Afterward, you can test your knowledge and take a quiz!{: external}
Term | Description |
---|---|
Project | A project is a grouping of {{site.data.keyword.codeengineshort}} entities such as applications, jobs, and builds. Projects are used to manage resources and provide access to its entities. |
Application | An application, or app, runs your code to serve HTTP requests. An application has a URL for incoming requests. The number of running instances of an application are automatically scaled up or down (to zero) based on incoming workload. |
Build | A build, or image build, is a mechanism that you can use to create a container image from your source code. {{site.data.keyword.codeengineshort}} supports building from a Dockerfile or Cloud Native Buildpacks. |
Job | A job runs one or more instances of your executable code. Unlike applications, which include an HTTP Server to handle incoming requests, jobs are designed to run one time and exit. |
{: caption="Table 1. {{site.data.keyword.codeengineshort}} Terms" caption-side="bottom"} |
For more information about terms, see {{site.data.keyword.codeengineshort}} terminology.
{: #app-hello}
Create your first {{site.data.keyword.codeengineshort}} app by using the icr.io/codeengine/helloworld
image.
{: shortdesc}
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Start creating from Run a container image.
- Select Application.
- Enter a name for the application. Use a name for your application that is unique within the project.
- Select a project from the list of available projects. You can also create a new one. Note that you must have a selected project to deploy an app.
- Select to run a Container image and specify
icr.io/codeengine/helloworld
for the image reference. For this example, you do not need to modify the default values for endpoint or runtime settings. For more information about the code that is used for this example, seehelloworld
{: external}. - Click Create.
- After the application status changes to Ready, you can test the application. Click Test application and then click Send request in the Test application pane. To open the application in a web page, click Application URL.
Example output
Hello World from:
___ __ ____ ____
/ __)/ \( \( __)
( (__( O )) D ( ) _)
\___)\__/(____/(____)
____ __ _ ___ __ __ _ ____
( __)( ( \ / __)( )( ( \( __)
) _) / /( (_ \ )( / / ) _)
(____)\_)__) \___/(__)\_)__)(____)
Some Env Vars:
--------------
CE_APP=myapp
CE_DOMAIN=us-south.codeengine.appdomain.cloud
CE_SUBDOMAIN=abcdabcdab
HOME=/root
HOSTNAME=myapp-00001-deployment-6db6d89dc7-k6qc7
K_REVISION=myapp-00001
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PORT=8080
PWD=/
SHLVL=1
{: screen}
You deployed your first application to {{site.data.keyword.codeengineshort}} and tested it out. Go to the Tutorial: Deploying applications to try out more options for applications.
{: #first-job}
Create and run your first {{site.data.keyword.codeengineshort}} job by using the icr.io/codeengine/firstjob
image. This job prints Hi from a batch job! My index is: <index>
.
{: shortdesc}
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Start creating from Run a container image.
- Select Job.
- Enter a name for the job. Use a name for your job that is unique within the project.
- Select a project from the list of available projects. You can also create a new one. Note that you must have a selected project to create a job.
- Specify
icr.io/codeengine/firstjob
for the image reference. For this example, you do not need to modify the default values for environment variables or runtime settings. For more information about the code that is used for this example, seefirstjob
{: external}. - Click Create.
- From your job page, click Submit job to submit a job based on the current configuration.
- From the Submit job pane, accept all the default values, and click Submit job again to run your job.
When logging is enabled, the expected output of Hi from a batch job! My index is: 0
is displayed in the logs. To learn about running jobs with logging enabled, see Viewing logs.
{: tip}
You created and ran your job from the console. Go to the Tutorial: Running jobs or Running jobs in Code Engine to try out more options for jobs.
{: #build-image-gs}
Create and run your first {{site.data.keyword.codeengineshort}} build and then deploy the container image in an application. {: shortdesc}
{{site.data.keyword.codeengineshort}} can automatically push images to a {{site.data.keyword.registryshort}} namespace in your account. It can even create a namespace for you. To push images to a different {{site.data.keyword.registryshort}} account or to a private Docker Hub account, see Adding access to a private container registry.
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Start creating from Start with source code.
- Select Application.
- Enter a name for the application. Use a name for your application that is unique within the project.
- Select a project from the list of available projects. You can also create a new one. Note that you must have a selected project to deploy an app.
- Select Source code.
- Click Specify build details.
- Select
https://github.com/IBM/CodeEngine
for Source repository andmain
for Branch name. If you do not provide a branch name and you leave the field empty, {{site.data.keyword.codeengineshort}} automatically uses the default branch of the specified repository. Click Next. - Select
Dockerfile
for Strategy,Dockerfile
for Dockerfile,10m
for Timeout, andMedium
for Build resources. Click Next. - Select a container registry location, such as
IBM Registry, Dallas
to specify where to store the image of your build output - For Registry access secret, select
{{site.data.keyword.codeengineshort}} managed secret
and let {{site.data.keyword.codeengineshort}} create and manage this secret for you. - Select an existing namespace or enter a name for a new one, for example,
newnamespace
. - Enter a name for your image and optionally a tag.
- Click Done.
- Click Create.
After your build run is submitted, the built container image is sent to {{site.data.keyword.registryshort}} and then your application pulls the image and deploys for you. After the application status changes to Ready, you can try it out. Click Test application and then click Send request in the Test application pane. To open the application in a web page, click Application URL.
Example output
Hello World from:
___ __ ____ ____
/ __)/ \( \( __)
( (__( O )) D ( ) _)
\___)\__/(____/(____)
____ __ _ ___ __ __ _ ____
( __)( ( \ / __)( )( ( \( __)
) _) / /( (_ \ )( / / ) _)
(____)\_)__) \___/(__)\_)__)(____)
Some Env Vars:
--------------
CE_APP=myapp
CE_DOMAIN=us-south.codeengine.appdomain.cloud
CE_SUBDOMAIN=abcdabcdab
HOME=/root
HOSTNAME=myapp-00001-deployment-6db6d89dc7-k6qc7
K_REVISION=myapp-00001
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PORT=8080
PWD=/
SHLVL=1
{: screen}
You submitted source code to {{site.data.keyword.codeengineshort}} and created a container image that you then deployed in an application - all from one interface.
Go to Building a container image to explore and try out more options for builds.
{: #nextsteps-getstart}
Learn more about performing these {{site.data.keyword.codeengineshort}} tasks from the console or with the {{site.data.keyword.codeengineshort}} CLI.
Looking for more code examples? Check out the Samples for {{site.data.keyword.codeenginefull_notm}} GitHub repo{: external}. {: tip}