Workflow clusters are a fully managed Argo Workflows service built on the open-source Argo Workflows project, offering elastic scaling and zero O&M overhead for simpler, lower-cost, high-efficiency CI pipelines. This topic describes how to build a Golang CI pipeline on a workflow cluster using BuildKit caching and NAS-stored Go module cache.workflow cluster with BuildKit caching and NAS-stored Go module cache.
Solution overview
On a workflow cluster, the pipeline uses BuildKit to build and push container images, BuildKit Cache to accelerate builds, and NAS-stored Go mod cache to speed up go test and go build.
Preset workflow template
A workflow cluster includes a preset CI workflow template (ClusterWorkflowTemplate) named ci-go-v1 that uses BuildKit Cache and NAS-stored Go mod cache to accelerate the CI pipeline.
Use the preset template directly or customize it for your CI workflow.
The preset template includes these steps:
-
Git clone & checkout
-
Clones a Git repository and checks out the target branch.
-
Retrieves the commit ID and appends it to the image tag.
-
-
Run go test
-
Runs all test cases in the Go project by default.
-
Use
enable_testto control whether to run this step. -
Stores the Go mod cache in
/pkg/modon NAS to acceleratego testandgo build.
-
-
Build & push image
-
Builds and pushes the container image with BuildKit, using a registry-type cache to accelerate builds.
-
Default image tag format:
{container_tag}-{commit_id}. A workflow parameter controls whether to append the commit ID. -
Also pushes a
latest-tagged image, overwriting the previous one.
-
Prerequisites
Step 1: Create a Container Registry access credential
-
Obtain the kubeconfig file for the cluster and use kubectl to connect to the cluster.
-
Configure the access credential for the ACR EE instance. For Virtual Private Cloud (VPC) domain access, ensure the cluster and the registry are in the same VPC. For public domain access, configure public access control.
-
Replace
USER_NAME:PASSWORDwith your ACR EE access credential and run the command to create a Secret in the workflow cluster for BuildKit.The Secret and NAS volume must be in the same namespace as the workflow you submit.
kubectl create secret generic docker-config --from-literal="config.json={\"auths\": {\"$repositoryDomain\": {\"auth\": \"$(echo -n USER_NAME:PASSWORD|base64)\"}}}"
Step 2: Mount a NAS volume
A NAS volume shares data between workflow tasks, such as cloned repository data, and stores the Go mod cache to accelerate go test and go build.
-
Log on to the NAS console.
-
In the left-side navigation pane, choose .
In the top navigation bar, select the resource group and region where your file system resides.
-
On the File System List page, find the target file system and click Manage in the Actions column.
-
On the file system details page, click the Mount Targets tab. In the Mount Target section, record the NAS mount point.
-
Save the following YAML as pv-nas.yaml, replace MOUNT_POINT with your NAS mount point, and run
kubectl apply -f pv-nas.yamlto create the volume.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 # Must be the same as the PV name. volumeAttributes: server: MOUNT_POINT 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: Start a workflow
Console
Log on to the Argo Workflow Clusters console.
-
On the Cluster Information page, click the Basic Information tab. In the Common Operations section, click Workflow Console (Argo).
-
In the left-side navigation pane of the Argo UI, click Cluster Workflow Templates, then click ci-go-v1.
-
On the template details page, click + SUBMIT. Enter the required parameters in the panel and click + SUBMIT.
Set parameters based on the parameter description.
In the Submit Workflow panel, set Entrypoint to
mainand specify the following parameters:-
repo_url: the URL of the Git repository, for example
https://github.com/ivan-cai/echo-server.git. -
repo_name: the repository name, for example
echo-server. -
target_branch: the target branch, for example
main. -
container_image: the URL of the container image.
-
container_tag: the image tag, for example
v1.0.0. -
dockerfile: the path to the Dockerfile, for example
./Dockerfile. -
enable_suffix_commitid: whether to append the commit ID to the image tag, for example
true. -
enable_test: whether to run the test step, for example
true.
After you specify the parameters, click +SUBMIT at the bottom of the panel to submit the workflow.
After submission, view the workflow status on the Workflows page:
After the workflow is submitted, the workflow DAG is displayed on the Workflows details page. The step nodes from top to bottom are git-checkout-pr, run-test, and build-push-image. A green checkmark on every node indicates that the workflow succeeded.
-
Argo CLI
-
Update parameter values based on the parameter description. Save the following YAML as
workflow.yaml, then runargo submit workflow.yamlto submit the workflow.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