As a developer, you need a pipeline that fetches an automation cloud template from an on-premises GitHub instance every time you commit a change. You need the pipeline to deploy a WordPress application to either Amazon Web Services (AWS) EC2 or a data center. Code Stream calls the cloud template from the pipeline and automates the continuous integration and continuous delivery (CICD) of that cloud template to deploy your application.

To create and trigger your pipeline, you'll need a VMware Cloud Template.

For Cloud template source in your Code Stream cloud template task, you can select either:

  • Cloud Assembly template as the source control. In this case, you do not need a GitLab or GitHub repository.
  • Source Control if you use GitLab or GitHub for source control. In this case, you must have a Git webhook and trigger the pipeline through the webhook.

If you have a YAML cloud template in your GitHub repository, and want to use that cloud template in your pipeline, here's what you'll need to do.

  1. In Cloud Assembly, push the cloud template to your GitHub repository.
  2. In Code Stream, create a Git endpoint. Then, create a Git webhook that uses your Git endpoint and your pipeline.
  3. To trigger your pipeline, update any file in your GitHub repository and commit your change.

If you don't have a YAML cloud template in your GitHub repository, and want to use a cloud template from source control, use this procedure to learn how. It shows you how to create a cloud template for a WordPress application, and trigger it from an on-premises GitHub repository. Whenever you make a change to the YAML cloud template, the pipeline triggers and automates the release of your application.

  • In Cloud Assembly, you'll add a cloud account, add a cloud zone, and create the cloud template.
  • In Code Stream, you'll add an endpoint for the on-premises GitHub repository that hosts your cloud template. Then, you'll add the cloud template to your pipeline.

This use case example shows you how to use a cloud template from an on-premises GitHub repository.

The workflow helps you navigate the process that automates the release of an application that you deploy from a YAML cloud template.

Prerequisites

  • Add a cloud account and a cloud zone in your vRealize Automation Cloud Assembly infrastructure. See the vRealize Automation Cloud Assembly documentation.
  • To create your cloud template in the following procedure, copy the WordPress YAML code to your clipboard. See the cloud template YAML code in the WordPress use case in the vRealize Automation Cloud Assembly documentation.
  • Add the YAML code for the WordPress application to your GitHub instance.
  • Add a webhook for the Git trigger so that your pipeline can pull your YAML code whenever you commit changes to it. In Code Stream, click Triggers > Git > Webhooks for Git.
  • To work with a cloud template task, you must have any of the Cloud Assembly roles.

Procedure

  1. In Cloud Assembly, follow these steps.
    1. Click VMware Cloud Templates, then create a cloud template and a deployment for the WordPress application.
    2. Paste the WordPress YAML code that you copied to your clipboard into your cloud template, and deploy it.
      By using the YAML code, the cloud template creates the database tier, web tier, and network in your deployment.
  2. In Code Stream, create endpoints.
    1. Create a Git endpoint for your on-premises GitHub repository where your YAML file resides.
    2. Add an Email endpoint that can notify users about the pipeline status when it runs.
      When you add an Email endpoint, you set the encryption method and set the outbound protocol.
  3. Create a pipeline, and add notifications for pipeline success and failure.
    When you add an email notification, you select one of the pipeline states, and select the Email server and recipients.
  4. Add a stage for development, and add a cloud template task.
    1. Add a cloud template task that deploys the machine, and configure the task to use the cloud template YAML for the WordPress application.
      resources:
        DBTier:    
          type: Cloud.Machine    
          properties:      
              name: mysql      
              image: 'ubuntu-16'      
              flavor: 'small'      
              constraints:        
                  -   tag: zone:dev
        WebTier:
          type: Cloud.Machine    
          properties:     
              name: wordpress      
              image: 'ubuntu-16'      
              flavor: 'small'      
              constraints:        
                  - tag: zone:dev
       WP-Network-Private:
          type: Cloud.Network
          properties:
              name: WP-Network-Private
              networkType: existing
              constraints:
                  - tag: 'type:isolated-net'
                  - tag: 'zone:dev'
    2. Add a cloud template task that destroys the machine to free up resources.
  5. Add a stage for production, and include approval and deployment tasks.
    1. Add a User Operation task to require approval to push the WordPress application to production.
    2. Add a cloud template task to deploy the machine and configure it with the cloud template YAML for the WordPress application.
      When you select Create, the deployment name must be unique. If you leave the name blank, Code Stream assigns it a unique random name.
      Here's what you must know if you select Rollback in your own use case: If you select the Rollback action and enter a Rollback Version, the version must be in the form of n-X. For example, n-1, n-2, n-3, and so on. If you create and update the deployment in any location other than Code Stream, rollback is allowed.
      When you log in to Code Stream, it gets a user token, which is valid for 30 minutes. For long-running pipeline durations, when the task prior to the cloud template task takes 30 minutes or more to run, the user token expires. As a result, the cloud template task fails.
      To ensure that your pipeline can run longer than 30 minutes, you can enter an optional API token. When Code Stream invokes the cloud template, the API token persists and the cloud template task continues to use the API token.
      When you use the API token as a variable, it is encrypted. Otherwise, it is used as plain text.
      The cloud template task can use a VMware cloud template in Cloud Assembly or pull one from source control in a GitLab repository or a GitHub repository.
  6. Run the pipeline.

    To verify that each task completed successfully, click the task in the execution, and examine the status in the deployment details to see detailed resource information.

  7. In GitHub, modify the flavor of the WordPress server instance from small to medium.
    When you commit changes, the pipeline triggers. It pulls your updated code from the GitHub repository and builds your application.
    WebTier:
        type: Cloud.Machine    
        properties:     
            name: wordpress      
            image: 'ubuntu-16'      
            flavor: 'medium'      
            constraints:        
                - tag: zone:dev
  8. Run the pipeline again, verify that it succeeded, and that it changed the flavor of the WordPress instance from small to medium.

Results

Congratulations! You automated the release of your application that you deployed from a YAML cloud template.

What to do next

To learn more about how you can use Code Stream, see Tutorials for using Code Stream.

For additional references, see More resources for Code Stream Administrators and Developers.