All Products
Search
Document Center

CloudOps Orchestration Service:Implement automated deployment by using Jenkins, OOS, and OSS

Last Updated:Feb 07, 2024

You can implement automated deployment by using Jenkins, CloudOps Orchestration Service (OOS), and Object Storage Service (OSS).

This topic uses WordPress as an example to describe how to use Jenkins, OOS, and OSS to implement automated deployment. The following products are involved:

  • WordPress (address on GitHub)

  • OOS, an automated O&M service provided by Alibaba Cloud, which is used for software version management and phased release

  • OSS, which is used to store built software packages

  • Jenkins, which is used to automate the build process and update software packages in OSS and OOS upon triggers

  • Resource Orchestration Service (ROS), an automated resource deployment service provided by Alibaba Cloud. ROS allows you to deploy cloud resources such as Elastic Compute Service (ECS), ApsaraDB for RDS, and Server Load Balancer (SLB) that the system depends on with one click.

Preparations

Create a WordPress environment in the cloud

To create a WordPress environment with ECS and ApsaraDB for RDS by using ROS, perform the following steps:

  1. Log on to the ROS console.

  2. In the left-side navigation pane, choose Templates > Sample Templates. On the Sample Templates page, find the template named Create a WordPress Environment Based on ECS and ApsaraDB for RDS and click Create Stack.

  3. Set parameters such as Instance Type and Instance Password, click Create, and then wait for a while. If the environment is created, the output result of the stack shown in the following figure appears on the Output tab. EECA6AF1-6FF7-44DB-ABF8-67EFF0D70F67

  4. Check the value of the WordPressUrl parameter, which indicates the URL of a standalone WordPress website. Open the URL in a browser to verify that the website has been deployed.

Install and configure Alibaba Cloud CLI

This section describes how to install and configure Alibaba Cloud Command Line Interface (CLI) in macOS. For more information about how to install and configure Alibaba Cloud CLI in other operating systems.

  1. Create a Resource Access Management (RAM) user for Alibaba Cloud CLI to obtain the AccessKey. For more information, see Create a RAM user.

  2. Install Alibaba Cloud CLI.

    brew install aliyun-cli

  3. Configure Alibaba Cloud CLI.

    aliyun configure

  4. Verify that Alibaba Cloud CLI is available. If so, you can view the supported regions in the command output.

aliyun ecs DescribeRegions

Install and configure Jenkins

This section describes how to install and configure Jenkins in macOS. For more information about how to install and configure Jenkins in other operating systems, see Install Jenkins.

  1. Install the latest version of Jenkins.

    brew install jenkins

  2. Install the Jenkins Long-Term Support (LTS) release.

    brew install jenkins-lts

  3. Start Jenkins.

    brew services start jenkins-lts

  4. Open localhost:8080 in a browser.

  5. Copy the initial password from the provided directory, paste it in the Administrator password field, and then click Continue.

  6. Install the default plug-ins.

  7. Set the username and password and then log on to Jenkins.

