设计与多媒体

Huawei Cloud Swr Image Automation

试用

在华为云 SWR 上配置跨区域镜像同步和触发器,让镜像推送自动变成 CCE/CCI 部署更新。

它能做什么

围绕 hcloud CLI(>= 7.2.2)封装华为云 SWR 的镜像自动化流程,覆盖跨区域自动同步配置、按 tag 的手动同步、可用目标同步区域查询、同步任务状态查询,以及把镜像推送自动触发 CCE 或 CCI 工作负载更新的触发器全生命周期管理。认证使用 AK/SK,通过 HUAWEI_CLOUD_AK 与 HUAWEI_CLOUD_SK 环境变量提供,并需要清单中列出的 SWR IAM 权限。

什么时候用它

  • 在镜像推送时自动复制到另一个区域
  • 按需把指定 tag 的镜像同步到目标区域
  • 把 SWR 推送事件接到 CCE 部署更新上
  • 调试发布时临时禁用某个触发器

技能文档

Huawei Cloud SWR Image Automation

Overview

This skill provides image automation capabilities for Huawei Cloud SWR (Software Repository for Container) using the hcloud CLI, including cross-region image sync and trigger-based auto-deployment.

Architecture: hcloud CLI → SWR Service API → SyncRepo/Trigger/SyncJob/SyncRegion resources

Related Skills:

  • huawei-cloud-swr-image-management - Image lifecycle management (namespaces, repos, tags, auth, quotas)

  • huawei-cloud-swr-image-governance - Image governance (permissions, retention, sharing, tags, immutable rules)

  • huawei-cloud-swr-enterprise-instance - Enterprise instance management

  • Configure auto-sync to replicate images across regions on push

  • Manually sync specific image tags to target regions

  • List available sync target regions

  • Check sync job execution status

  • Create and manage triggers for auto-deploy to CCE/CCI workloads

  • Enable/disable triggers and update trigger configurations

Typical Use Cases:

  • "Set up auto-sync for my image repository to cn-east-3"
  • "Manually sync image tags v1.0 and v2.0 to another region"
  • "List available regions for image sync"
  • "Check the status of my image sync job"
  • "Create a trigger to auto-update my CCE deployment when a new image is pushed"
  • "List all triggers for a repository"
  • "Disable a trigger temporarily"
  • "Delete an old trigger configuration"
  • "Configure image replication across multiple regions"

Prerequisites

1. hcloud CLI Requirements (MANDATORY)

  • hcloud CLI installed (version >= 7.2.2)
  • Run hcloud version to verify installation
  • First-time usage: printf "y\n" | hcloud version to accept privacy statement

2. Credential Configuration

  • Valid Huawei Cloud credentials (AK/SK mode)
  • Security Rules:
    • 🚫 Never expose AK/SK values in code, conversation, or commands
    • 🚫 Never use echo $HUAWEI_CLOUD_AK or echo $HUAWEI_CLOUD_SK to check credentials
    • ✅ Use environment variables: HUAWEI_CLOUD_AK, HUAWEI_CLOUD_SK, HUAWEI_CLOUD_REGION
    • ✅ Prefer IAM users over root account for cloud operations
    • ✅ Enable MFA for sensitive operations

Configuration Method (Environment Variables Only):

export HUAWEI_CLOUD_AK=
export HUAWEI_CLOUD_SK=
export HUAWEI_CLOUD_REGION=cn-north-4

⚠️ Important Security Notes:

  • Never commit credentials to version control
  • Use IAM users with minimal required permissions
  • Enable MFA for sensitive operations
  • Rotate AK/SK regularly

3. IAM Permission Requirements

API ActionPermissionPurpose
swr:sync:createCreate sync repoConfigure cross-region image sync
swr:sync:deleteDelete sync repoRemove sync configuration
swr:sync:listList sync reposQuery auto-sync configurations
swr:syncmanual:createManual syncTrigger manual image sync
swr:syncregion:listList sync regionsQuery available sync target regions
swr:syncjob:getGet sync job statusCheck sync execution status
swr:trigger:createCreate triggerSet up auto-deploy trigger
swr:trigger:listList triggersQuery trigger configurations
swr:trigger:getGet triggerView specific trigger details
swr:trigger:updateUpdate triggerModify trigger configuration
swr:trigger:deleteDelete triggerRemove trigger configuration

See IAM Permission Policies for complete policy JSON.

Permission Failure Handling:

  1. When any command fails due to permission errors, read references/iam-policies.md
  2. Display the required permission list and policy JSON to the user
  3. Guide the user to create a custom policy in the IAM console and grant authorization
  4. Pause execution and wait for user confirmation that permissions have been granted

