📣

TiDB Cloud Serverless 现已更名为
Starter
!此页面由 AI 自动翻译,英文原文请见
此处。

Gitpod

通过 Gitpod,你可以只需点击一个按钮或链接,即可在浏览器中获得完整的开发环境,并立即开始编写代码。

Gitpod 是一个开源的 Kubernetes 应用(GitHub 仓库地址:https://github.com/gitpod-io/gitpod),用于直接编码的开发环境,它在云端为每个任务快速启动全新、自动化的开发环境。它允许你将开发环境描述为代码,并可以直接从浏览器或桌面 IDE 启动即时的远程云端开发环境。

快速开始

  1. Fork 用于 TiDB 应用开发的示例代码仓库 pingcap-inc/tidb-example-java

  2. 在浏览器地址栏中,将示例代码仓库的 URL 前缀改为 https://gitpod.io/#,启动你的 Gitpod 工作区。

  • 例如,https://gitpod.io/#https://github.com/pingcap-inc/tidb-example-java

  • 你可以在 URL 中配置环境变量。例如,https://gitpod.io/#targetFile=spring-jpa-hibernate_Makefile,targetMode=spring-jpa-hibernate/https://github.com/pingcap-inc/tidb-example-java

  1. 登录并使用列出的提供商之一启动工作区。例如,Github

使用默认的 Gitpod 配置和环境

完成 快速开始 步骤后,Gitpod 需要一些时间来设置你的工作区。

Spring Boot Web 应用为例,你可以通过 URL https://gitpod.io/#targetFile=spring-jpa-hibernate_Makefile,targetMode=spring-jpa-hibernate/https://github.com/pingcap-inc/tidb-example-java 创建一个新的工作区。

之后,你会看到类似如下的页面:

playground gitpod workspace init

页面中的场景使用 TiUP 构建 TiDB Playground。你可以在终端区域左侧查看进度。

当 TiDB Playground 准备就绪后,另一个 Spring JPA Hibernate 任务将会运行。你可以在终端区域右侧查看进度。

所有任务完成后,你会看到类似如下的页面。在左侧导航栏的 REMOTE EXPLORER 区域(Gitpod 支持基于 URL 的端口转发)中,找到端口 8080 的 URL。

playground gitpod workspace ready

使用自定义的 Gitpod 配置和 Docker 镜像

自定义 Gitpod 配置

参考 example.gitpod.yml,在你的项目根目录创建 .gitpod.yml 文件,以配置 Gitpod 工作区。

# This configuration file was automatically generated by Gitpod. # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) # and commit this file to your remote git repository to share the goodness with others. # image: # file: .gitpod.Dockerfile tasks: - name: Open Target File command: | if [ -n "$targetFile" ]; then code ${targetFile//[_]//}; fi - name: TiUP init playground command: | $HOME/.tiup/bin/tiup playground - name: Test Case openMode: split-right init: echo "*** Waiting for TiUP Playground Ready! ***" command: | gp await-port 3930 if [ "$targetMode" == "plain-java-jdbc" ] then cd plain-java-jdbc code src/main/resources/dbinit.sql code src/main/java/com/pingcap/JDBCExample.java make mysql elif [ "$targetMode" == "plain-java-hibernate" ] then cd plain-java-hibernate make elif [ "$targetMode" == "spring-jpa-hibernate" ] then cd spring-jpa-hibernate make fi ports: - port: 8080 visibility: public - port: 4000 visibility: public - port: 2379-36663 onOpen: ignore

自定义 Gitpod Docker 镜像

默认情况下,Gitpod 使用名为 Workspace-Full 的标准 Docker 镜像作为工作区基础。由此镜像启动的工作区预装有 Docker、Go、Java、Node.js、C/C++、Python、Ruby、Rust、PHP 以及 Homebrew、Tailscale 和 Nginx 等工具。

你可以使用公共 Docker 镜像或 Dockerfile,并安装项目所需的任何依赖。

例如,可以使用如下的 Dockerfile(另见 示例 .gitpod.Dockerfile):

FROM gitpod/workspace-java-17 RUN sudo apt install mysql-client -y RUN curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

然后,更新你的 .gitpod.yml 文件:

# This configuration file was automatically generated by Gitpod. # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) # and commit this file to your remote git repository to share the goodness with others. image: # Import your Dockerfile here. file: .gitpod.Dockerfile tasks: - name: Open Target File command: | if [ -n "$targetFile" ]; then code ${targetFile//[_]//}; fi - name: TiUP init playground command: | $HOME/.tiup/bin/tiup playground - name: Test Case openMode: split-right init: echo "*** Waiting for TiUP Playground Ready! ***" command: | gp await-port 3930 if [ "$targetMode" == "plain-java-jdbc" ] then cd plain-java-jdbc code src/main/resources/dbinit.sql code src/main/java/com/pingcap/JDBCExample.java make mysql elif [ "$targetMode" == "plain-java-hibernate" ] then cd plain-java-hibernate make elif [ "$targetMode" == "spring-jpa-hibernate" ] then cd spring-jpa-hibernate make fi ports: - port: 8080 visibility: public - port: 4000 visibility: public - port: 2379-36663 onOpen: ignore

应用更改

完成 .gitpod.yml 文件的配置后,确保最新的代码已推送到你的对应 GitHub 仓库。

访问 https://gitpod.io/#<YOUR_REPO_URL>,即可创建一个应用了最新代码的 Gitpod 工作区。

访问 https://gitpod.io/workspaces 查看所有已建立的工作区。

概要

Gitpod 提供一个完整的、自动化的、预配置的云原生开发环境。你可以直接在浏览器中开发、运行和测试代码,无需任何本地配置。

playground gitpod summary

需要帮助?

DiscordSlack 上向社区提问,或 提交支持工单

文档内容是否有帮助?