From e0ecd1beb1b1edff466841614fa4e6e6a09384f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=B8=96=E5=86=9B?= <30999793+AllForNothing@users.noreply.github.com> Date: Fri, 18 Mar 2022 19:55:19 +0800 Subject: [PATCH] Update push and pull command for helm (#16553) Signed-off-by: AllForNothing --- .../artifact-list-tab.component.html | 4 +- .../artifact-list-tab.component.ts | 33 ++++------- .../artifact-tag/artifact-tag.component.ts | 19 +++---- .../project/repository/artifact/artifact.ts | 57 ++++++++++++------- .../push-image/push-image.component.ts | 6 +- src/portal/src/i18n/lang/de-de-lang.json | 2 +- src/portal/src/i18n/lang/en-us-lang.json | 2 +- src/portal/src/i18n/lang/es-es-lang.json | 2 +- src/portal/src/i18n/lang/fr-fr-lang.json | 2 +- src/portal/src/i18n/lang/pt-br-lang.json | 2 +- src/portal/src/i18n/lang/tr-tr-lang.json | 2 +- src/portal/src/i18n/lang/zh-cn-lang.json | 2 +- src/portal/src/i18n/lang/zh-tw-lang.json | 6 ++ 13 files changed, 72 insertions(+), 67 deletions(-) diff --git a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html index 35ac7a564..c10b67114 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html +++ b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.html @@ -190,8 +190,8 @@ - - + +
diff --git a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts index 3d4a19b4f..039b2a6e6 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts +++ b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/artifact-list-tab.component.ts @@ -31,7 +31,6 @@ import { VULNERABILITY_SCAN_STATUS } from "../../../../../../../shared/units/utils"; import { ImageNameInputComponent } from "../../../../../../../shared/components/image-name-input/image-name-input.component"; -import { CopyInputComponent } from "../../../../../../../shared/components/push-image/copy-input.component"; import { ErrorHandler } from "../../../../../../../shared/units/error-handler"; import { ArtifactService } from "../../../artifact.service"; import { OperationService } from "../../../../../../../shared/components/operation/operation.service"; @@ -42,7 +41,7 @@ import { artifactDefault, ArtifactFront as Artifact, ArtifactFront, - artifactPullCommands, + ArtifactType, getPullCommandByDigest, getPullCommandByTag, mutipleFilter } from '../../../artifact'; import { Project } from "../../../../../project"; @@ -130,8 +129,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { imageNameInput: ImageNameInputComponent; @ViewChild("digestTarget") textInput: ElementRef; - @ViewChild("copyInput") copyInput: CopyInputComponent; - pageSize: number = DEFAULT_PAGE_SIZE; currentPage = 1; totalCount = 0; @@ -408,7 +405,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { this.artifactList.forEach((artifact, index) => { artifact.platform = clone(platFormAttr[index].platform); }); - this.getPullCommand(this.artifactList); this.getArtifactTagsAsync(this.artifactList); this.getAccessoriesAsync(this.artifactList); this.checkCosignAsync(this.artifactList); @@ -442,7 +438,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { } } this.artifactList = res.body; - this.getPullCommand(this.artifactList); this.getArtifactTagsAsync(this.artifactList); this.getAccessoriesAsync(this.artifactList); this.checkCosignAsync(this.artifactList); @@ -466,17 +461,16 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { this.clrLoad(st); } - getPullCommand(artifactList: Artifact[]) { - artifactList.forEach(artifact => { - artifact.pullCommand = ''; - artifactPullCommands.forEach(artifactPullCommand => { - if (artifactPullCommand.type === artifact.type) { - artifact.pullCommand = - `${artifactPullCommand.pullCommand} ${this.registryUrl ? - this.registryUrl : location.hostname}/${this.projectName}/${this.repoName}@${artifact.digest}`; - } - }); - }); + getPullCommand(artifact: Artifact): string { + let pullCommand: string = ''; + if (artifact.type === ArtifactType.CHART && artifact.tags && artifact.tags[0]) { + pullCommand = getPullCommandByTag(artifact.type, `${this.registryUrl ? + this.registryUrl : location.hostname}/${this.projectName}/${this.repoName}`, artifact.tags[0]?.name); + } else { + pullCommand = getPullCommandByDigest(artifact.type, `${this.registryUrl ? + this.registryUrl : location.hostname}/${this.projectName}/${this.repoName}`, artifact.digest); + } + return pullCommand; } labelSelectedChange(artifact?: Artifact[]): void { this.artifactListPageService.imageStickLabels.forEach(data => { @@ -980,11 +974,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy { this.onSendingScanCommand = e; } } - - // pull command - onCpError($event: any): void { - this.copyInput.setPullCommendShow(); - } handleScanOverview(scanOverview: any): any { if (scanOverview) { return Object.values(scanOverview)[0]; diff --git a/src/portal/src/app/base/project/repository/artifact/artifact-tag/artifact-tag.component.ts b/src/portal/src/app/base/project/repository/artifact/artifact-tag/artifact-tag.component.ts index e4560893a..c4899f038 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact-tag/artifact-tag.component.ts +++ b/src/portal/src/app/base/project/repository/artifact/artifact-tag/artifact-tag.component.ts @@ -8,7 +8,7 @@ import { OperationService } from "../../../../../shared/components/operation/ope import { ErrorHandler } from "../../../../../shared/units/error-handler"; import { ConfirmationButtons, ConfirmationState, ConfirmationTargets } from "../../../../../shared/entities/shared.const"; import { operateChanges, OperateInfo, OperationState } from "../../../../../shared/components/operation/operate"; -import { AccessoryQueryParams, AccessoryType, ArtifactFront as Artifact, artifactImages, artifactPullCommands } from '../artifact'; +import { AccessoryQueryParams, AccessoryType, ArtifactFront as Artifact, ArtifactType, getPullCommandByTag } from '../artifact'; import { ArtifactService } from '../../../../../../../ng-swagger-gen/services/artifact.service'; import { Tag } from '../../../../../../../ng-swagger-gen/models/tag'; import { SystemInfo, SystemInfoService, UserPermissionService, USERSTATICPERMISSION } from "../../../../../shared/services"; @@ -143,7 +143,7 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { if (res.headers) { let xHeader: string = res.headers.get("x-total-count"); if (xHeader) { - this.totalCount = Number.parseInt(xHeader); + this.totalCount = Number.parseInt(xHeader, 10); } } this.currentTags = res.body; @@ -340,20 +340,17 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { } hasPullCommand(): boolean { return this.artifactDetails - && (this.artifactDetails.type === artifactImages[0] - || this.artifactDetails.type === artifactImages[1] - || this.artifactDetails.type === artifactImages[2]) + && (this.artifactDetails.type === ArtifactType.IMAGE + || this.artifactDetails.type === ArtifactType.CHART + || this.artifactDetails.type === ArtifactType.CNAB) && this.accessoryType !== AccessoryType.COSIGN; } getPullCommand(tag: Tag): string { let pullCommand: string = ''; if (tag && tag.name && this.artifactDetails ) { - artifactPullCommands.forEach(artifactPullCommand => { - if (artifactPullCommand.type === this.artifactDetails.type) { - pullCommand = `${artifactPullCommand.pullCommand} ${this.registryUrl}/${this.projectName}/${this.repositoryName}:${tag.name}`; - } - }); + pullCommand = getPullCommandByTag(this.artifactDetails?.type, + `${this.registryUrl}/${this.projectName}/${this.repositoryName}`, tag.name); } - return pullCommand; + return pullCommand; } } diff --git a/src/portal/src/app/base/project/repository/artifact/artifact.ts b/src/portal/src/app/base/project/repository/artifact/artifact.ts index 7c7d51ee1..3392f9097 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact.ts +++ b/src/portal/src/app/base/project/repository/artifact/artifact.ts @@ -66,30 +66,45 @@ export enum AccessoryType { COSIGN = 'signature.cosign' } -export const artifactImages = [ - 'IMAGE', 'CHART', 'CNAB', 'OPENPOLICYAGENT' -]; -export const artifactPullCommands = [ - { - type: artifactImages[0], - pullCommand: 'docker pull' - }, - { - type: AccessoryType.COSIGN, - pullCommand: 'docker pull' - }, - { - type: artifactImages[1], - pullCommand: 'helm chart pull' - }, - { - type: artifactImages[2], - pullCommand: 'cnab-to-oci pull' - } -]; +export enum ArtifactType { + IMAGE = 'IMAGE', + CHART = 'CHART', + CNAB = 'CNAB', + OPENPOLICYAGENT = 'OPENPOLICYAGENT' +} + export const artifactDefault = "images/artifact-default.svg"; export enum AccessoryQueryParams { ACCESSORY_TYPE = 'accessoryType' } +export function getPullCommandByDigest(artifactType: string, url: string, digest: string): string { + let pullCommand: string = ''; + if (artifactType && url && digest) { + if (artifactType === ArtifactType.IMAGE) { + pullCommand = `docker pull ${url}@${digest}`; + } + if (artifactType === ArtifactType.CNAB) { + pullCommand = `cnab-to-oci pull ${url}@${digest}`; + } + } + return pullCommand; +} + +export function getPullCommandByTag(artifactType: string, url: string, tag: string): string { + let pullCommand: string = ''; + if (artifactType && url && tag) { + if (artifactType === ArtifactType.IMAGE) { + pullCommand = `docker pull ${url}:${tag}`; + } + if (artifactType === ArtifactType.CNAB) { + pullCommand = `cnab-to-oci pull ${url}:${tag}`; + } + if (artifactType === ArtifactType.CHART) { + pullCommand = `helm pull oci://${url} --version ${tag}`; + } + } + return pullCommand; +} + diff --git a/src/portal/src/app/shared/components/push-image/push-image.component.ts b/src/portal/src/app/shared/components/push-image/push-image.component.ts index 4110cf0b3..7b5de4836 100644 --- a/src/portal/src/app/shared/components/push-image/push-image.component.ts +++ b/src/portal/src/app/shared/components/push-image/push-image.component.ts @@ -30,13 +30,11 @@ export class PushImageButtonComponent { return `docker push ${this.registryUrl}/${this.projectName}/REPOSITORY[:TAG]`; } public get tagCommandChart(): string { - return `helm chart save CHART_PATH ${this.registryUrl}/${ - this.projectName - }/REPOSITORY[:TAG]`; + return `helm package CHART_PATH`; } public get pushCommandChart(): string { - return `helm chart push ${this.registryUrl}/${this.projectName}/REPOSITORY[:TAG]`; + return `helm push CHART_PACKAGE oci://${this.registryUrl}/${this.projectName}`; } public get pushCommandCnab(): string { diff --git a/src/portal/src/i18n/lang/de-de-lang.json b/src/portal/src/i18n/lang/de-de-lang.json index 3c417b619..e5fb6928b 100644 --- a/src/portal/src/i18n/lang/de-de-lang.json +++ b/src/portal/src/i18n/lang/de-de-lang.json @@ -1088,7 +1088,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Tag ein Chart für dieses Projekt:", + "TAG_COMMAND_CHART": "Package ein Chart für dieses Projekt:", "PUSH_COMMAND_CHART": "Push ein Chart für dieses Projekt:", "PUSH_COMMAND_CNAB": "Push ein CNAB für dieses Projekt:", "TOOLTIP": "Befehlreferenz um ein Artefakt in das Projekt zu pushen.", diff --git a/src/portal/src/i18n/lang/en-us-lang.json b/src/portal/src/i18n/lang/en-us-lang.json index ff3bde890..57f8bdbba 100644 --- a/src/portal/src/i18n/lang/en-us-lang.json +++ b/src/portal/src/i18n/lang/en-us-lang.json @@ -1088,7 +1088,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Tag a chart for this project:", + "TAG_COMMAND_CHART": "Package a chart for this project:", "PUSH_COMMAND_CHART": "Push a chart to this project:", "PUSH_COMMAND_CNAB": "Push a CNAB to this project:", "TOOLTIP": "Command references for pushing an artifact to this project.", diff --git a/src/portal/src/i18n/lang/es-es-lang.json b/src/portal/src/i18n/lang/es-es-lang.json index 7be7d00c7..cad6b68d0 100644 --- a/src/portal/src/i18n/lang/es-es-lang.json +++ b/src/portal/src/i18n/lang/es-es-lang.json @@ -1089,7 +1089,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Tag a chart for this project:", + "TAG_COMMAND_CHART": "Package a chart for this project:", "PUSH_COMMAND_CHART": "Push a chart to this project:", "PUSH_COMMAND_CNAB": "Push a CNAB to this project:", "TOOLTIP": "Command references for pushing an artifact to this project.", diff --git a/src/portal/src/i18n/lang/fr-fr-lang.json b/src/portal/src/i18n/lang/fr-fr-lang.json index 876e47bf7..706ad68a4 100644 --- a/src/portal/src/i18n/lang/fr-fr-lang.json +++ b/src/portal/src/i18n/lang/fr-fr-lang.json @@ -1061,7 +1061,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Tag a chart for this project:", + "TAG_COMMAND_CHART": "Package a chart for this project:", "PUSH_COMMAND_CHART": "Push a chart to this project:", "PUSH_COMMAND_CNAB": "Push a CNAB to this project:", "TOOLTIP": "Command references for pushing an artifact to this project.", diff --git a/src/portal/src/i18n/lang/pt-br-lang.json b/src/portal/src/i18n/lang/pt-br-lang.json index a5c37b039..b5d8c081c 100644 --- a/src/portal/src/i18n/lang/pt-br-lang.json +++ b/src/portal/src/i18n/lang/pt-br-lang.json @@ -1084,7 +1084,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Colocar tag em chart deste projeto:", + "TAG_COMMAND_CHART": "Package a chart for this project:", "PUSH_COMMAND_CHART": "Enviar um chart a este projeto:", "PUSH_COMMAND_CNAB": "Enviar um CNAB a este projeto:", "TOOLTIP": "Referência de comandos para enviar artefatos a este projeto.", diff --git a/src/portal/src/i18n/lang/tr-tr-lang.json b/src/portal/src/i18n/lang/tr-tr-lang.json index 20c1b9523..c6a5ae733 100644 --- a/src/portal/src/i18n/lang/tr-tr-lang.json +++ b/src/portal/src/i18n/lang/tr-tr-lang.json @@ -1088,7 +1088,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "Tag a chart for this project:", + "TAG_COMMAND_CHART": "Package a chart for this project:", "PUSH_COMMAND_CHART": "Push a chart to this project:", "PUSH_COMMAND_CNAB": "Push a CNAB to this project:", "TOOLTIP": "Command references for pushing an artifact to this project.", diff --git a/src/portal/src/i18n/lang/zh-cn-lang.json b/src/portal/src/i18n/lang/zh-cn-lang.json index d6485b4a4..90e4710fa 100644 --- a/src/portal/src/i18n/lang/zh-cn-lang.json +++ b/src/portal/src/i18n/lang/zh-cn-lang.json @@ -1089,7 +1089,7 @@ "DOCKER": "Docker", "HELM": "Helm", "CNAB": "CNAB", - "TAG_COMMAND_CHART": "在项目中标记 chart", + "TAG_COMMAND_CHART": "在项目中打包 chart", "PUSH_COMMAND_CHART": "推送 chart 到当前项目", "PUSH_COMMAND_CNAB": "推送 CNAB 到当前项目", "TOOLTIP": "推送一个 artifact 到当前项目的参考命令。", diff --git a/src/portal/src/i18n/lang/zh-tw-lang.json b/src/portal/src/i18n/lang/zh-tw-lang.json index 81c930416..d44c089fa 100644 --- a/src/portal/src/i18n/lang/zh-tw-lang.json +++ b/src/portal/src/i18n/lang/zh-tw-lang.json @@ -1081,6 +1081,12 @@ }, "PUSH_IMAGE":{ "TITLE": "推送鏡像的Docker命令", + "DOCKER": "Docker", + "HELM": "Helm", + "CNAB": "CNAB", + "TAG_COMMAND_CHART": "Package a chart for this project:", + "PUSH_COMMAND_CHART": "Push a chart to this project:", + "PUSH_COMMAND_CNAB": "Push a CNAB to this project:", "TOOLTIP": "推送一個鏡像到當前項目的參考命令。", "TAG_COMMAND": "在項目中標記鏡像:", "PUSH_COMMAND": "推送鏡像到當前項目:",