GitLab統合
コードの変更をプッシュすると、環境を自動的に構築およびデプロイするようにGitLab リポジトリを設定できます。 この統合により、GitLab リポジトリとAdobe Commerce on cloud infrastructure アカウントが同期されます。
この統合により、次のことが可能になります。
- ブランチの作成時に環境を作成する
- プルリクエストをマージするときに環境を再デプロイする
- ブランチを削除するときに環境を削除する
プロセスを続行するには、GitLab トークンとWebhookを取得する必要があります。
前提条件
- Adobe Commerce オンクラウド インフラストラクチャ プロジェクトへの管理者アクセス
- ローカル環境の
magento-cloudCLI ツール - GitLab アカウント
- GitLab リポジトリへの書き込みアクセスを持つGitLab個人アクセストークン。選択したスコープは
apiおよびread_repository以上である必要があります。
リポジトリの準備
既存の環境からAdobe Commerce on cloud infrastructure プロジェクトを複製し、同じブランチ名を保持しながら、プロジェクトのブランチを新しい空のGitLab リポジトリに移行します。 同一のGit ツリーを保持することは 重要 であるため、Adobe Commerce on cloud infrastructure プロジェクトの既存の環境やブランチが失われることはありません。
-
ターミナルから、Adobe Commerce on cloud infrastructure プロジェクトにログインします。
code language-bash magento-cloud login -
プロジェクトのリストを作成し、プロジェクト IDをコピーします。
code language-bash magento-cloud project:list -
プロジェクトをローカル環境に複製します。
code language-bash magento-cloud project:get <project-id> -
GitLab リポジトリをリモートとして追加します(GitLabがSaaS バージョンで使用されている場合)。
code language-bash git remote add origin git@gitlab.com:<user-name>/<repo-name>.gitリモート接続の既定の名前は
originまたはmagentoです。originが存在する場合は、別の名前を選択するか、既存の参照の名前を変更または削除できます。 git-remote ドキュメント を参照してください。 -
GitLab リモートが正しく追加されていることを確認します。
code language-bash git remote -v期待される応答:
code language-none origin git@gitlab.com:<user-name>/<repo-name>.git (fetch) origin git@gitlab.com:<user-name>/<repo-name>.git (push) -
プロジェクトファイルを新しいGitLab リポジトリにプッシュします。 すべてのブランチ名を同じにしておくことを忘れないでください。
code language-bash git push -u origin master新しいGitLab リポジトリで始める場合は、リモートリポジトリがローカルコピーと一致しないため、
-fオプションを使用する必要がある場合があります。 -
GitLab リポジトリにすべてのプロジェクトファイルが含まれていることを確認します。
GitLab統合を有効にする
magento-cloud integration コマンドを使用してGitLab統合を有効にし、GitLab Webhookのペイロード URLを取得して、GitLabからAdobe Commerce on cloud infrastructure プロジェクトに更新を送信します。
magento-cloud integration:add --type=gitlab --project=<project-ID> --token=<your-GitLab-token> [--base-url=<GitLab-url> --server-project=<GitLab-project> --build-merge-requests={true|false} --merge-requests-clone-parent-data={true|false} --fetch-branches={true|false} --prune-branches={true|false}]
<project-ID><your-GitLab-token>--base-urlhttps://gitlab.com/ GitLabがSaaS バージョンで使用されている場合)--server-project--build-merge-requeststrue)--merge-requests-clone-parent-datatrue)--fetch-branchestrueから)すべてのブランチを取得できるようにするオプション パラメーター(デフォルト)--prune-branchestrue既定)に存在しないブランチを削除するように指示するオプション パラメーターmagento-cloud integration コマンドは、Adobe Commerce on cloud infrastructure プロジェクトの_all_ コードを、GitLab リポジトリのコードで上書きします。 これには、production ブランチを含むすべてのブランチが含まれます。 この操作は瞬時におこなわれ、元に戻すことはできません。 ベストプラクティスとして、GitLab統合を追加する前に、Adobe Commerce on cloud infrastructure プロジェクトからすべてのブランチを複製し、GitLab リポジトリにプッシュすることが重要です。GitLab統合を有効にするには:
-
ターミナルから、GitLab統合をAdobe Commerce on cloud infrastructure プロジェクトに追加します。
code language-bash magento-cloud integration:add --type gitlab --project=3txxjf32gtryos --token=qVUfeEn4ouze7A7JH --base-url=https://gitlab.com/ --server-project=my-agency/project-name --build-merge-requests=false --merge-requests-clone-parent-data=false --fetch-branches=true --prune-branches=true -
プロンプトが表示されたら、
yと入力して統合を追加します。code language-none Warning: adding a 'gitlab' integration will automatically synchronize code from the external Git repository. This means it can overwrite all the code in your project. Are you sure you want to continue? [y/N] y -
戻り出力で表示される フック URL をコピーします。
code language-none Hook URL: https://eu-3.magento.cloud/api/projects/3txxjf32gtryos/integrations/eolmpfizzg9lu/hook Created integration eolmpfizzg9lu (type: gitlab) +----------------------------------+---------------------------------------------------------------------------------------+ | Property | Value | +----------------------------------+---------------------------------------------------------------------------------------+ | id | <integration-id> | | type | gitlab | | token | ****** | | base_url | https://gitlab.com/ | | project | my-agency/project-name | | fetch_branches | true | | prune_branches | true | | build_merge_requests | false | | merge_requests_clone_parent_data | false | | hook_url | https://eu-3.magento.cloud/api/projects/<project-id>/integrations/<integration-id>/hook | +----------------------------------+---------------------------------------------------------------------------------------+
GitLabでWebhookを追加する
プッシュリクエストや結合リクエストなどのイベントをCloud Git サーバーと通信するには、GitLab リポジトリ用のWebhook🔗を作成する必要があります
-
GitLab リポジトリで、「設定」タブをクリックします。
-
左側のナビゲーションバーで、Webhookをクリックします。
-
Webhook フォームで、次のフィールドを編集します。
- URL: GitLab統合を有効にしたときに返された
Hook URLを入力します。 - 秘密鍵:必要に応じて確認秘密鍵を入力します。
- トリガー: ニーズに応じて
Merge request eventsまたはPush eventsを確認してください。 - SSL検証を有効にする:このオプションを選択する必要があります。
- URL: GitLab統合を有効にしたときに返された
-
「Webhookを追加」をクリックします。
統合をテストする
GitLab統合を設定した後、magento-cloud CLIを使用して統合が動作していることを確認できます。
magento-cloud integration:validate
GitLab リポジトリに簡単な変更をプッシュしてテストすることもできます。
-
テストファイルを作成します。
code language-bash touch test.md -
変更をコミットしてGitLab リポジトリにプッシュします。
code language-bash git add . && git commit -m "Testing GitLab integration" && git push -
Cloud Consoleにログインし、コミットメッセージが表示され、プロジェクトがデプロイされていることを確認します。
Cloud ブランチの作成
magento-cloud CLI environment:push コマンドを使用して、新しい環境を作成し、アクティブ化します。 クラウドブランチの作成を参照してください。
統合の削除
magento-cloud CLI integration:delete コマンドを使用して、統合を削除します。 統合の削除を参照してください。