From d45a5714034a5fda82e3ce47c7aae865e31601a0 Mon Sep 17 00:00:00 2001 From: Erik-jan Riemers Date: Jan 16 2020 15:03:55 +0000 Subject: Merge pull request #97 from agimenez/runners-cache-gcs Allow GCS cache configuration --- diff --git a/defaults/main.yml b/defaults/main.yml index 533e8ca..1fa1e70 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -72,7 +72,7 @@ gitlab_runner_runners: # ssh_identity_file: '' # # Cache type - # cache_type: 's3' + # cache_type: 's3|gcs' # # Cache path # cache_path: prefix/key @@ -98,6 +98,18 @@ gitlab_runner_runners: # Cache S3 insecure # cache_s3_insecure: false # + # Cache GCS Bucket name + # cache_gcs_bucket_name: "my-bucket" + # + # Cache GCS CredentialsFile + # cache_gcs_credentials_file: "/path/to/key_file.json" + # + # Cache GCS Access ID + # cache_gcs_access_id: "cache-access-account@project.iam.gserviceaccount.com" + # + # Cache GCS Private Key + # cache_gcs_private_key: "-----BEGIN PRIVATE KEY-----\nXXXXXX\n-----END PRIVATE KEY-----\n" + # # Builds directory # builds_dir: '/builds_dir' # diff --git a/tasks/update-config-runner.yml b/tasks/update-config-runner.yml index 795ea97..61523a1 100644 --- a/tasks/update-config-runner.yml +++ b/tasks/update-config-runner.yml @@ -136,6 +136,17 @@ check_mode: no notify: restart_gitlab_runner +- name: Set cache gcs section + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*\[runners\.cache\.gcs\]' + line: ' [runners.cache.gcs]' + state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + - name: Set cache type option lineinfile: dest: "{{ temp_runner_config.path }}" @@ -238,6 +249,52 @@ notify: restart_gitlab_runner +#### [runners.cache.gcs] section #### +- name: Set cache gcs bucket name + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*BucketName =' + line: ' BucketName = {{ gitlab_runner.cache_gcs_bucket_name|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs credentials file + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*CredentialsFile =' + line: ' CredentialsFile = {{ gitlab_runner.cache_gcs_credentials_file|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_credentials_file is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs access id + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*AccessID =' + line: ' AccessID = {{ gitlab_runner.cache_gcs_access_id|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_access_id is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs private key + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*PrivateKey =' + line: ' PrivateKey = {{ gitlab_runner.cache_gcs_private_key|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_private_key is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + + #### [runners.ssh] section ##### - name: Set ssh user option lineinfile: diff --git a/tests/vars/default.yml b/tests/vars/default.yml index 8cf9dcd..5e2b71d 100644 --- a/tests/vars/default.yml +++ b/tests/vars/default.yml @@ -28,4 +28,19 @@ gitlab_runner_runners: cache_s3_secret_key: mysecret-key cache_s3_bucket_name: build-cache-bucket cache_s3_insecure: false + + - name: 'vagrant-docker-cache-gcs' + executor: docker + docker_image: 'docker:stable' + tags: + - node + - ruby + - mysql + - cache + cache_type: gcs + cache_shared: true + cache_gcs_bucket_name: gcs-cache-bucket + cache_gcs_credentials_file: '/etc/gitlab-runner/credentials.json' + cache_gcs_access_id: 'cache-access-account@project.iam.gserviceaccount.com' + cache_gcs_private_key: "-----BEGIN PRIVATE KEY-----\nXXXXXX\n-----END PRIVATE KEY-----\n" ...