大网数据广告活动
数据库部署与 SQL 参考

TiDB 中文参考:Gitpod

· 52CE 我爱测

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

Gitpod

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

Gitpod 是一个开源 Kubernetes 应用程序(GitHub 仓库地址 https://github.com/gitpod-io/gitpod),适用于可直接编写代码的开发环境,可为云中的每个任务提供全新的自动化开发环境,非常迅速。此外,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。

  3. 使用列出的提供商之一登录并启动工作区,例如,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 可以创建一个新工作区。

完成后,你将看到如下所示的页面。

[图示请参阅官方原文]

页面中的这个场景使用了 TiUP 来搭建一个 TiDB Playground。你可以在终端的左侧查看进度。

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

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

[图示请参阅官方原文]

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

自定义 Gitpod 配置

在项目的根目录中,参考示例 .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:
  # 在这里导入你的 Dockerfile
  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 提供了完整的、自动化的、预配置的云原生开发环境。无需本地配置,你可以直接在浏览器中开发、运行、测试代码。

[图示请参阅官方原文]

本文来自 PingCAP / TiDB 文档贡献者,按 CC BY-SA 3.0 整理版式与相对链接,保留正文与代码。图示请参阅原文。作者与贡献记录。

资料来源与适用范围

资料来源
PingCAP / TiDB 文档贡献者
适用范围
master 文档快照(2026-11-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-16
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。