建立及複製存放區
在 Secure Source Manager 中建立存放區,並複製到本機電腦。
事前準備
- 建立或要求存取 Secure Source Manager 執行個體。詳情請參閱「建立 Secure Source Manager 執行個體」。
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- 安裝
alpha
Google Cloud CLI 元件:gcloud components install alpha
必要的角色
如要取得建立存放區所需的權限,請要求管理員授予下列 IAM 角色:
-
Secure Source Manager 執行個體存放區建立者角色 (
roles/securesourcemanager.instanceRepositoryCreator
) 在 Secure Source Manager 執行個體上 -
Secure Source Manager 存放區建立者角色 (
roles/securesourcemanager.repoCreator
) 執行個體專案
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
如要瞭解如何授予 Secure Source Manager 角色,請參閱「透過 IAM 控管存取權」和「授予使用者執行個體存取權」。
建立存放區
網頁介面
-
如要透過網頁介面存取 Secure Source Manager 執行個體,請將下列網址複製到瀏覽器的網址列。
INSTANCE_ID-PROJECT_NUMBER.LOCATION.sourcemanager.dev
取代下列項目:
- 將 INSTANCE_ID 替換為執行個體名稱。
- 將 PROJECT_NUMBER 換成執行個體的 Google Cloud 專案編號。如要瞭解如何識別專案,請參閱「識別專案」。
- LOCATION,其中包含執行個體的所在地區。
視需要使用 Secure Source Manager 憑證進行驗證。
按一下導覽選單右上角的「+ Create new repository」(+ 建立新存放區) 圖示。
填寫存放區詳細資料:
存放區 ID:輸入存放區名稱。
說明:選填。存放區的說明。
初始化存放區:選用。如要初始化存放區並新增 .gitignore、授權和 README 檔案,請選取這個選項。
.gitignore:選用。使用下拉式選單範本,選擇要排除追蹤的檔案。
license:選用。從下拉式選單中選取常見授權。
預設分支版本:預設分支版本的名稱。
按一下「提交」。
存放區會在 Secure Source Manager 執行個體中建立。
建立新存放區時,系統會授予您存放區管理員角色 (roles/securesourcemanager.repoAdmin
)。新的 IAM 權限可能需要最多 2 分鐘才能生效,因此如果您在建立存放區後嘗試存取時收到權限錯誤,請稍候幾分鐘再試一次。
您建立的存放區會列在「我的存放區」頁面上的 Secure Source Manager 網頁介面中。
設定憑證
執行下列指令,將 Secure Source Manager 驗證輔助程式新增至全域 Git 設定:
Linux
git config --global credential.'https://*.*.sourcemanager.dev'.helper gcloud.sh
舊版 Git 可能不支援萬用字元。如要新增驗證輔助程式 (不含萬用字元),請執行下列指令:
git config --global credential.'https://INSTANCE_ID-PROJECT_NUMBER-git.LOCATION.sourcemanager.dev'.helper gcloud.sh
Windows
git config --global credential.https://*.*.sourcemanager.dev.helper gcloud.cmd
舊版 Git 可能不支援萬用字元。如要新增驗證輔助程式 (不含萬用字元),請執行下列指令:
git config --global credential.https://INSTANCE_ID-PROJECT_NUMBER-git.LOCATION.sourcemanager.dev.helper gcloud.cmd
更改下列內容:
INSTANCE_ID
改為您的 Secure Source Manager 執行個體名稱。- 將
PROJECT_NUMBER
改成您的專案編號。如需專案編號的相關說明,請參閱「識別專案」。 LOCATION
,其中包含執行個體的所在地區。如要進一步瞭解地區,請參閱「位置」。
使用 Secure Source Manager 執行 Git 指令時,驗證輔助程式會使用 gcloud CLI 擷取您的Google Cloud 憑證。
如要在初始憑證設定後重新驗證,請執行下列 gcloud CLI 指令:
gcloud auth login
複製存放區
在 Secure Source Manager 網頁介面中,前往存放區頁面。
複製存放區頁面頂端的 HTTPS 網址。
執行下列指令來複製存放區:
git clone REPOSITORY_URL
其中
REPOSITORY_URL
是要複製的存放區頁面頂端顯示的 HTTPS 網址。請忽略複製空存放區的警告。
推送至存放區
在終端機視窗中,將目錄變更為複製的存放區。
cd REPOSITORY_NAME
其中
REPOSITORY_NAME
是存放區名稱。建立空白的 README 檔案:
touch README.md
將 README 檔案新增至 Git,並建立提交訊息:
git add README.md git commit -m "initial commit"
將變更推送至遠端存放區:
git push -u origin main
Git 會將檔案從主要分支版本推送至 origin 遠端。輸出內容會類似如下:
Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 211 bytes | 211.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: . Processing 1 references remote: Processed 1 references in total To https://instance-id-123456789012-git.us-central1.sourcemanager.dev/my-project/my-repo.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
在 Secure Source Manager 中查看檔案
在 Secure Source Manager 網頁介面中,按一下存放區名稱。
系統會開啟存放區頁面,並在「<> Code」分頁中列出 README.md
檔案。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
移除存放區之前,請先確認要保留的檔案均已存放於其他位置。
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:執行 Secure Source Manager 的 Google Cloud 專案專案 ID。
- LOCATION:執行個體所在的區域。如要瞭解支援的位置,請參閱「位置」。
- REPOSITORY_ID:存放區 ID。
HTTP 方法和網址:
DELETE https://securesourcemanager.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/repositories/REPOSITORY_ID
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
"name":"operations/cc3ea26c-9b57-11ed-be0a-2e3b5910efef","metadata":{"@type":"type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata","createTime":"2023-01-23T19:54:49.904779921Z","endTime":"2023-01-23T19:54:50.947030402Z","target":"projects/my-project/locations/us-central1/repositories/my-repo","verb":"delete","apiVersion":"v1"},"done":true,"response":{"@type":"type.googleapis.com/google.protobuf.Empty"} ```
回應類似以下內容:
{"name":"operations/cc3ea26c-9b57-11ed-be0a-2e3b5910efef","metadata":{"@type":"type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata","createTime":"2023-01-23T19:54:49.904779921Z","endTime":"2023-01-23T19:54:50.947030402Z","target":"projects/my-project/locations/us-central1/repositories/my-repo","verb":"delete","apiVersion":"v1"},"done":true,"response":{"@type":"type.googleapis.com/google.protobuf.Empty"}