How to Quickly Transform a Container Application into a Cloud Development Application
Understand Cloud Development Application
Cloud development applications can be understood as applications running in a cloud development environment. For example, a service that includes capabilities such as frontend, backend, database, and others can be deployed with one click directly into the cloud development environment, utilizing various underlying Serverless resources to enjoy the benefits of elasticity and maintenance-free operations.
A cloud development application can be broken down into three parts, including code, declarative configuration, and environment variable information.
We will demonstrate how to rapidly transform an open-source containerized project into a cloud development application that can be deployed with one click.
Nextcloud is a personal cloud storage solution that comes with built-in applications such as photo albums, calendar contacts, file management, and RSS reader. This open-source application provides a deployable Docker image and requires a MySQL database. The following section will demonstrate how to achieve one-click deployment for this application.
Through one-click deployment in cloud development, applications can be deployed in the user's cloud development environment without the need to worry about server management and maintenance.
Project Demo URL:
https://fx-1259727701.ap-shanghai.service.tcloudbase.com/
Experience One-Click Deployment
Click the Deploy button below to install the NextCloud application with one click.
After clicking the button above, you will be redirected to the Tencent Cloud Development Console to enter the quick installation and deployment process.
The first step is to select a CloudBase environment (Note: For this application, we need to choose an environment where the root path of the HTTP access route is not occupied).
Step 2: You can configure the network, set tags, and associate or create cloud resources. For example, this application relies on CFS for container file storage and uses CynosDB for MySQL (Serverless edition) as the database dependency.
Click Complete, then wait for the installation to finish. After that, you can open the application's access address in the console to access it.
How to Develop a Cloud Development Application
So how do we build such a cloud development application that supports one-click deployment?
The overall process is divided into 3 steps, primarily consisting of development, configuration, and deployment verification phases. This document will focus mainly on the configuration and deployment verification phases.
Development
The development phase will not be covered in detail, as the specific implementation can be understood by obtaining the source code.
Project Source Code
The source code for this project can be viewed and obtained on Github:
https://github.com/TencentCloudBase-Marketplace/nextcloud
Nextcloud official open source repository
https://github.com/nextcloud/server
Cloud Development and Other Cloud Resources Used
Cloud Development Cloud Hosting service: Used to deploy the backend service of the application.
CynosDB: Use CynosDB database to store data
CFS: Use CFS for persistent data storage
Configuration
After obtaining the project code, how do we build this application into a cloud development application that supports one-click deployment?
The following steps will explain how to build a Cloud Development application through configuration.
Configuring Application Basic Information
First, create a cloudbaserc.json
configuration file. The content of the file is as follows.
{
"envId": "{{env.ENV_ID}}",
"version": "2.0",
"$schema": "https://framework-1258016615.tcloudbaseapp.com/schema/latest.json",
"framework": {
"name": "nextcloud",
"plugins": {}
}
}
Key Points
envId
specifies the environment where the application is deployed. Here we use the template variableenv.ENV_ID
to read theENV_ID
environment variable.framework.name
is the application's English name, supporting only A-Z, a-z, 0-9, -, and _, with a length of 1-32 characters.framework.plugins
is the plugin information used by the application. This is left blank for now; we will fill it in based on the resources and application type below.- To learn more about project information configuration, please refer to the Application Project Information Documentation.
Using the Cloud Run Plugin
In this step, we need to use the Cloud Run plugin to automatically deploy container services to CloudBase Run on CloudBase.
Add a field server
under framework.plugins
, where the value of the field is a JSON object.
{
"server": {
"use": "@cloudbase/framework-plugin-container",
"inputs": {
"cpu": 0.5,
"mem": 1,
"serviceName": "nextcloud",
"servicePath": "/",
"uploadType": "image",
"containerPort": 80,
"imageInfo": {
"imageUrl": "nextcloud:20"
},
"envVariables": {
"MYSQL_HOST": "{{env.DB_IP}}:{{env.DB_PORT}}",
"MYSQL_DATABASE": "nextcloud"
},
"volumeMounts": {
"/var/www/html": "nextcloud-cfs"
}
}
}
}
Key Points
- The name of the field
server
can be customized; it only serves as an alias, and the same applies below. "use": "@cloudbase/framework-plugin-container"
indicates that the@cloudbase/framework-plugin-container
cloud run plugin is used here to deploy images and services to CloudBase Run.inputs
is used to set the parameters received by the plugin. The configuration above accomplishes the following:- Specifies the CPU and memory specifications for the cloud hosting service,
- Specified the service name: "serviceName": "nextcloud"
- Specified the HTTP access path for service deployment: "servicePath": "/", equivalent to the root directory
- Specifies deployment using an image on port 80, with the image address and version as
nextcloud:20
- In the
envVariables
section for environment variables, we specify the environment variables to be injected into the container runtime.MYSQL_HOST
is an environment variable supported by NextCloud, which can be used to configure the application's database connection information. We use{{env.DB_IP}}:{{env.DB_PORT}}
as template variables to generate the connection address. The actual IP address and port will be populated at build time based on the real IP and port of the associated database. - In the
volumeMounts
section for mount directory settings, we declare that a CFS persistent storage instance named "nextcloud-cfs" will be mounted at the path "/var/www/html" within the container.
- The cloud hosting plugin also supports configuration of code sources, auto-scaling settings, and more. For detailed configuration instructions, please refer to the Cloud Hosting Container Configuration Documentation
Configuring Application Parameters and Dependencies
When deploying applications, users may also need to input custom parameters or configure external cloud resources as mentioned above.
These can all be configured in framework.requirement
.
Field | Description | Type |
---|---|---|
addons | External cloud resources used during application deployment, including cfs, cynosdb, redis, etc. | AddonsConfig |
environment | Declares environment variables for the application at build time and runtime, injected by default into the computing environment (Cloud Functions, Cloud Applications), also used as environment variables during cloud build and deployment, and can be referenced in cloudbaserc.json via env.ENV_NAME | EnvironmentConfig |
Next, we add the following JSON configuration to framework.requirement
.
{
"requirement": {
"addons": [
{
"type": "CFS",
"name": "nextcloud-cfs"
},
{
"type": "CynosDB",
"name": "nextcloud",
"envMap": {
"IP": "DB_IP",
"PORT": "DB_PORT",
"USERNAME": "MYSQL_USER",
"PASSWORD": "MYSQL_PASSWORD"
}
}
]
}
}
Key Points
- In
addons
, we can declare the dependent cloud resources. - First, we specify the dependency on
CFS
with the namenextcloud-cfs
; this name must correspond to the mount name in the cloud hosting plugin mentioned above. - Next, we specify the dependency on
CynosDB
. Here we focus on theenvMap
configuration. After the database instance is successfully created, the database's IP, PORT, USERNAME, and PASSWORD will be written to the application's global environment variables. We can map these connection details to the required environment variable names. For example, we configure the password to be mapped toMYSQL_PASSWORD
, which can be directly accessed within the container. - For other advanced usage techniques, please refer to the Application Dependency Configuration Documentation
Generate Deploy Button
Next, we can upload the code to Git to generate a one-click deploy button. First, open the one-click deploy button generation URL:
https://docs.cloudbase.net/framework/deploy-button.html
On the page, enter the project's Git URL, configuration file directory, and branch information to automatically generate the following deploy button code snippet.
Here, code snippets for the deploy button in several formats will be generated, which can be embedded in different scenarios to allow users to deploy your application.
- Markdown code is suitable for scenarios like README files, Markdown-based blog posts, etc.
- HTML code is suitable for scenarios like WeChat Official Accounts, HTML-based websites/blog posts, etc.
- URL links can be used on any page that supports hyperlinks. You can copy the link below and paste it into the corresponding page.
After generating the deploy button, you can follow the cloud development application template to write the README document and submit the application to the Cloud Development Application Center.
Application Template URL
https://github.com/TencentCloudBase-Marketplace/app-template
Summary
In this article, we learned what a cloud development application is, using the open-source project Nextcloud as an example, and introduced how to quickly transform an open-source containerized project into a cloud development application that can be deployed with one click.
Through hands-on practice, we have also learned about cloud development and the usage of CloudBase Framework. By completing development, configuration, and deployment verification, applications can be quickly transformed into rapidly distributable programs. Users can automatically deploy applications without manually setting up environments or configurations.
Reference Documentation
- CloudBase Framework:https://github.com/Tencent/cloudbase-framework
- CloudBase Framework Documentation: https://docs.cloudbase.net/framework/
- One-Click Deployment Button Generator: https://docs.cloudbase.net/framework/deploy-button.html
- Cloud Development Application Template: https://github.com/TencentCloudBase-Marketplace/app-template
- CloudBase Application Source Code List: https://github.com/TencentCloudBase-Marketplace