Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ansible/roles/dev-desktop/files/refresh-crates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -euxo pipefail

cd /home/crates-io-downloader

# Refresh crates.io index
if [ -d crates.io-index ]; then
git -C crates.io-index pull --force
else
git clone https://github.com/rust-lang/crates.io-index.git
fi

# Re-fetch latest copies of crates into ./all-crates.
# This will automatically skip downloading existing crates.
./.cargo/bin/get-all-crates --index ./crates.io-index --out /var/cache/all-crates
48 changes: 48 additions & 0 deletions ansible/roles/dev-desktop/tasks/crates-io.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- name: Set up user for crates.io downloads
user:
name: crates-io-downloader
state: present

- name: Install Rust for crates-io-downloader
shell: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
become_user: crates-io-downloader

- name: Install get-all-crates
shell: "PATH=$PATH:$HOME/.cargo/bin cargo install get-all-crates --version 0.1.22 --locked"
become_user: crates-io-downloader

- name: Set up get-all-crates systemd service
template:
src: get-all-crates.service.j2
dest: /etc/systemd/system/get-all-crates.service
mode: 0644
register: get_all_crates_service

- name: Set up get-all-crates systemd timer
template:
src: get-all-crates.timer.j2
dest: /etc/systemd/system/get-all-crates.timer
mode: 0644
register: get_all_crates_timer

- name: reload systemd
systemd:
daemon_reload: true
when: get_all_crates_timer is changed or get_all_crates_service is changed

- name: setup all-crates directory
file:
path: /var/cache/all-crates
state: directory
owner: crates-io-downloader
group: crates-io-downloader
mode: 0755

- name: Set up get-all-crates script
copy:
src: files/refresh-crates.sh
dest: /home/crates-io-downloader/refresh-crates.sh
owner: crates-io-downloader
mode: u+x
1 change: 1 addition & 0 deletions ansible/roles/dev-desktop/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---

- include_tasks: crates-io.yml
- include_tasks: cloud_provider.yml
- include_tasks: oom.yml
- include_tasks: dependencies.yml
Expand Down
8 changes: 8 additions & 0 deletions ansible/roles/dev-desktop/templates/get-all-crates.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Refresh crates.io export

[Service]
Type=oneshot
User=crates-io-downloader
ExecStart=/home/crates-io-downloader/refresh-crates.sh
MemoryMax=80%
9 changes: 9 additions & 0 deletions ansible/roles/dev-desktop/templates/get-all-crates.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Refresh crates.io export timer

[Timer]
OnCalendar=daily
RandomizedDelaySec=3600

[Install]
#WantedBy=timers.target
Loading