Skip to content

Commit

Permalink
Merge pull request #97 from agimenez/runners-cache-gcs
Browse files Browse the repository at this point in the history
Allow GCS cache configuration
  • Loading branch information
riemers committed Jan 16, 2020
2 parents c8569c7 + 003933f commit d45a571
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
14 changes: 13 additions & 1 deletion defaults/main.yml
Expand Up @@ -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
Expand All @@ -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'
#
Expand Down
57 changes: 57 additions & 0 deletions tasks/update-config-runner.yml
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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 }}'

This comment has been minimized.

Copy link
@thiagoalmeidasa

thiagoalmeidasa Jan 17, 2020

Contributor

This line is removing BucketName from runners.cache.s3 section even without any gcs configuration being provided.
I'll try to breakdown these sections in a more modular way and implement a few tests during the weekend.

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:
Expand Down
15 changes: 15 additions & 0 deletions tests/vars/default.yml
Expand Up @@ -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"
...

0 comments on commit d45a571

Please sign in to comment.