Core Commands

1. Auto Sync (Cross-region Image Replication)

See Task: Image Sync for detailed workflows.

# List available sync target regions
hcloud SWR ListSyncRegions --cli-region=cn-north-4

# Configure auto-sync for a repository to target region
hcloud SWR CreateImageSyncRepo --namespace=group-dev --repository=my-app --remoteRegionId=cn-east-3 --remoteNamespace=group-dev --override=false --syncAuto=true --cli-region=cn-north-4

# List auto-sync configurations for a repository
hcloud SWR ListImageAutoSyncReposDetails --namespace=group-dev --repository=my-app --cli-region=cn-north-4

# Delete auto-sync configuration
hcloud SWR DeleteImageSyncRepo --namespace=group-dev --repository=my-app --remoteRegionId=cn-east-3 --remoteNamespace=group-dev --cli-region=cn-north-4

Auto Sync Behavior: When syncAuto=true, every new image push to the source repository automatically triggers a sync to the target region. When syncAuto=false, sync only occurs on manual trigger.

2. Manual Sync

# Manually sync specific image tags to target region
hcloud SWR CreateManualImageSyncRepo --namespace=group-dev --repository=my-app --remoteRegionId=cn-east-3 --remoteNamespace=group-dev --imageTag.1=v1.0 --imageTag.2=v2.0 --override=false --cli-region=cn-north-4

⚠️ Important: --imageTag uses indexed array format, NOT plain value format:

  • ✅ CORRECT: --imageTag.1=v1.0 --imageTag.2=v2.0
  • ❌ WRONG: --imageTag=v1.0 (missing index)
  • ❌ WRONG: --imageTag=v1.0,v2.0 (comma-separated not supported)

3. Sync Regions

# List all regions available as sync targets
hcloud SWR ListSyncRegions --cli-region=cn-north-4

Response Format (verified against actual API):

