Halaman ini belum tersedia dalam bahasa lokal Anda. Kami berusaha keras untuk menambahkan lebih banyak versi bahasa. Terima kasih atas dukungan Anda.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ CodeArts Artifact/ Best Practices/ Releasing/Obtaining a Go Component via a Build Task

Releasing/Obtaining a Go Component via a Build Task

Updated on 2025-02-07 GMT+08:00

This section describes how to release a component to a Go repository via a build task and obtain a dependency from the repository for deployment.

Prerequisites

Releasing a Component to a Go Repository

  1. Download the configuration file.

    1. Log in to CodeArts Artifact and access the Go repository. Click Tutorial on the right of the page.
    2. In the displayed dialog box, click Download Configuration File.

  2. Configure a repository.

    1. Go to Repo. Create a Go repository. For details, see Creating a Repository This procedure uses the Go web Demo template.
    2. Prepare the go.mod and upload it to the root directory of the repository. For details, see Uploading Code Files to CodeArts Repo The following figure shows the go.mod file used in this example.

  3. Configure and run a build task.

    1. On the Repo page, select a repository and click Create Build Task in the upper right.

      Select Blank Template and click OK.

    2. Add the Build with Go action.

    3. Edit the Build with Go action.
      • Select the desired tool version. In this example, go-1.13.1 is used.
      • Delete the existing commands, open the configuration file downloaded in 1, and copy the commands for configuring Go environment variables in Linux to the command box.
      • Copy the Go upload command segment in the configuration file to the command box, and replace the parameters in the commands by referring to Go Module Packaging. (In this example, the package version is v1.0.0.)
    4. Click Save and Run on the right of the page to start the build task.

      When the message build successful is displayed, go to the self-hosted repo page and find the uploaded Go component.

Obtaining a Dependency from a Go Repository

The following procedure uses the Go component released in Releasing a Component to a Go Repository as an example to describe how to obtain a dependency from a Go repository.

  1. Download the configuration file by referring to Releasing a Component to a Go Repository.
  2. Go to Repo and create a Go repository. For details, see Creating a Repository. This procedure uses the Go web Demo template.
  3. Configure and run a build task.

    1. On the Repo page, select a repository and click Create Build Task in the upper right.

      Select Blank Template and click OK.

    2. Add the Build with Go action.
    3. Edit the Build with Go action.
      • Select the desired tool version. In this example, go-1.13.1 is used.
      • Delete the existing commands, open the downloaded configuration file, and copy the commands for configuring Go environment variables in Linux to the command box.
      • Copy the Go download commands in the configuration file to the command box and replace the <modulename> parameter with the actual value. (In this example, the parameter is set to example.com/demo).

  4. Click Save and Run on the right of the page to start the build task.

    When a message build successful is displayed, view the task details. If information similar to the following is found in the log, the dependency has been downloaded from the self-hosted repo.

Go Module Packaging

This section describes how to build and upload Go components through Go module packaging.

Perform the following steps:

  1. Create a source folder in the working directory.
    mkdir -p {module}@{version}
  2. Copy the code source to the source folder.
    cp -rf . {module}@{version}
  3. Compress the component into a ZIP package.
    zip -D -r [package name] [package root directory]
  4. Upload the component ZIP package and the go.mod file to the self-hosted repo.
    curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/{filePath} -T {{localFile}}

The component directory varies according to the package version. The version can be:

  • Versions earlier than v2.0: The directory is the same as the path of the go.mod file. No special directory structure is required.
  • v2.0 or later:
    • If the first line in the go.mod file ends with /vX, the directory must contain /vX. For example, if the version is v2.0.1, the directory must contain v2.
    • If the first line in the go.mod file does not end with /vN, the directory remains unchanged and the name of the file to be uploaded must contain +incompatible.

The following are examples of component directories for different versions:

  • Versions earlier than v2.0

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.
      The value of module is example.com/demo and that of version is 1.0.0. The command is as follows:
      mkdir -p ~/example.com/demo@v1.0.0
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command):

      cp -rf . ~/example.com/demo@v1.0.0/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v1.0.0.zip. The command is as follows:

      zip -D -r v1.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v1.0.0.zip and that of localFile is v1.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v1.0.0.mod and that of localFile is example.com/demo@v1.0.0/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values):

      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.zip -T v1.0.0.zip
      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.mod -T example.com/demo@v1.0.0/go.mod
  • v2.0 and later, with the first line in go.mod ending with /vX

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.
      The value of module is example.com/demo/v2 and that of version is 2.0.0. The command is as follows:
      mkdir -p ~/example.com/demo/v2@v2.0.0
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command):

      cp -rf . ~/example.com/demo/v2@v2.0.0/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v2.0.0.zip. The command is as follows:

      zip -D -r v2.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/v2/@v/v2.0.0.zip and that of localFile is v2.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/v2/@v/v2.0.0.mod and that of localFile is example.com/demo/v2@v2.0.0/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values):

      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.zip -T v2.0.0.zip
      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.mod -T example.com/demo/v2@v2.0.0/go.mod
  • v2.0 and later, with the first line in go.mod not ending with /vX

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.
      The value of module is example.com/demo and that of version is 3.0.0. The command is as follows:
      mkdir -p ~/example.com/demo@v3.0.0+incompatible
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command):

      cp -rf . ~/example.com/demo@v3.0.0+incompatible/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v3.0.0.zip. The command is as follows:

      zip -D -r v3.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.zip and that of localFile is v3.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.mod and that of localFile is example.com/demo@v3.0.0+incompatible/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values):

      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.zip -T v3.0.0.zip
      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.mod -T example.com/demo@v3.0.0+incompatible/go.mod

Kami menggunakan cookie untuk meningkatkan kualitas situs kami dan pengalaman Anda. Dengan melanjutkan penelusuran di situs kami berarti Anda menerima kebijakan cookie kami. Cari tahu selengkapnya

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback