Gitpod
Gitpodを使用すると、ボタンまたはリンクをクリックするだけでブラウザで完全な開発環境を取得でき、すぐにコードを作成できます。
Gitpod は、コードへの直接開発環境用のオープンソース Kubernetes アプリケーション (GitHub リポジトリ アドレス: https://github.com/gitpod-io/gitpod ) であり、タスクごとに新しい自動開発環境をクラウド上に数秒で起動します。これにより、開発環境をコードとして記述し、ブラウザまたはデスクトップ IDE から直接、インスタントのリモートおよびクラウドベースの開発環境を開始できます。
クイックスタート
TiDB アプリケーション開発用のサンプル コード リポジトリpingcap-inc/tidb-example-javaをフォークします。
ブラウザのアドレス バーで、サンプル コード リポジトリの 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
。
ログインし、リストされているプロバイダーのいずれかを使用してワークスペースを開始します。たとえば、
Github
。
デフォルトの Gitpod 構成と環境を使用する
クイックスタート手順を完了した後、Gitpod がワークスペースをセットアップするまでにしばらく時間がかかります。
スプリングブートウェブアプリケーションを例に挙げます。 https://gitpod.io/#targetFile=spring-jpa-hibernate_Makefile,targetMode=spring-jpa-hibernate/https://github.com/pingcap-inc/tidb-example-java
URLで新しいワークスペースを作成できます。
その後、次のようなページが表示されます。
このページのこのシナリオでは、 TiUPを使用して TiDB プレイグラウンドを構築します。ターミナルエリアの左側で進捗状況を確認できます。
TiDB プレイグラウンドの準備が完了すると、別のSpring JPA Hibernate
タスクが実行されます。ターミナルエリアの右側で進捗状況を確認できます。
これらのタスクがすべて完了すると、次のようなページが表示されます。このページで、左側のナビゲーション ペインのREMOTE EXPLORER
領域 (Gitpod は URL ベースのポート転送をサポートしています) を確認し、ポート8080
の URL を見つけます。
カスタム 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、Rust、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 は、完全で自動化された事前構成済みのクラウドネイティブ開発環境を提供します。ローカル構成を必要とせずに、ブラウザーで直接コードを開発、実行、テストできます。