[
  {
    "regionID": "cn-north-4"
  }

Returns all regions where you can sync images. Use the regionID field value as the --remoteRegionId parameter.

4. Sync Job Status

# Check sync job status
hcloud SWR ShowSyncJob --namespace=group-dev --repository=my-app --cli-region=cn-north-4

Response format to be verified. Use --help for parameter details.

5. Trigger Management (Auto-deploy to CCE/CCI)

See Task: Trigger Management for detailed workflows.

# Create a trigger for auto-deploy to CCE
hcloud SWR CreateTrigger --namespace=group-dev --repository=my-app --name=deploy-trigger --trigger_type=all --condition=".*" --action=update --app_type=deployments --application=my-deployment --cluster_ns=default --enable=true --trigger_mode=cce --cluster_id= --cluster_name= --cli-region=cn-north-4

# List all triggers for a repository
hcloud SWR ListTriggersDetails --namespace=group-dev --repository=my-app --cli-region=cn-north-4

# Show trigger details
hcloud SWR ShowTrigger --namespace=group-dev --repository=my-app --trigger=deploy-trigger --cli-region=cn-north-4

# Update a trigger (enable/disable or modify configuration)
hcloud SWR UpdateTrigger --namespace=group-dev --repository=my-app --trigger=deploy-trigger --enable=false --cli-region=cn-north-4

# Delete a trigger
hcloud SWR DeleteTrigger --namespace=group-dev --repository=my-app --trigger=deploy-trigger --cli-region=cn-north-4

Trigger Types:

  • all: Trigger on any image push (condition=".*")
  • tag: Trigger on specific tag push (condition=tag-name)
  • regular: Trigger on tag matching regex (condition=regex-pattern)

Trigger Modes:

  • cce: Deploy to CCE (Cloud Container Engine) cluster — requires --cluster_id
  • cci: Deploy to CCI (Cloud Container Instance) — no cluster ID needed

Parameter Reference

Common Parameters

ParameterRequired/OptionalDescriptionDefault
--cli-regionRequiredHuawei Cloud region IDConfig value or HUAWEI_CLOUD_REGION
--namespaceContext-dependentSWR namespace (organization)N/A
--repositoryContext-dependentImage repository nameN/A

Auto Sync Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesSource namespaceExisting namespace name
--repositoryYesSource repositoryExisting repository name
--remoteRegionIdYesTarget region IDMust be from ListSyncRegions result
--remoteNamespaceYesTarget namespaceNamespace name in target region
--overrideNoOverwrite existing imagestrue or false (default false)
--syncAutoNoAuto sync on pushtrue or false (default false)

Manual Sync Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesSource namespaceExisting namespace name
--repositoryYesSource repositoryExisting repository name
--remoteRegionIdYesTarget region IDMust be from ListSyncRegions result
--remoteNamespaceYesTarget namespaceNamespace name in target region
--imageTag.[N]YesTag list (indexed array)--imageTag.1=v1.0 --imageTag.2=v2.0
--overrideNoOverwrite existing imagestrue or false (default false)

Trigger Parameters

ParameterRequiredDescriptionConstraints
--namespaceYesSWR namespaceExisting namespace name
--repositoryYesImage repositoryExisting repository name
--nameYesTrigger nameUnique within repository
--trigger_typeYesTrigger typeall, tag, regular
--conditionYesMatch condition.* for all, tag name for tag, regex for regular
--actionYesTrigger actionupdate
--app_typeYesApplication typedeployments or statefulsets
--applicationYesCCE/CCI application nameExisting deployment name
--cluster_nsYesApplication namespaceKubernetes namespace (e.g., default)
--enableYesEnable triggertrue or false
--trigger_modeNoDeploy targetcce (default) or cci
--cluster_idCCE onlyCCE cluster IDRequired for cce mode, empty for cci
--cluster_nameNoCCE cluster nameOptional cluster name
--containerNoTarget containerSpecific container name (default: all)

Output Format

ListSyncRegions (verified)

Response is a flat JSON array of region objects:

[
  {
    "regionID": "cn-north-4",
    "region_name": "north-1"
  }
]

Note: Returns all available sync target regions. Use region_id as --remoteRegionId.

ListImageAutoSyncReposDetails

Response format to be verified — returns list of sync repo configurations when they exist. Returns empty when no auto sync configured.

ListTriggersDetails

Response format to be verified — returns list of trigger objects when they exist. Returns empty when no triggers configured.

ShowTrigger

Response format to be verified. Use --namespace, --repository, --trigger (trigger name) as parameters.

ShowSyncJob

Response format to be verified. Use --namespace, --repository as primary parameters.

Verification

See Verification Method for step-by-step verification.

Common Region IDs

Region NameRegion ID
North China - Beijing 4cn-north-4
North China - Beijing 1cn-north-1
East China - Shanghai 1cn-east-3
East China - Shanghai 2cn-east-2
South China - Guangzhoucn-south-1
South China - Shenzhencn-south-4
Southwest China - Guiyang 1cn-southwest-2
Asia Pacific - Bangkokap-southeast-2
Asia Pacific - Singaporeap-southeast-1
Asia Pacific - Hong Kongap-southeast-3
Europe - Pariseu-west-0

Best Practices

  1. Auto-sync for production repos: Set syncAuto=true for production repositories to ensure images are automatically replicated to target regions
  2. Manual sync for selective replication: Use CreateManualImageSyncRepo when you only need to sync specific tags (e.g., production releases)
  3. Override caution: Only set override=true when you intentionally want to overwrite existing images in the target region
  4. Trigger naming: Use descriptive trigger names (e.g., prod-deploy-trigger, staging-update-trigger)
  5. Trigger condition design: Use trigger_type=regular with regex for flexible matching (e.g., v\d+\.\d+\.\d+ for semver tags)
  6. Disable before delete: Disable a trigger (enable=false) before deleting to avoid unintended deployments during cleanup
  7. Verify target namespace: Ensure the target namespace exists in the target region before creating sync configurations
  8. Regional namespace alignment: Use identical namespace names across regions for easier cross-region management
  9. Check sync regions first: Always run ListSyncRegions before creating sync configurations to verify the target region is available

Reference Documents

DocumentDescription
SWR Automation API Guidehcloud SWR automation API reference
IAM Permission PoliciesRequired permissions and policy JSON
Verification MethodStep-by-step verification
Common PitfallsTroubleshooting guides
Task: Image SyncAuto/manual sync workflows
Task: Trigger ManagementTrigger workflows

Notes

  • Auto-sync is persistent — once configured, it automatically triggers on every new push until deleted
  • Manual sync is one-time — each CreateManualImageSyncRepo invocation syncs specified tags once
  • --imageTag.[N] uses indexed array format — NOT plain value or comma-separated
  • Sync target namespace must exist — create the namespace in the target region before syncing
  • AK/SK must never be hardcoded — credentials should only be obtained via environment variables
  • hcloud CLI is the only supported method — all operations use hcloud SWR format
  • Trigger requires CCE/CCI cluster — triggers only work with existing CCE clusters or CCI instances
  • Response formats pending verification — ListImageAutoSyncReposDetails, ListTriggersDetails, ShowTrigger, ShowSyncJob response formats need live verification

Common Pitfalls

See Common Pitfalls & Solutions for detailed troubleshooting guides.

Quick Reference:

PitfallSymptomQuick Fix
--imageTag wrong formatManual sync failsUse indexed: --imageTag.1=v1.0
Target namespace missingSync creation failsCreate namespace in target region first
Invalid remoteRegionIdSync creation failsCheck with ListSyncRegions
CCE cluster not foundTrigger creation failsVerify cluster_id with CCE console
Trigger already exists409 ConflictUse ShowTrigger to check first
Auto-sync unwantedImages sync unexpectedlySet syncAuto=false or delete sync config

常见问题

需要什么环境和凭证?
hcloud CLI >= 7.2.2,凭证只能通过 HUAWEI_CLOUD_AK 和 HUAWEI_CLOUD_SK 环境变量提供,AK/SK 明文不能出现在命令或对话里。
能同时覆盖 CCE 和 CCI 的自动部署吗?
可以。触发器支持 trigger_mode=cce(需要传 --cluster_id)和 trigger_mode=cci(不需要 cluster_id)两种模式,触发类型包括 all、tag、regular。
怎么查到哪些区域可以作为同步目标?
执行 `hcloud SWR ListSyncRegions --cli-region=<区域>`,返回结果里的 regionID 就是同步命令中 --remoteRegionId 可用的值。

相关技能

通过 hcloud CLI 管理华为云 SWR 命名空间、镜像仓库、版本标签、登录凭证与配额。

作者 shijingcheng3 次安装1 星标

通过 hcloud CLI 管理华为云 SWR 镜像权限、保留规则、共享下载域名与委托关系。

作者 shijingcheng3 次安装1 星标

Query the list of Huawei Cloud SWR (Software Repository for Container) image repositories under the current project/region. Lists all image repositories with their name, namespace, category, visibility (public/private), image/tag count, size, download count, full image path, tags and timestamps. Supports optional filtering by namespace, repository name (fuzzy match), category, and pagination (limit/offset) with sorting for account-wide repository inventory. Use when the user wants to: (1) list all Huawei Cloud SWR image repositories / 查询华为云SWR镜像仓库列表, (2) check how many image repositories exist in the account or region, (3) inspect repository visibility, size, tag count, or path for daily inspection or troubleshooting, (4) filter repositories by namespace, name, or category, (5) page through or sort repository results. Triggers include: "SWR列表", "华为云SWR列表", "查询SWR列表", "SWR镜像仓库列表", "容器镜像仓库列表", "SWR repository list", "list SWR repos", "ListReposDetails", "SWR仓库查询", "查看SWR仓库", "镜像仓库列表"

1 次安装

Huawei Cloud SWR enterprise instance lifecycle management via hcloud CLI. Trigger: "SWR enterprise instance", "SWR 企业实例", "SWR 企业版", "企业仓库实例", "swr.ee", "实例管理

作者 shijingcheng3 次安装1 星标

Query the list of Huawei Cloud SWR (Software Repository for Container) namespaces (organizations) under the current project/region. Lists all namespaces with their ID, name, creator, auth level, access user count and repository count. Supports optional filtering by namespace name. This is the top-level resource listing for SWR — namespaces organize image repositories into groups. Use when the user wants to: (1) list all Huawei Cloud SWR namespaces / 查询华为云SWR组织列表, (2) check how many SWR organizations exist in the account or region, (3) inspect namespace auth level, repository count, or creator for daily inspection or troubleshooting, (4) filter namespaces by name. Triggers include: "SWR组织列表", "华为云SWR组织列表", "查询SWR组织", "SWR namespace list", "list SWR namespaces", "ListNamespaces", "SWR命名空间列表", "查看SWR组织", "SWR名称列表"

1 次安装

Provides guidance for Huawei Cloud KooCLI command-line tool operations. Covers KooCLI installation, IAM authentication configuration, access credential confi...

作者 huaweicloud-skills-team1 次安装

shijingcheng 的更多技能

浏览全部技能

通过 Python SDK 管理华为云 CCE 集群、节点池、节点和插件的全生命周期,危险操作需 confirm=true。

作者 shijingcheng4 次安装1 星标

查询华为云 CCE 集群 Pod/Node 指标及 ECS、ELB、EIP、NAT 资源指标,支持基于阈值的异常检测。

作者 shijingcheng4 次安装1 星标

通过 hcloud CLI 管理华为云 SWR 命名空间、镜像仓库、版本标签、登录凭证与配额。

作者 shijingcheng3 次安装1 星标

通过 hcloud CLI 管理华为云 SWR 镜像权限、保留规则、共享下载域名与委托关系。

作者 shijingcheng3 次安装1 星标

通过 hcloud CLI 全生命周期管理华为云 CCI 容器实例:命名空间、网络、工作负载、日志查询,并内置安全确认机制。

作者 shijingcheng3 次安装1 星标