Skip to content

Commit

Permalink
Add fnm role and update linux runner path to look in .fnm (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender authored Oct 31, 2024
1 parent 36846a8 commit 96327eb
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fnm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
user: ubuntu
group: ubuntu

fnm_version: v1.37.2

# Optional, will skip installing any version if left empty
fnm_install_node_version: ""
20 changes: 20 additions & 0 deletions fnm/tasks/install-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- name: Check if a file exists with a wildcard pattern
stat:
path: /home/ubuntu/.fnm/node-versions/v{{ fnm_install_node_version }}*
register: fnm_version_check

- ansible.builtin.debug:
var: fnm_version_check

- name: Install desired version of node
become: yes
become_user: "{{ user }}"
ansible.builtin.command: fnm install {{ fnm_install_node_version }} --fnm-dir /home/{{ user }}/.fnm
when: not fnm_version_check.stat.exists

- name: Set default version of node
become: yes
become_user: "{{ user }}"
ansible.builtin.command: fnm default {{ fnm_install_node_version }} --fnm-dir /home/{{ user }}/.fnm
args:
creates: /home/{{ user }}/.fnm/aliases/default/bin/node
60 changes: 60 additions & 0 deletions fnm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
- name: Load architecture specific vars
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- '{{ansible_architecture}}.yml'
paths:
- 'vars'

- name: Install Common Deps
become: true
ansible.builtin.apt:
name:
- xz-utils
state: present
update_cache: true
cache_valid_time: 300
register: apt_action
retries: 100
until: apt_action is success or ('Failed to lock apt for exclusive operation' not in apt_action.msg and '/var/lib/dpkg/lock' not in apt_action.msg)

- name: Download the FNM release binary
become: yes
become_user: "{{ user }}"
get_url:
url: https://github.com/Schniz/fnm/releases/download/{{ fnm_version }}/fnm-{{ fnm_suffix }}.zip
dest: "/home/{{ user }}/fnm-{{ fnm_version }}.zip"
mode: 0644

- name: Unarchive FNM
become: yes
become_user: "{{ user }}"
ansible.builtin.unarchive:
src: "/home/{{ user }}/fnm-{{ fnm_version }}.zip"
dest: "/usr/local/bin/"
remote_src: yes
creates: "/usr/local/bin/fnm"

- name: Ensure FNM has the correct permissions
become: yes
ansible.builtin.file:
path: "/usr/local/bin/fnm"
state: file
mode: '0755'

- name: Ensure fnm is configured in the shell
become: yes
become_user: "{{ user }}"
ansible.builtin.lineinfile:
path: /home/ubuntu/.bashrc
search_string: 'fnm env'
line: 'eval "$(fnm env --fnm-dir /home/{{ user }}/.fnm)"'
owner: ubuntu
group: ubuntu
mode: '0644'

- name: Install node
when: fnm_install_node_version != ""
ansible.builtin.include_tasks: "install-node.yml"
2 changes: 2 additions & 0 deletions fnm/vars/aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
fnm_suffix: "arm64"
2 changes: 2 additions & 0 deletions fnm/vars/x86_64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
fnm_suffix: "linux"
1 change: 1 addition & 0 deletions linux-runner/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ runner_post_run_exclusions:
- .bash_logout
- .bashrc
- .profile
- .fnm
10 changes: 10 additions & 0 deletions linux-runner/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
mode: "0644"
notify: restart-runner

- name: Add the .path file
become: yes
ansible.builtin.template:
src: "path"
dest: "{{ runner_directory_path }}/.path"
owner: "{{ runner_user }}"
group: "{{ runner_group }}"
mode: "0644"
notify: restart-runner

- name: Ensure the service is in desired boot and current state
become: true
ansible.builtin.systemd:
Expand Down
1 change: 1 addition & 0 deletions linux-runner/templates/path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/ubuntu/.fnm/aliases/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

0 comments on commit 96327eb

Please sign in to comment.