Distributed Cloud Container Platform for Kubernetes (ACK One) workflow clusters are developed based on open source Argo Workflows. With the benefits of ultrahigh elasticity, auto scaling, and zero O&M costs, hosted Argo Workflows can help you quickly create Continuous Integration (CI) pipelines with low costs. This topic describes how to create CI pipelines for Golang projects in workflow clusters.
Introduction
To create CI pipelines in ACK One workflow clusters, use BuildKit to build and push container images and use BuildKit Cache to accelerate image building. Using File Storage NAS (NAS) to store the Go mod cache can accelerate the Go Test
and Go Build
steps. This greatly reduces the time required for creating CI pipelines.
Introduction to the predefined ClusterWorkflowTemplate
By default, workflow clusters provide a predefined ClusterWorkflowTemplate named ci-go-v1
. The template uses BuildKit Cache and NAS to store the Go mod cache, which greatly accelerates CI pipeline creation.
You can directly use the predefined template or create a custom template based on the predefined template.
The predefined template consists of the following steps:
Git Clone & Checkout
Clone the Git repository and check out the Git repository to the destination branch.
Obtain the commit ID, which is appended as a suffix to the image tag during image building.
Run Go Test
Run all test cases (Go projects) in the Git repository by default.
You can set the pipeline parameter
enable_test
to specify whether to perform this step.The Go mod cache is stored in the
/pkg/mod
directory of the NAS file system to accelerateGo Test
andGo Build
.
Build & Push Image
Use BuildKit to build and push container images, and use caches of the registry type in BuildKit Cache to accelerate image building.
By default, the image tag is in the
{container_tag}-{commit_id}
format. You can specify whether to append the commit ID to the image tag when you submit the pipeline.During image pushing, the latest version of the image is pushed to overwrite the current version.
Content of the predefined template:
The following table describes the parameters in the template.
Parameter | Description | Example |
entrypoint | Specify the entry template. | main |
repo_url | The URL of the Git repository. | https://github.com/ivan-cai/echo-server.git |
repo_name | The name of the repository. | echo-server |
target_branch | The destination branch of the repository. Default value: main. | main |
container_image | The image to be built. Format: <ACR EE Domain>/<ACR EE Namespace>/<Repository Name>. | test-registry.cn-hongkong.cr.aliyuncs.com/acs/echo-server |
container_tag | The image tag. Default: v1.0.0. | v1.0.0 |
dockerfile | The directory and name of the Dockerfile. Specify the relative path in the root directory. Default: |
|
enable_suffix_commitid | Specify whether to append the commit ID to the image tag. Valid values:
Default value: true. | true |
enable_test | Specify whether to run the Go Test step. Valid values:
Default value: true. | true |
Prerequisites
A Kubernetes cluster for distributed Argo workflows is created.
The kubeconfig file of the workflow cluster is obtained in the ACK One console and a kubectl client is connected to the workflow cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
A Container Registry Enterprise Edition instance is created.
Procedure
A public Git repository is used as an example to demonstrate how to create a CI pipeline. If you use a private Git repository, you need to first clone the private repository in the CI pipeline.
The Secret that stores the credentials for accessing the container image and the NAS volume must belong to the namespace of the pipeline to be submitted.
Step 1: Create credentials in the workflow cluster to access the Container Registry Enterprise Edition instance
The credentials are used to pull images from BuildKit.
Configure access credentials for the Container Registry Enterprise Edition instance. For more information, see Configure access credentials for a Container Registry Enterprise Edition instance.
Run the following command to create a Secret in the workflow cluster to store the credentials. The credentials will be used by BuildKit.
Replace
$username:$password
with the credentials used to access the Container Registry Enterprise Edition instance.kubectl create secret generic docker-config --from-literal="config.json={\"auths\": {\"$repositoryDomain\": {\"auth\": \"$(echo -n $username:$password|base64)\"}}}"
Step 2: Mount the NAS volume to the workflow cluster
The NAS volume is used to meet the following requirements:
Share data among tasks of the pipeline, such as information about the cloned repository.
Store the Go mod cache, which is used to accelerate the
Go Test
andGo Build
steps in the CI pipeline.
Perform the following steps to mount the NAS volume to the workflow cluster:
Obtain the mount target of the NAS file system. For more information, see Manage mount targets.
Create a persistent volume (PV) and persistent volume claim (PVC) in the workflow cluster based on the following template. For more information, see Use NAS volumes.
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nas labels: alicloud-pvname: pv-nas spec: capacity: storage: 100Gi accessModes: - ReadWriteMany csi: driver: nasplugin.csi.alibabacloud.com volumeHandle: pv-nas # Specify the name of the PV. volumeAttributes: server: <your nas filesystem mount point address> path: "/" mountOptions: - nolock,tcp,noresvport - vers=3 --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi selector: matchLabels: alicloud-pvname: pv-nas
Step 3: Launch a pipeline based on the predefined template
Submit a pipeline in the console
Log on to the ACK One console. In the left-side navigation pane, choose .
On the Cluster Information page, click the Basic Information tab. In the Common Operations section, click Workflow Console (Argo).
In the Argo workbench, click Cluster Workflow Templates in the left-side navigation pane and click the predefined template named ci-go-v1.
On the template details page, click + SUBMIT in the upper-right corner. In the panel that appears, configure the parameters and click + SUBMIT.
Refer to Template parameters and configure the parameters.
After you complete the configuration, you can view the status of the pipeline on the Workflows details page.
Use the Argo CLI to submit a pipeline
Create a file named
workflow.yaml
and copy the following content to the file. Refer to Template parameters and configure the parameters.apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: ci-go-v1- labels: workflows.argoproj.io/workflow-template: ackone-ci spec: arguments: parameters: - name: repo_url value: https://github.com/ivan-cai/echo-server.git - name: repo_name value: echo-server - name: target_branch value: main - name: container_image value: "test-registry.cn-hongkong.cr.aliyuncs.com/acs/echo-server" - name: container_tag value: "v1.0.0" - name: dockerfile value: ./Dockerfile - name: enable_suffix_commitid value: "true" - name: enable_test value: "true" workflowTemplateRef: name: ci-go-v1 clusterScope: true
Run the following command to submit a pipeline:
argo submit workflow.yaml