Deploy an Application

Overview

The Control Plane CLI offers developers the ability to containerize their code and push the resulting image to their org's private image registry. The image registry is scoped to the org and available for use by all workloads within the org. Along with the console, the CLI can be used to deploy the image to the cloud by configuring a GVC and workload.

This quick start will demonstrate how to:

  • Containerize a Node.js application
  • Configure a GVC and workload using the CLI
  • Test the deployed application

Prerequisites

Step One - Containerize the Sample Application

  1. Decompress the sample application to a new directory. The application is a web application that will display the environment variables of the running process. This will include variables that Control Plane injects.
TIP
  • Decompression helper commands:

    OSCommand
    macOSgunzip cpln_app.tgz && open cpln_app.tar
    Linux & Windows 10tar -xvf cpln_app.tgz
  1. Run the following command from the cpln_app directory to containerize the application:
NOTE

Substitute ORG_NAME with the name of your org. If you have already set a default org in your profile, you can omit the --org flag.

copy
cpln image build --name quick-start-4:0.1 --push --org ORG_NAME

This command will containerize the application locally using Docker and push the image to your org's private image registry. The image name will be quick-start-4 and the tag is 0.1. You can build and push multiple versions with the same name and different tags (e.g., 0.2, 0.3, etc.).

TIP

Notice that the application doesn't contain a Dockerfile. The cpln image build command uses Buildpacks to scan the application and automatically build the image. If your application has an existing Dockerfile, the command has the flag --dockerfile that can point to an existing Dockerfile.

Review the Push an Image guide for additional details.

Step Two - Configure a GVC

In this step, you will configure a new GVC for the application using the CLI. If you'd like to use the GVC created in the previous quick start, skip to step 3.

Run the following command to create a new GVC mapped to two different cloud providers/locations:

copy
cpln gvc create --name quick-start-4 --location aws-us-west-2 --location gcp-us-east1 --org ORG_NAME

The output from this command will show the new GVC and its associated locations.

TIP

To view the list of available locations, run the command: cpln location get --org ORG_NAME.

Review the Create a GVC guide for additional details.

Step Three - Configure a Workload

In this step, you will configure a new workload for the application.

Run the following command to create a new workload.

For the --name flag, choose an appropriate name for the workload. It will be used when generating the endpoint URL.

For the --image flag, use the name of the image that was created in step 1. Prefix the image name with \\image\ to have the platform pull the image from your org's private registry.

For the --gvc flag, use the GVC name created in step 2 or from the previous quick start.

For the --port flag, use port 8080 which is the port the application exposes.

The command uses the --public flag which will automatically set the firewall rules for this workload to allow inbound and outbound Internet traffic.

copy
cpln workload create --name show-env-variables --image //image/quick-start-4:0.1 --port
8080 --public --gvc quick-start-4 --org ORG_NAME

The output from this command will show the new workload name and the endpoint URL. The endpoint is using the domain name that is set in the GVC. Notice that the URL is HTTPS. A TLS certificate was generated and configured for the endpoint. The platform automatically performs TLS termination and port translation from 443 to 8080.

Review the Create a Workload and Workload Reference guide for additional details.

Step Four - Test the Deployed Application

Allow a few minutes for the workload to deploy, then copy the endpoint URL and paste it into a browser. The output will display the environment variables for the running process. The variables that are prefixed with CPLN_ are injected by Control Plane and can be used by your application.

For example, the variable CPLN_LOCATION will be the location where the workload was served from. Since we configured the GVC with two locations, this variable can change depending on the location of the caller since the endpoint URL is DNS geo-routed to the nearest healthy location.

Visit the Workload Environment Variables reference page to view the built-in variables.

Summary

This quick start demonstrated how to deploy an application, end-to-end, in a couple of steps. The sample application targeted Node.js, but you can deploy any language that can be containerized (e.g., Java, .NET, Go, etc.).

In the previous quick start, you used the console to deploy an application, here you exercised the CLI to perform the same actions. All resources (GVC, workload, etc.) created can be modified either using the console or the CLI.

Copyright © 2021 Control Plane Corporation. All rights reserved. Revision 30221ec6
Contents