almaops.ct_gitlab_runner
almaops.ct_gitlab_runner
この役割は、Dockerコンテナ内にGitLabランナーをデプロイし、GitLabに登録します。
役割の変数
ct_gitlab_runner_name: ランナーのページで表示される名前。デフォルトは "{{ inventory_hostname }}" です。
ct_gitlab_runner_ct_name: コンテナ名。デフォルトは "gitlab-runner" で、同じホストで複数のランナーを実行する場合は変更してください。
ct_gitlab_runner_registration_token: ランナーの登録に必要なトークン。特定のランナーに対してはプロジェクトから取得でき、共有ランナーには管理パネルから取得できます。必須のパラメータで、デフォルトはありません。
ct_gitlab_runner_coordinator_url: GitLabのアドレス。デフォルトは "https://gitlab.com/ci" に設定されています。オンプレミスのGitLabを使用している場合は変更してください。
ct_gitlab_runner_tags: タグ;デフォルトは [] です。
ct_gitlab_runner_executor: 実行環境;デフォルトは "docker" で、最も便利な方法です。他の実行環境はテストされていません。
ct_gitlab_runner_parallel_builds_number: デフォルトは "1" です。
ct_gitlab_runner_run_untagged: ランナーがタグなしのジョブを実行する必要があるか指定します。デフォルトは "true" です。
ct_gitlab_runner_docker_image: デフォルトは "alpine" です。
ct_gitlab_runner_path_srv_dir: サービス構成を保存する場所を決定する基本ディレクトリ。デフォルトは "/srv" です。
ct_gitlab_runner_path_cfg_dir: サービス構成が保存される最終ディレクトリ。デフォルトは "{{ ct_gitlab_runner_path_srv_dir }}/{{ ct_gitlab_runner_ct_name }}/config" です。
ct_gitlab_runner_path_cfg: ランナーの構成ファイル。デフォルトは "{{ ct_gitlab_runner_path_cfg_dir }}/config.toml" で、変更しないでください。本当に config.toml です。
ct_gitlab_runner_ct_image_tag: ランナーのバージョン、つまりGitLabランナーのイメージタグ。デフォルトは "alpine" です。
ct_gitlab_runner_ct_image: GitLabランナーコンテナのイメージ。デフォルトは "gitlab/gitlab-runner:{{ ct_gitlab_runner_ct_image_tag }}" です。カスタムビルドが必要な場合のみ変更してください。
ct_gitlab_runner_ct_restart_policy: コンテナの再起動ポリシー。デフォルトは "always" です。
ct_gitlab_runner_ct_state: デプロイ後のコンテナの状態。デフォルトは "started" です。
ct_gitlab_runner_ct_restart: デプロイ後にコンテナを再起動する必要があるか。デフォルトは "false" です。
ct_gitlab_runner_ct_pull: デプロイ時にイメージをプルする必要があるか。デフォルトは "false" です。
ct_gitlab_runner_ct_recreate: コンテナを再作成する必要があるか。デフォルトは "false" です。
ct_gitlab_runner_cache_s3_enabled: S3/Minioでキャッシュを使用するか。デフォルトは false です。
ct_gitlab_runner_cache_s3_server_address: S3が有効な場合に必須の項目。デフォルトはありません。
ct_gitlab_runner_cache_s3_access_key: S3が有効な場合に必須の項目。デフォルトはありません。
ct_gitlab_runner_cache_s3_secret_key: S3が有効な場合に必須の項目。デフォルトはありません。
ct_gitlab_runner_force_reg: このランナーを再登録したい場合。デフォルトは false です。
ct_gitlab_runner_docker_volumes: Docker実行者が実行するコンテナの追加マウント。デフォルトは [] で、docker.sockを渡したり、/cacheボリュームをマウントする場合に便利です。
ct_gitlab_runner_dind_enabled: Dockerコンテナを特権モードで実行する必要がある場合は true に設定します。デフォルトは false です。
ct_gitlab_runner_ct_volumes: デフォルトでは、ランナーコンテナに構成ディレクトリをマウントします。つまり、[ "{{ ct_gitlab_runner_path_cfg_dir }}:/etc/gitlab-runner:rw" ] です。
ct_gitlab_runner_dond_enabled: true(これがデフォルトの場合)に設定されている場合、ランナーコンテナに /var/run/docker.sock も渡します。
もっと興味深い変数がいくつかあります。それらを確認してください:defaults/main.yml
例のプレイブック
- hosts:
- gitlab_runners
become: true
vars:
# 共通設定
ct_gitlab_runner_ct_image_tag: "v14.8.1"
ct_gitlab_runner_cache_s3_enabled: true
ct_gitlab_runner_cache_s3_server_address: "{{ minio_bind_ip }}:{{ minio_bind_port }}"
ct_gitlab_runner_cache_s3_access_key: "{{ minio_access_key }}"
ct_gitlab_runner_cache_s3_secret_key: "{{ minio_secret_key }}"
ct_gitlab_runner_name: "{{ runner_name }}_{{ inventory_hostname }}"
gitlab_runner_ct_name: "gitlab-runner_{{ runner_name }}"
# トークン
main_registration_token: "<...>"
proj_registration_token: "<...>"
roles:
- role: almaops.ct_gitlab_runner
tags:
- runner-tag-common
vars:
runner_name: "common"
ct_gitlab_runner_registration_token: "{{ main_registration_token }}"
ct_gitlab_runner_parallel_builds_number: "3"
ct_gitlab_runner_tags:
- common
- role: almaops.ct_gitlab_runner
tags:
- runner-tag-proj
vars:
runner_name: "proj"
ct_gitlab_runner_registration_token: "{{ proj_registration_token }}"
ct_gitlab_runner_parallel_builds_number: "1"
ct_gitlab_runner_run_untagged: "false"
ct_gitlab_runner_tags:
- proj
ライセンス
MIT
著者情報
ドミトリー・カシン, freehck@freehck.com
