詳情請參閱定價頁面。
控管費用的最佳做法
啟用 Container Scanning API 後,系統會自動掃描您推送的每個新映像檔。如要降低費用,請嘗試下列做法:
在專案中啟用單一存放區的掃描功能。
將要掃描的容器映像檔分別放入不同專案。
設定新的Google Cloud 專案,並為該專案啟用 Container Scanning API。這項專案會產生 Artifact Registry 的正常帳單費用。將要掃描的圖片推送到這個專案。
在 CI/CD 管道中新增下列步驟:
新增與啟用 Container Scanning 的 Artifact Registry 專案相應的標記。
將圖片推送至專案。
預估掃描費用
如要估算專案中圖片的費用,請估算您在一段時間內推送的圖片數量,然後將該數量乘以每次掃描的價格。您可以在 Cloud Shell 中執行殼層指令碼,完成這項操作。
在專案中開啟 Cloud Shell。
按一下「開啟編輯器」圖示,然後建立新檔案
cost-estimation.sh
,其中含有下列內容:#!/bin/bash # Replace with price from https://cloud.google.com/artifact-analysis/pricing PRICE='PRICE' # Replace with your project data GC_PROJECT='PROJECT_REPOSITORY' START_DATE='START_DATE' END_DATE='END_DATE' REGION=$(echo $GC_PROJECT | sed -n 's/\/.*//p') if [ -z "$REGION" ]; then printf "'GC_PROJECT' value must be a valid GCR or AR repository (e.g. gcr.io/corp-staging or us-central1-docker.pkg.dev/myproj/myrepo" exit 1 fi IFS=$'\n' FILTER="timestamp.date('%Y-%m-%d', Z)>'$START_DATE' AND timestamp.date('%Y-%m-%d', Z)<'$END_DATE'" images=$( gcloud container images list --repository="$GC_PROJECT" | sed -n "/$REGION/p" | sed 's/NAME: //' ) num_images=$(echo $images | wc -w) printf "Using gcloud to filter $num_images images from $START_DATE to $END_DATE (takes about 1 second per image)\n\n" total_digests=0 for image in $images; do printf "querying $image\n" image_digests=$( gcloud container images list-tags --filter="$FILTER" "$image" 2> >(sed "s/Listed 0 items.//" | sed -n "/.\+/p" >&2) | wc -l) if [[ "$image_digests" -gt 1 ]]; then total_digests=$(( total_digests + $image_digests - 1 )) fi done total_price=$( python -c "print($total_digests * $PRICE)" ) echo '' echo "Number of images: $total_digests" echo "Estimated cost: $total_price"
更改下列內容:
PRICE
:自動安全漏洞掃描的價格,請參閱「價格」頁面。PROJECT_REPOSITORY
:您的專案存放區。例如:gcr.io/corp-staging
。START_DATE
:要估算期間的開始日期,格式為Y-m-d
。例如:2020-03-01
。END_DATE
:估算期間的結束日期,格式為Y-m-d
。例如:2020-03-31
。
執行指令碼:
bash cost-estimation.sh
畫面會顯示圖片總數和預估總費用:
Number of images: 53 Estimated cost: 13.78
這只是預估值,實際費用可能會因其他因素而異,例如:
將同一張映像檔推送至同一專案中的不同多區域,不會產生額外費用。
將同一張映像檔推送至兩個不同專案中的兩個不同存放區,不會產生額外費用。
查看目前的安全漏洞掃描費用
您可以在帳單報表中查看這項資訊。
後續步驟
- 進一步瞭解安全漏洞掃描。