Use Jenkins to update a software package

  1. Click New Item on the Jenkins dashboard.

  2. Select Freestyle project, enter the name of your project in the Enter an item name field, and then click OK.

  3. Go to the Source Code Management tab, select Git, and then enter the repository URL.

    https://github.com/WordPress/WordPress.git

  4. Go to the Build tab, click Add build step in the Build section, and then select Execute shell from the drop-down list. Copy and paste the following script to the Command field. The script is used to package the master branch of WordPress, copy the package to the oss://wordpress-test-oos path, and then create a software package named wordpress in OOS.

    version=`date +%s`
    # Generate the wordpress_$version.tar package.
    tar -cvf wordpress_$version.tar `find .|grep -v wp-config-sample.php|grep -v targets|grep -v .git|grep -v ^\. $`
    # Copy the package to OSS.
    /usr/local/bin/aliyun oss cp wordpress_$version.tar oss://wordpress-test-oos/wordpress_$version.tar
    templateName=wordpress
    # Specify the value of Location and include the installation script in templateContent.
    # {
    #   "FormatVersion": "OOS-2020-01-01-Package",
    #   "Description": "",
    #   "Packages": [{
    #       "Name": "wordpress_$version.tar",
    #       "Location": "oss://wordpress-test-oos/wordpress_$version.tar",
    #       "InstallScript": "test -e wordpress || mkdir wordpress && cd wordpress && mv ../wordpress_$version.tar . && tar xvf wordpress_$version.tar > /dev/null && rm wordpress_$version.tar && cp -rf * /var/www/html/",
    #       "UninstallScript": "echo uninstall",
    #       "Targets": [{
    #           "PlatForm": "centos",
    #           "Architect": "x86_64"
    #       }]
    #   }]
    # }
    templateContent="{\"FormatVersion\":\"OOS-2020-01-01-Package\",\"Description\":\"\",\"Packages\":[{\"Name\":\"wordpress_$version.tar\",\"Location\":\"oss://wordpress-test-oos/wordpress_$version.tar\",\"InstallScript\":\"test -e wordpress || mkdir wordpress && cd wordpress && mv ../wordpress_$version.tar . && tar xvf wordpress_$version.tar > /dev/null && rm wordpress_$version.tar && cp -rf * /var/www/html/\",\"UninstallScript\":\"echo uninstall\",\"Targets\":[{\"PlatForm\":\"centos\",\"Architect\":\"x86_64\"}]}]}"
    # Update the software package in OOS.
    /usr/local/bin/aliyun oos CreateTemplate --TemplateName=$templateName --Content "$templateContent" || /usr/local/bin/aliyun oos UpdateTemplate --TemplateName=$templateName --Content "$templateContent"
    # Delete the temporary package.
    rm wordpress_$version.tar

  5. Click Save.

  6. Click Build Now to start deployment. Verify the deployment status by clicking the build number under Build History.

  7. On the Console Output page, view the logs of the deployment. The whole process includes pulling code from Git, running the tar command to generate a package, copying the package to OSS, and then creating (updating) a package named wordpress in OOS. To view the package, log on to the OOS console, switch to the target region, and then click My Software in the left-side navigation pane.

  8. Click Details in the Actions column to view the package details, including the package name, storage location, installation script, uninstallation script, and historical versions.

Deploy the software package in the OOS console

  1. Log on to the OOS console and click My Software in the left-side navigation pane. On the Batch Software Management page, click Create. On the page that appears, select My Software for Software Type, select Install and wordpress for Operations, and then select the target instance where the software package is to be deployed. In this example, select the ID of the instance created in the ROS console.

  2. Note that the Select Instances button is dimmed now. In this case, you need to configure a RAM role for the instance. OOS assumes this role to obtain package information and the permission to download the package from OSS. Click Authorize.

  3. The page for adding a RAM role appears.

    • If an existing RAM role has been granted the AliyunOOSReadOnlyAccess and AliyunOSSReadOnlyAccess permissions and is assumed by ECS, click Execute. The execution list shows that the execution is successful.

    • To create a RAM role, perform the following steps:

      1. Log on to the RAM console. Click Create RAM Role, select Alibaba Cloud Service as the trusted entity type, and then select ECS as the trusted service.

      2. Grant the AliyunOOSReadOnlyAccess and AliyunOSSReadOnlyAccess permissions to the new role.

      3. Go to the Batch Instance Operations page, select Instance Operations and Add Role, and then assign the RAM role to the instance.

  4. After the RAM role is assigned, return to the Batch Software Management page, select the instance to which the RAM role is assigned, and then click Execute Now.

  5. Verify that the execution is successful and the WordPress files in /var/www/html are the latest. You can click Details in the Actions column to view the execution details.

Summary

We have completed the continuous integration or continuous delivery (CI/CD) process by using OOS and Jenkins. By using the My Software feature of OOS, you can manage software versions and deploy applications in the phased release mode. In Jenkins, you can also directly call the My Software feature of OOS to automate the deployment process. We will introduce how to use OOS and Jenkins to automatically update images in subsequent articles.