You can use Flow in Apsara DevOps for continuous integration and deployment of task templates. This topic describes how to use Apsara DevOps to deploy a PHP task template to Serverless App Engine (SAE) as a ZIP package.
Background
If you are new to Apsara DevOps, familiarize yourself with its deployment process and the deployment methods supported by SAE. For more information, see Overview of deploying SAE applications and job templates with Apsara Devops 2020.
Step 1: Create a task template in SAE
If this is your first time hosting a job on SAE, create a task template in the SAE console. SAE supports deployments from both code packages and images. The deployment method for the task template must match the pipeline configuration.
For detailed instructions, see Manage task templates.
Step 2: Create an enterprise in Apsara DevOps
If this is the first time you are using Apsara DevOps Flow, you need to create your enterprise on Apsara DevOps. If you have already created an enterprise, you can skip this step.
Log on to Flow.
Set an enterprise name, select your R&D organization size, and then click Create Now.
Step 3: Create a pipeline in Apsara DevOps
Log on to Flow.
In the upper-right corner of the Flow page, click New Pipeline.
In the Select a pipeline template dialog box, select the template, and then click Create.
On the Flow Configuration tab, in the left-side navigation pane of the Add pipeline source panel, select code source. Then, configure the code source information and click Add.
Step 4: Deploy the task template to SAE
On the Flow Configuration tab, in the Build stage, click PHP build and upload to repository.
In the Edit panel that appears, configure the settings.
In the Task steps section, click the minus icon (-) next to Upload artifact, and then click OK.
Click + Add step and select from the drop-down list.
Expand PHP build and enter the following script in the Build command section.
Note You can change the PACKAGE_NAME value to manage package names for different applications and avoid conflicts.
Only the ZIP format is supported for packaging. If you need to include more directories or files in the package, modify the zip -r command.
# Install the packaging tool
apt-get update
apt-get install zip -y
# Define the package name
PACKAGE_NAME="hello-sae-php.zip"
# Ensure the build starts with a clean state by removing any previous package
rm -rf ${PACKAGE_NAME} || echo "Package does not exist. Ignoring cleanup."
# Add the ./nginx and ./php directories to the archive file
zip -r ${PACKAGE_NAME} ./nginx ./php
Expand Upload artifact (for EDAS/SAE). In the Files to upload field, enter the file name that you defined for PACKAGE_NAME in the previous step, such as hello-sae-php.zip.
In the upper-right corner of the Edit panel, click the close icon.
In the New stage section, click New task and select Update Serverless (SAE) task template.
In the Edit panel, configure the task settings, and then click Save and Run.
Parameter | Description |
Task name | A custom name for the task, up to 20 characters long. |
Build cluster | You can select a different build cluster for the task. |
Download pipeline source | If enabled, source files from the configured pipeline source are downloaded to the working directory. |
Select service connection | Select a service connection to authorize Apsara DevOps to deploy the task template to SAE. If you have not created a service connection, click Add service connection and complete the Alibaba Cloud RAM authorization before proceeding. |
Region | Select the region for the task template that you created in Step 1: Create a task template in SAE. |
Namespace | Select the namespace where you created the task template in Step 1: Create a task template in SAE. |
SAE task template | Select the task template that you created in Step 1: Create a task template in SAE. |
Build artifact | Select the tag name created in In the Edit panel, configure the settings. In the Task Steps section, click the minus icon to the right of Upload Build Output, and then click Confirm. Click + Add Step and select Upload > Upload Build Output (for EDAS/SAE). Expand PHP Build and enter the required parameters in the Build Command section. Modify the PACKAGE_NAME value to manage package names for different applications and prevent conflicts. Only the ZIP format is supported for packaging. To package more directories or files, you can modify the zip -r command to add them.# Install the packaging software apt-get update apt-get install zip -y # Define the package name PACKAGE_NAME="hello-sae-php.zip" # Ensure the build starts clean rm -rf ${PACKAGE_NAME} || echo "Package not exists. Ignore to cleanup" # Add ./nginx and ./php to the package file zip -r ${PACKAGE_NAME} ./nginx ./php Expand Upload Build Output (for EDAS/SAE). In the Upload File text box, enter the name of the file from the previous step, which is specified by PACKAGE_NAME, such as hello-sae-php.zip. Click the close icon in the upper-right corner of the Edit panel. In the Edit panel, configure the settings. In the Task Steps section, click the minus icon to the right of Upload Build Output, and then click Confirm. Click + Add Step and select Upload > Upload Build Output (for EDAS/SAE). Expand PHP Build and enter the required parameters in the Build Command section. Modify the PACKAGE_NAME value to manage package names for different applications and prevent conflicts. Only the ZIP format is supported for packaging. To package more directories or files, you can modify the zip -r command to add them.# Install the packaging software apt-get update apt-get install zip -y # Define the package name PACKAGE_NAME="hello-sae-php.zip" # Ensure the build starts clean rm -rf ${PACKAGE_NAME} || echo "Package not exists. Ignore to cleanup" # Add ./nginx and ./php to the package file zip -r ${PACKAGE_NAME} ./nginx ./php Expand Upload Build Output (for EDAS/SAE). In the Upload File text box, enter the name of the file from the previous step, which is specified by PACKAGE_NAME, such as hello-sae-php.zip. Click the close icon in the upper-right corner of the Edit panel.. |
Use Container Registry Enterprise Edition | This parameter is required only for image-based deployments. |
Task Plug-ins | Configure task plug-ins to send pipeline notifications. DingTalk robot notification. Email notification: Enter email addresses. Separate multiple addresses with semicolons (;). Webhook notification. WeCom group notification. Feishu group notification.
|
In the Run configurations dialog box, confirm the settings and click Run.
Verify the results
After Apsara DevOps starts the deployment, the Recent Runs tab opens by default, where you can view the pipeline status. If a run fails, examine the pipeline logs to diagnose the issue, and then run the pipeline again.