copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2022-05-17 |
applications in code engine, apps in code engine, http requests in code engine, deploy apps in code engine, app workloads in code engine, deploying workloads in code engine, application, app, memory, cpu, environment variables |
codeengine |
{{site.data.keyword.attribute-definition-list}}
{: #deploy-app-crimage}
Deploy your app with {{site.data.keyword.codeengineshort}} that uses an image in {{site.data.keyword.registrylong}}. You can create an app from the console or with the CLI. {: shortdesc}
Before you begin
-
You must have an image in {{site.data.keyword.registrylong}}. For more information, see Getting started with {{site.data.keyword.registryshort}}. Or, you can build an image from repository source or from local source.
-
Verify that you can access the registry. See Setting up authorities for container registries.
{: #deploy-app-crimage-console}
Deploy an application that uses an image in {{site.data.keyword.registryshort}} by using the {{site.data.keyword.codeengineshort}} console. {: shortdesc}
{{site.data.keyword.codeengineshort}} can automatically pull images from a {{site.data.keyword.registryshort}} namespace in your account. To pull images from a different {{site.data.keyword.registryshort}} account or from a private Docker Hub account, see Deploying application workloads from images in a private registry.
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Start creating from Run a container image.
- Select Application.
- Enter a name for the application; for example,
helloapp
. 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. You must have a selected project to deploy an app.
- Select Container image and click Configure image.
- Select a container registry location, such as
IBM Registry, Dallas
. - Select
{{site.data.keyword.codeengineshort}} managed secret
for Registry access secret. Because this example uses an image in a {{site.data.keyword.registryshort}} namespace in your account, {{site.data.keyword.codeengineshort}} can automatically create and manage the registry access secret for you. - Select an existing namespace and name of the image in the registry for the {{site.data.keyword.codeengineshort}} app to reference. For example, select
mynamespace
and select the imagehello_repo
in that namespace. - Select a value for Tag; for example,
latest
. - Click Done.
- Modify any runtime settings or environment variables for your app. For more information about these options, see Options for endpoint visibility of apps and Options for deploying an app.
- Click Create to create the application.
- 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.
Now that you have deployed your application, you can view information about application revisions and any running instances, and configuration details.
If you want to add registry access to a {{site.data.keyword.registryshort}} instance that is not in your account, see Adding access to a {{site.data.keyword.registryshort}}.
{: #deploy-app-crimage-cli}
Deploy an application that uses an image in {{site.data.keyword.registrylong}} with the CLI with the ibmcloud ce app create
command. For a complete listing of options, see the ibmcloud ce app create
command.
{: shortdesc}
Before you begin
- Set up your {{site.data.keyword.codeengineshort}} CLI environment.
- Create and work with a project.
- Before you can work with a {{site.data.keyword.codeengineshort}} application that references an image in {{site.data.keyword.registryshort}}, you must first add access to the registry so {{site.data.keyword.codeengineshort}} can pull the image when the app is deployed. For information about required permissions for accessing image registries, see Setting up authorities for image registries.
-
To add access to {{site.data.keyword.registryshort_notm}}, create an IAM API key. To create an {{site.data.keyword.cloud_notm}} IAM API key with the CLI, run the
iam api-key-create
command. For example, to create an API key calledcliapikey
with a description of "My CLI APIkey" and save it to a file calledkey_file
, run the following command:ibmcloud iam api-key-create cliapikey -d "My CLI APIkey" --file key_file
{: pre}
If you choose to not save your key to a file, you must record the API key that is displayed when you create it. You cannot retrieve it later. {: important}
-
After you create your API key, add registry access to {{site.data.keyword.codeengineshort}}. To add access to {{site.data.keyword.registryshort}} with the CLI, use the
ibmcloud ce registry create
command to create an image registry access secret. For example, the followingregistry create
command creates registry access to a {{site.data.keyword.registryshort}} instance calledmyregistry
. Note, even though the--server
and--username
options are specified in the example command, the default value for the--server
option isus.icr.io
and the--username
option defaults toiamapikey
when the server isus.icr.io
.ibmcloud ce registry create --name myregistry --server us.icr.io --username iamapikey --password APIKEY
{: pre}
Example output
Creating image registry access secret 'myregistry'... OK
{: screen}
-
Create your app and reference the
hello_repo
image in {{site.data.keyword.registryshort}}. For example, use theibmcloud ce app create
command to create themyhelloapp
app to reference theus.icr.io/mynamespace/hello_repo
by using themyregistry
access information.ibmcloud ce app create --name myhelloapp --image us.icr.io/mynamespace/hello_repo --registry-secret myregistry
{: pre}
The format of the name of the image for this application is
REGISTRY/NAMESPACE/REPOSITORY:TAG
whereREGISTRY
andTAG
are optional. IfREGISTRY
is not specified, the default isdocker.io
. IfTAG
is not specified, the default islatest
. {: important} -
After your app deploys, you can access the app. To obtain the URL of your app, run
ibmcloud ce app get --name myhelloapp --output url
. When you curl themyhelloapp
app,Hello World
is returned.curl https://myhelloapp.abcdabcdhye.us-south.codeengine.appdomain.cloud
{: pre}
{: #nextsteps-appdeploycr}
-
After your app deploys, access your app through a URL.
-
Now that you app is deployed, consider making your apps event-driven. By using event subscriptions, you can trigger your apps by periodic schedules or set your app to react to events like file uploads.
-
After your app is deployed, you can update your deployed app and its referenced code by using any of the following ways, independent of how you created or previously updated your app:
-
If you have a container image, per the Open Container Initiative (OCI) standard{: external}, then you need to provide only a reference to the image, which points to the location of your container registry when you deploy your app. You can deploy your app with an image in a public registry or private registry.
-
If you are starting with source code that resides in a Git repository, you can choose to let {{site.data.keyword.codeengineshort}} take care of building the image from your source and deploying the app with a single operation. In this scenario, {{site.data.keyword.codeengineshort}} uploads your image to {{site.data.keyword.registrylong}}. To learn more, see Deploying your app from repository source code. If you want more control over the build of your image, then you can choose to build the image with {{site.data.keyword.codeengineshort}} before you deploy your app.
-
If you are starting with source code that resides on a local workstation, you can choose to let {{site.data.keyword.codeengineshort}} take care of building the image from your source and deploying the app with a single CLI command. In this scenario, {{site.data.keyword.codeengineshort}} uploads your image to {{site.data.keyword.registrylong}}. To learn more, see Deploying your app from local source code with the CLI. If you want more control over the build of your image, then you can choose to build the image with {{site.data.keyword.codeengineshort}} before you deploy your app.
For example, you might choose to let {{site.data.keyword.codeengineshort}} handle the build of your local source while you evolve the development of your source for the app. Then, after the image is matured, you can update the deployed app to reference the specific image that you want. You can repeat this process as needed.
When you deploy your updated app, the latest version of your referenced container image is downloaded and deployed, unless a tag is specified for the image. If a tag is specified for the image, then the tagged image is used for the deployment.
-
Looking for more code examples? Check out the Samples for {{site.data.keyword.codeenginefull_notm}} GitHub repo{: external}. {: tip}