Skip to content

Commit

Permalink
feat: release products use retag image registry
Browse files Browse the repository at this point in the history
  • Loading branch information
CeerDecyProMax authored and CeerDecy committed Nov 22, 2023
1 parent 7cd9e5b commit 8398288
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion actions/release/1.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ release action 运行成功后会在当前目录生成 `dicehub-release` 文件
- ${bp-web}/pack-result
```
#### 对服务镜像进行retag并推送
#### 对服务镜像进行retag并推送;默认开启“制品镜像选用retag中的镜像地址”,可以通过`useRetagImage`标识是否开启该功能

```yaml
- stage:
- release:
Expand All @@ -338,4 +339,6 @@ release action 运行成功后会在当前目录生成 `dicehub-release` 文件
registryUsername: ${{ secrets.REGISTRY_USERNAME }}
# 远端镜像仓库的密码
registryPassword: ${{ secrets.REGISTRY_PASSWORD }}
# 制品不使用retag中镜像地址
useRetagImage: false
```
1 change: 1 addition & 0 deletions actions/release/1.0/internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Service struct {
RetagImage string `json:"retagImage"`
RegistryUsername string `json:"registryUsername"`
RegistryPassword string `json:"registryPassword"`
UseRetagImage *bool `json:"useRetagImage"` // 制品的镜像是否使用RetagImage对应的镜像仓库;默认为nil,使用RetagReg的镜像仓库
}

type MobileData struct {
Expand Down
4 changes: 3 additions & 1 deletion actions/release/1.0/internal/pkg/diceyml.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func fillDiceYml(cfg *conf.Conf, storage *StorageURL) (string, error) {
return "", err
}

//假如是service模式,需要将service中的cmd塞入dice.yaml中的cmd中
//假如是service模式,需要将service中的cmd塞入dice.yaml中的cmd中;并判定是否使用的镜像修改成retag中的镜像
if cfg.Services != nil {
insertCommands(&dCopy, cfg)
// 若RetagImage被定义过,则默认将制品中使用的镜像修改成retag中的镜像
useRetagImage(&dCopy, cfg)
}

if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions actions/release/1.0/internal/pkg/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ func composeYaml(targetYml *diceyml.DiceYaml, env, envYmlFile string) error {
return nil
}

func useRetagImage(d *diceyml.DiceYaml, cfg *conf.Conf) {
if d == nil {
return
}

diceServices := d.Services()
if diceServices == nil {
return
}
for k, service := range cfg.Services {
if diceServices[k] == nil {
continue
}
// 若RetagImage没有被定义过,则跳过此逻辑
if service.RetagImage == "" {
continue
}
// UseRetagImage 默认为nil(或值为true),使用retag中的镜像;在pipeline.yml中可以使用 useRetagImage: false 将值修改成false
if service.UseRetagImage == nil || *service.UseRetagImage {
diceServices[k]["image"] = service.RetagImage
}
}
}

func insertCommands(d *diceyml.DiceYaml, cfg *conf.Conf) {
if d == nil {
return
Expand Down

0 comments on commit 8398288

Please sign in to comment.