在 Cloud Shell 中创建私有教程

Cloud Shell 支持创建私有教程,使您可以专门为受众群体设计教程。

按照在 Cloud Shell 中编写教程指南编写教程并按照教程样式指南中的最佳做法操作后,您可以:可以在私有 Git 代码库中托管您的教程,以供用户使用。

托管非公开教程

要将教程设为不公开,您需要一个私有 Git 代码库来托管您的教程。您可以使用任何偏好的 Git 代码库托管服务。本指南使用 Cloud Source Repositories;托管在 Google Cloud 上的私有 Git 代码库。

如需创建 Cloud Source Repositories 代码库以托管您的非公开教程,请执行以下操作:

  1. 启动 Cloud Shell 终端。对于独立 Cloud Shell 会话,请使用 shell.cloud.google.com
  2. 创建私有代码库:

    gcloud source repos create REPO_NAME
    
  3. 将您的代码库克隆到 Cloud Shell:

    gcloud source repos clone REPO_NAME
    
  4. 将教程文件移动到本地创建的代码库:

    mv PATH/TO/TUTORIAL REPO_NAME/PATH/TO/TUTORIAL
    
  5. 转到您的本地代码库:

    cd REPO_NAME
    
  6. 添加要提交的教程:

    git add .
    
  7. 使用描述此操作历史的注释将文件提交到代码库:

    git commit -m "Add private tutorial to Cloud Source Repositories"
    
  8. 使用 git push 命令,将本地 Git 代码库的内容添加到 Cloud Source Repositories:

    git push origin master
    
  9. 在 Google Cloud 控制台中查看您的代码库及其内容:

    打开 Cloud Source Repositories

为了帮助用户访问您的教程,您可以使用 Cloud Shell 的“在 Cloud Shell 中打开”功能,该功能可让您定义用户如何访问教程。如需详细了解如何自定义链接,请参阅在 Cloud Shell 中打开指南

对于托管在 Cloud Source Repositories 代码库中的教程,您需要使用代码库的网址定义 cloudshell_git_repo 参数。

定义了 cloudshell_git_repo 的链接示例:

https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://source.developers.google.com/p/project_name/r/repo_name

您可以将此链接设计为可嵌入文档中的按钮,以便用户轻松找到:

[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://source.developers.google.com/p/project_name/r/repo_name)

使用附加工具自定义教程

通过为用户提供自定义工具来处理您的教程,您可以进一步自定义您的私有教程体验。

为此,您可以创建一个 Docker 映像,将其用作自定义 Cloud Shell 环境,并在其中包含您希望提供给用户的所有其他软件包和自定义配置。如需详细了解如何创建自定义容器映像并更新“在 Cloud Shell 中打开”链接以引用此容器映像,请参阅自定义容器映像指南