如果尚未建立 Secure Source Manager 執行個體,請參閱建立 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
- 安裝
beta
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:選用。從下拉式選單中選取常見授權。
預設分支版本:預設分支版本的名稱。
按一下「提交」。
gcloud
使用 gcloud CLI 執行下列指令,建立存放區:
gcloud alpha source-manager repos create REPOSITORY_ID \ --region=LOCATION \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --description=DESCRIPTION \ --default-branch=BRANCH \ --gitignores=GITIGNORES \ --license=LICENSE \ --readme=README
更改下列內容:
REPOSITORY_ID
改為存放區的名稱。LOCATION
改為您要在其中建立存放區的地區。如要瞭解支援的位置,請參閱「位置」。請將
PROJECT_ID
替換為您要在其中建立存放區的 Secure Source Manager 執行個體專案 ID。INSTANCE_ID
,其中是您要在其中建立存放區的執行個體 ID。如要列出專案中的 Secure Source Manager 執行個體,請參閱「列出及查看執行個體」。DESCRIPTION
,並附上存放區的說明。這項設定為選用,可以省略。將
BRANCH
替換為預設分支版本名稱。這是選用屬性,可以省略。如未設定,預設分支版本名稱為main
。GITIGNORES
,並以半形逗號分隔 .gitignore 範本名稱清單。這是選用項目,可以省略。 如要查看可用範本的完整清單,請參閱存放區初始化設定參考資料。LICENSE
替換為要套用至存放區的授權範本名稱。這是選用項目,可以省略。 如要查看可用授權範本的完整清單,請參閱存放區初始化設定參考資料。README
default
,即可從預設範本建立 README 檔案。這項設定為選用,可以省略。如果省略,系統就不會建立 README 檔案。
API
執行下列指令,透過 REST 呼叫建立存放區:
curl \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ https://securesourcemanager.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/repositories?repository_id=REPOSITORY_ID \ -d '{"instance": "projects/PROJECT_ID/locations/REGION/instances/INSTANCE_ID"}'
更改下列內容:
REGION
是 Secure Source Manager 執行個體的所在區域。 如要瞭解支援的位置,請參閱「位置」。INSTANCE_ID
是您的 Secure Source Manager 執行個體 ID。PROJECT_ID
是 Secure Source Manager 執行個體的專案 ID。如要瞭解專案 ID 的位置,請參閱「識別專案」。REPOSITORY_ID
是存放區的名稱。
您可以使用 HTTP POST 資料標記
-d'{}'
指定其他值,包括初始化存放區、新增特定檔案或授權。.gitignore
詳情請參閱參考說明文件。如要讓輸出內容更容易閱讀,可以使用
json_pp
將輸出內容導向 JSON。例如:
curl \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ https://securesourcemanager.googleapis.com/v1/projects/my-project-id/locations/us-central1/repositories?repository_id=my-repo \ -d '{"instance": "projects/my-project-id/locations/us-central1/instances/prod-test-instance", "initialConfig":{"defaultBranch":"main"}}' | json_pp
回應內容如下所示:
{ "name": "operations/266bf4c7-13fe-11ed-be24-da823b7355d0", "metadata": { "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata", "createTime": "2022-08-04T14:02:59.810496928Z", "endTime": "2022-08-04T14:03:00.558354528Z", "target": "projects/654987321654/locations/us-central1/repositories/my-repo", "verb": "create", "apiVersion": "v1" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.Repository", "name": "projects/my-project-id/locations/us-central1/repositories/my-repo", "instance": "projects/654987321654/locations/us-central1/instances/prod-test-instance", "createTime": "2022-08-04T14:03:00Z", "uris": { "html": "https://prod-test-instance-654987321654.us-central1.sourcemanager.dev/my-project-id/my-repo", "gitHttps": "https://prod-test-instance-654987321654-git.us-central1.sourcemanager.dev/my-project-id/my-repo.git" } }
其中:
654987321654
是存放區專案號碼。my-project-id
是存放區專案 ID。my-repo
是您在建立指令中設定的REPOSITORY_ID
。 「uris
」欄位包含透過網頁瀏覽器或 Git 通訊協定 HTTPS 存取存放區的網址。
使用回應中的 HTML URI 存取新存放區。Secure Source Manager 網頁介面支援程式碼審查、問題追蹤和提取要求。
存放區會在 Secure Source Manager 執行個體中建立。
建立新存放區時,系統會授予您存放區管理員角色 (roles/securesourcemanager.repoAdmin
)。新的 IAM 權限可能需要最多 2 分鐘才能生效,因此如果您在建立存放區後嘗試存取時收到權限錯誤,請稍候幾分鐘再試一次。
您建立的存放區會列在「我的存放區」頁面上的 Secure Source Manager 網頁介面中。
後續步驟
- 授予使用者存放區存取權
- 使用 Git 原始碼管理搭配 Secure Source Manager。
- 在 Secure Source Manager 網頁介面中列出及查看存放區。