Skip to content

Commit 63220d7

Browse files
authored
Merge 9b62fdd into 299ee83
2 parents 299ee83 + 9b62fdd commit 63220d7

36 files changed

+947
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[defaults]
2+
forks = 10
3+
inventory = hosts.yaml
4+
retry_files_enabled = False
5+
interpreter_python=/usr/bin/python3
6+
callbacks_enabled = ansible.posix.profile_tasks
7+
stdout_callback = yaml
8+
stderr_callback = yaml
9+
check_mode_markers = true
10+
show_per_host_start = false
11+
show_custom_stats = true
12+
13+
roles_path = ./roles:
14+
15+
[ssh_connection]
16+
pipelining = true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: install bazel-remote
3+
hosts: bazel_remote_servers
4+
become: true
5+
roles:
6+
- bazel-remote
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bazel_remote_htpasswd_lockbox_secret_id: e6qe20m48alkec2btn5v
2+
bazel_remote_instances:
3+
- name: ccache
4+
config:
5+
dir: /mnt/ccache/cache/
6+
max_size: 175
7+
http_address: 0.0.0.0:8080
8+
- name: ya-cache
9+
config:
10+
dir: /mnt/ya-cache/cache/
11+
max_size: 4000
12+
http_address: 0.0.0.0:8081
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bazel_remote_servers:
2+
hosts:
3+
cachesrv:
4+
ansible_host: 158.160.147.211
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bazel_remote_version: 2.4.3
2+
bazel_remote_config_default:
3+
disable_http_ac_validation: true
4+
allow_unauthenticated_reads: true
5+
htpasswd_file: /home/bazel-remote/htpasswd
6+
grpc_address: none
7+
8+
bazel_remote_instances: []
9+
bazel_remote_htpasswd_lockbox_secret_id: ~
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: restart-bazel-remote
2+
ansible.builtin.systemd_service:
3+
name: "bazel-remote@{{ item.name }}"
4+
enabled: true
5+
state: restarted
6+
loop: "{{ bazel_remote_instances }}"
7+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- name: ensure YC_TOKEN variable exists
2+
ansible.builtin.assert:
3+
that:
4+
- lookup('env', 'YC_TOKEN') != ''
5+
msg: |
6+
Please set YC_TOKEN environment variable, example: export YC_TOKEN=$(yc --profile ydbtech iam create-token)
7+
8+
- name: get htpasswd content
9+
delegate_to: 127.0.0.1
10+
become: false
11+
ansible.builtin.uri:
12+
url: "https://payload.lockbox.api.cloud.yandex.net/lockbox/v1/secrets/{{ bazel_remote_htpasswd_lockbox_secret_id }}/payload"
13+
headers:
14+
Authorization: "Bearer {{ lookup('env', 'YC_TOKEN') }}"
15+
register: htpasswd
16+
check_mode: no
17+
18+
- name: extract htpasswd content
19+
ansible.builtin.set_fact:
20+
htpasswd_content: "{{ (htpasswd.json.entries | items2dict('key', 'textValue')).htpasswd }}"
21+
22+
- name: create htpasswd
23+
ansible.builtin.copy:
24+
dest: /home/bazel-remote/htpasswd
25+
content: "{{ htpasswd_content }}"
26+
mode: 0600
27+
owner: bazel-remote
28+
group: bazel-remote
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- name: download bazel-remote
2+
ansible.builtin.get_url:
3+
url: "https://github.com/buchgr/bazel-remote/releases/download/v{{ bazel_remote_version }}/bazel-remote-{{ bazel_remote_version }}-linux-x86_64"
4+
dest: /usr/local/bin/bazel-remote
5+
mode: '0755'
6+
7+
- name: add bazel-remote group
8+
ansible.builtin.group:
9+
name: bazel-remote
10+
system: true
11+
12+
- name: add bazel-remote user
13+
ansible.builtin.user:
14+
name: bazel-remote
15+
group: bazel-remote
16+
system: true
17+
18+
- name: create folders
19+
ansible.builtin.file:
20+
path: "{{ item.config.dir }}"
21+
state: directory
22+
mode: 0755
23+
owner: bazel-remote
24+
group: bazel-remote
25+
loop: "{{ bazel_remote_instances }}"
26+
27+
- ansible.builtin.include_tasks: htpasswd.yaml
28+
29+
- name: configure instances
30+
ansible.builtin.template:
31+
src: bazel-remote.yaml.j2
32+
dest: "/usr/local/etc/bazel-remote-{{ item.name }}.yaml"
33+
notify:
34+
- restart-bazel-remote
35+
loop: "{{ bazel_remote_instances }}"
36+
37+
- name: configure systemd unit
38+
ansible.builtin.template:
39+
src: bazel-remote.service.j2
40+
dest: "/etc/systemd/system/bazel-remote@.service"
41+
register: systemd_unit
42+
notify:
43+
- restart-bazel-remote
44+
45+
- name: reload systemd daemon
46+
ansible.builtin.systemd_service:
47+
daemon-reload: true
48+
when: systemd_unit.changed
49+
50+
- name: enable systemd units
51+
ansible.builtin.systemd_service:
52+
name: "bazel-remote@{{ item.name }}"
53+
enabled: true
54+
loop: "{{ bazel_remote_instances }}"
55+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[Unit]
2+
Description=bazel-remote cache (%i instance)
3+
4+
[Service]
5+
# Assuming you have created a bazel-remote user and group, that can write
6+
# to the cache directory specified in ExecStart below:
7+
User=bazel-remote
8+
Group=bazel-remote
9+
10+
# We need to have a lot of files open at once.
11+
LimitNOFILE=1000000
12+
13+
# Try to avoid "runtime: failed to create new OS thread (have 2458 already; errno=11)"
14+
# errors. You can check if this worked by running "systemctl status bazel-remote"
15+
# and see if there's a "Tasks: 18 (limit: 2457)" line (hopefully not, after adding this).
16+
LimitNPROC=infinity
17+
TasksMax=infinity
18+
19+
Restart=on-failure
20+
21+
Environment=GODEBUG=gctrace=1
22+
23+
ExecStart=/usr/local/bin/bazel-remote --config_file /usr/local/etc/bazel-remote-%i.yaml
24+
25+
[Install]
26+
WantedBy=multi-user.target
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Bazel remote config for {{ item.name }}, generated using ansible. Please don't modify by hand.
2+
{{ (bazel_remote_config_default | ansible.builtin.combine(item.config)) | to_nice_yaml }}

0 commit comments

Comments
 (0)