LoginSignup
4
1

More than 1 year has passed since last update.

CodeReady WorkspacesでGitHub Enterpriseを連携させる

Posted at

GitHub Enterprise(GHE)のプライベート・レポジトリーにあるソースコードをCodeReady Workspacesで利用できるようGHEの認証情報を設定し連携させてみました。結論としては、CodeReady WorkspacesのベースとなっているEclipse Cheと同様の設定で想定通りに動作しました。

連携で実現できること

CodeReady Workspacesへのワークスペース作成時に、ユーザーはYAML形式のdevfileを記述します。devfileには、ワークスペースに読み込むソースファイルの場所を意味する「プロジェクトソース」の設定が含まれます。

プロジェクトソースの設定例
source:
    type: git
    location: https://github.com/eclipse/che.git

以上の例のような公開レポジトリーとは違い、GHEのプライベート・レポジトリーへのアクセスには認証が必要です。devfileのlocationにGHEのプライベート・レポジトリーのURLを設定するだけでは、認証エラーによりワークスペースが作成されません。GHEのプライベート・レポジトリーをプロジェクトソースとするには、CodeReady WorkspacesにGHEの認証情報設定が必要となります。

前提環境

  • OpenShift 4.8 (IBM Red Hat OpenShift Kubernetes Service: ROKS)
  • CodeReady Workspaces 2.13
  • GHEのPersonal access token
    • 流れは以下の通りですが、GHEでもGitHubでも同様ですので取得方法詳細は省略します。
  1. GHEにブラウザーでログインします。
  2. Settings > Developer Settings > Personal access tokens へ進み、Generate new tokenボタンをクリックします。
  3. スコープとして repo にチェックを入れ、Generate tokenボタンをクリックします。

設定手順

OpenShift コンソールで 管理者パースペクティブの ワークロード > シークレットにアクセスします。
自分のワークスペースのプロジェクトに切り替え、「作成」ボタンをクリックします。オペレータでCodeReady Workspacesを導入したプロジェクトではなく、ユーザーごとに作成されるプロジェクトに対して操作することに注意します。
crw001.png

「ソース: YAML」をクリックします。
crw002.png

以下のYAMLを入力します。フォーマットの例については、Eclipse Cheのドキュメントを参照できます。

git-credentials-secret.yml
apiVersion: v1
kind: Secret
metadata:
  name: git-credentials-secret
  labels:
    app.kubernetes.io/component: workspace-secret
    app.kubernetes.io/part-of: che.eclipse.org
  annotations:
    che.eclipse.org/automount-workspace-secret: 'true'
    che.eclipse.org/git-credential: 'true'
    che.eclipse.org/mount-as: file
    che.eclipse.org/mount-path: /home/theia/.git-credentials
data:
  credentials: (.git-credentials の内容をbase64エンコードした値を入力)

.git-credentials のフォーマットは以下のようになります。.git-credentialsの内容をbase64エンコードした値をYAMLに入力します。

https://(GHEのユーザー名):(Personal access token)@(GHEのドメイン名)

「作成」ボタンをクリックします。
crw003.png

作成完了すると、シークレットが以下のように見えます。
crw004.png

これで devfileのlocationにGHEのURLを指定してワークスペース作成できるようになります。

参考情報

Mounting a git credentials store into a workspace container
https://www.eclipse.org/che/docs/che-7/end-user-guide/mounting-a-secret-as-a-file-or-an-environment-variable-into-a-workspace-container/#mounting-a-git-credential-store-into-a-workspace-container_che

.git-credentialsのフォーマット
https://git-scm.com/docs/git-credential-store#_storage_format

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1