From 079f3164ad2c57be37e09f75e8c76bd1db4cce45 Mon Sep 17 00:00:00 2001 From: Aki Kanellis Date: Mon, 1 Jan 2024 21:21:19 +0000 Subject: [PATCH] feat: replace asdf with rtx (#402) --- .envrc | 1 - README.md | 2 +- ansible/roles/all/tasks/install-asdf.yml | 21 ---- ...tilities.yml => install-rtx-utilities.yml} | 12 +- ansible/roles/all/tasks/install-rtx.yml | 17 +++ ansible/roles/all/tasks/main.yml | 8 +- ansible/roles/all/tasks/setup-zsh.yml | 1 - .../all/templates/users/aki/zsh/env.zsh.j2 | 1 - .../templates/users/aki/zsh/functions.zsh.j2 | 9 +- .../all/templates/users/aki/zsh/zshrc.j2 | 6 +- ansible/roles/all/vars/main.yml | 11 +- ansible/roles/common/tasks/asdf.yml | 110 ------------------ ansible/roles/common/tasks/npm.yml | 14 ++- ansible/roles/common/tasks/rtx.yml | 62 ++++++++++ .../workstations/tasks/install-dev-tools.yml | 22 +++- docs/DEVELOPERS_GUIDE.md | 2 +- justfile | 2 +- 17 files changed, 133 insertions(+), 168 deletions(-) delete mode 100644 .envrc delete mode 100644 ansible/roles/all/tasks/install-asdf.yml rename ansible/roles/all/tasks/{install-asdf-utilities.yml => install-rtx-utilities.yml} (63%) create mode 100644 ansible/roles/all/tasks/install-rtx.yml delete mode 100644 ansible/roles/common/tasks/asdf.yml create mode 100644 ansible/roles/common/tasks/rtx.yml diff --git a/.envrc b/.envrc deleted file mode 100644 index a63eb9626..000000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use asdf diff --git a/README.md b/README.md index f4f0bb10e..d094b763d 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ fully automated, seamless CI/CD pipeline. Install the following software - [just](https://github.com/casey/just) -- [asdf](https://github.com/asdf-vm/asdf) +- [rtx](https://github.com/jdx/rtx) - [![VirtualBox](docs/images/virtualbox.svg) VirtualBox](https://www.virtualbox.org) ### Usage diff --git a/ansible/roles/all/tasks/install-asdf.yml b/ansible/roles/all/tasks/install-asdf.yml deleted file mode 100644 index 84a791cf0..000000000 --- a/ansible/roles/all/tasks/install-asdf.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Clone asdf - become_user: aki - ansible.builtin.git: - repo: https://github.com/asdf-vm/asdf.git - dest: ~/.asdf - version: "{{ asdf_version }}" - single_branch: true - force: true - register: result - retries: 10 - delay: 2 - until: result is success - -- name: Install direnv - ansible.builtin.import_role: - name: common - tasks_from: asdf - vars: - asdf_plugins: - - name: direnv diff --git a/ansible/roles/all/tasks/install-asdf-utilities.yml b/ansible/roles/all/tasks/install-rtx-utilities.yml similarity index 63% rename from ansible/roles/all/tasks/install-asdf-utilities.yml rename to ansible/roles/all/tasks/install-rtx-utilities.yml index 80ecd5a47..0929e59a6 100644 --- a/ansible/roles/all/tasks/install-asdf-utilities.yml +++ b/ansible/roles/all/tasks/install-rtx-utilities.yml @@ -1,23 +1,23 @@ --- -- name: Install asdf plugins +- name: Install rtx plugins ansible.builtin.import_role: name: common - tasks_from: asdf + tasks_from: rtx vars: - asdf_plugins: + rtx_plugins: - name: nodejs - name: python -- name: Install tldr +- name: Install Node utilities ansible.builtin.import_role: name: common tasks_from: npm vars: package_names: [tldr] -- name: Install pip_search +- name: Install Python utilities ansible.builtin.import_role: name: common tasks_from: pip vars: - package_names: pip_search + package_names: [pip_search] diff --git a/ansible/roles/all/tasks/install-rtx.yml b/ansible/roles/all/tasks/install-rtx.yml new file mode 100644 index 000000000..4c6a82d1e --- /dev/null +++ b/ansible/roles/all/tasks/install-rtx.yml @@ -0,0 +1,17 @@ +--- +- name: Install rtx + ansible.builtin.get_url: + url: + "https://github.com/jdx/rtx/releases/download/\ + {{ rtx_version }}/\ + rtx-\ + {{ rtx_version }}-\ + {{ ansible_system | lower }}-{{ rtx_architecture }}" + dest: /home/aki/.local/bin/rtx + owner: aki + group: aki + mode: 0700 + register: result + retries: 10 + delay: 2 + until: result is success diff --git a/ansible/roles/all/tasks/main.yml b/ansible/roles/all/tasks/main.yml index 5d40db0fd..2454b9cf7 100644 --- a/ansible/roles/all/tasks/main.yml +++ b/ansible/roles/all/tasks/main.yml @@ -26,8 +26,8 @@ - name: Setup ZSH ansible.builtin.import_tasks: setup-zsh.yml -- name: Install asdf - ansible.builtin.import_tasks: install-asdf.yml +- name: Install rtx + ansible.builtin.import_tasks: install-rtx.yml -- name: Install asdf utilities - ansible.builtin.import_tasks: install-asdf-utilities.yml +- name: Install rtx utilities + ansible.builtin.import_tasks: install-rtx-utilities.yml diff --git a/ansible/roles/all/tasks/setup-zsh.yml b/ansible/roles/all/tasks/setup-zsh.yml index 57dae11cf..68787751e 100644 --- a/ansible/roles/all/tasks/setup-zsh.yml +++ b/ansible/roles/all/tasks/setup-zsh.yml @@ -10,7 +10,6 @@ antigen_theme: name: robbyrussell antigen_bundles: - - name: asdf - name: aws - name: brew - name: dirhistory diff --git a/ansible/roles/all/templates/users/aki/zsh/env.zsh.j2 b/ansible/roles/all/templates/users/aki/zsh/env.zsh.j2 index b2c82d887..d54209939 100644 --- a/ansible/roles/all/templates/users/aki/zsh/env.zsh.j2 +++ b/ansible/roles/all/templates/users/aki/zsh/env.zsh.j2 @@ -15,5 +15,4 @@ export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" export _ZO_FZF_OPTS="--preview 'less {2}' --preview-window 'wrap'" -export DIRENV_LOG_FORMAT="" export ASDF_GROOVY_DISABLE_JAVA_HOME_EXPORT=true diff --git a/ansible/roles/all/templates/users/aki/zsh/functions.zsh.j2 b/ansible/roles/all/templates/users/aki/zsh/functions.zsh.j2 index 22c1442c2..9cb748bb0 100644 --- a/ansible/roles/all/templates/users/aki/zsh/functions.zsh.j2 +++ b/ansible/roles/all/templates/users/aki/zsh/functions.zsh.j2 @@ -37,11 +37,10 @@ function update() { echo "brew updated!" fi - if command_exists asdf; then - echo "Updating asdf..." - asdf update - asdf plugin update --all - echo "asdf updated!" + if command_exists rtx; then + echo "Updating rtx..." + rtx upgrade --yes + echo "rtx updated!" fi if command_exists npm; then diff --git a/ansible/roles/all/templates/users/aki/zsh/zshrc.j2 b/ansible/roles/all/templates/users/aki/zsh/zshrc.j2 index ac9f8e9c6..e740b1372 100644 --- a/ansible/roles/all/templates/users/aki/zsh/zshrc.j2 +++ b/ansible/roles/all/templates/users/aki/zsh/zshrc.j2 @@ -13,8 +13,8 @@ source ~/.zsh/options.zsh source ~/.zsh/starship.zsh source ~/.zsh/zoxide.zsh -# Created from `asdf direnv setup --shell zsh --version system` -# See: https://github.com/asdf-community/asdf-direnv#setup -source "${XDG_CONFIG_HOME:-$HOME/.config}/asdf-direnv/zshrc" +# Created from `echo 'eval "$(rtx activate zsh)"' >> "${ZDOTDIR-$HOME}/.zshrc"` +# See: https://rtx.jdx.dev/getting-started.html#zsh +eval "$(rtx activate zsh)" source ~/.zsh/extra-zshrc-config.zsh diff --git a/ansible/roles/all/vars/main.yml b/ansible/roles/all/vars/main.yml index 9dad4ba45..1c0a713fd 100644 --- a/ansible/roles/all/vars/main.yml +++ b/ansible/roles/all/vars/main.yml @@ -1,7 +1,4 @@ --- -# renovate: datasource=github-releases depName=asdf-vm/asdf -asdf_version: v0.13.1 - # renovate: datasource=github-releases depName=sharkdp/bat bat_version: v0.24.0 architecture_to_bat_architecture: @@ -70,6 +67,14 @@ architecture_to_lazygit_architecture: lazygit_architecture: >- {{ architecture_to_lazygit_architecture[ansible_architecture] }} +# renovate: datasource=github-releases depName=jdx/rtx +rtx_version: v2023.12.40 +architecture_to_rtx_architecture: + x86_64: x64 + armv7l: armv7 +rtx_architecture: >- + {{ architecture_to_rtx_architecture[ansible_architecture] }} + # renovate: datasource=github-releases depName=ajeetdsouza/zoxide zoxide_version: v0.9.2 architecture_to_zoxide_architecture: diff --git a/ansible/roles/common/tasks/asdf.yml b/ansible/roles/common/tasks/asdf.yml deleted file mode 100644 index a19b59a82..000000000 --- a/ansible/roles/common/tasks/asdf.yml +++ /dev/null @@ -1,110 +0,0 @@ ---- -- name: Set plugin names - ansible.builtin.set_fact: - asdf_plugins_names: "{{ asdf_plugins | map(attribute='name') | list }}" - -- name: Install "direnv" asdf plugin dependencies - ansible.builtin.package: - name: direnv - when: "'direnv' in asdf_plugins_names" - -- name: Install "nodejs" asdf plugin dependencies - ansible.builtin.package: - name: - - dirmngr - - gpg - when: "'nodejs' in asdf_plugins_names" - -# Needed by the python plugin due to pyenv -# See: https://github.com/pyenv/pyenv/wiki#suggested-build-environment -- name: Install "python" asdf plugin dependencies - ansible.builtin.package: - name: - - libbz2-dev - - libffi-dev - - liblzma-dev - - libncursesw5-dev - - libsqlite3-dev - - libssl-dev - - libxml2-dev - - libxmlsec1-dev - - llvm - - tk-dev - - xz-utils - - zlib1g-dev - when: "'python' in asdf_plugins_names" - -- name: Install "aki" user asdf plugins - become_user: aki - ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && - asdf plugin add {{ item.name }} {{ item.repository | default('') }}" - creates: ~/.asdf/plugins/{{ item.name }} - with_items: "{{ asdf_plugins }}" - -- name: Install "aki" user asdf tools versions - become_user: aki - ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && - asdf install {{ item.name }} {{ item.version | default('latest') }}" - register: asdf_install - retries: 10 - delay: 2 - until: asdf_install is success - with_items: "{{ asdf_plugins }}" - changed_when: "'already installed' not in asdf_install.stdout" - -- name: Set "aki" user global asdf tools versions - become_user: aki - ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && - asdf global {{ item.name }} {{ item.version | default('latest') }}" - with_items: "{{ asdf_plugins }}" - changed_when: false - -- name: Setup "aki" user direnv asdf plugin - become_user: aki - ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && - asdf direnv setup --shell zsh --version system" - creates: ~/.config/asdf-direnv/zshrc - when: "'direnv' in asdf_plugins_names" - -- name: Create "aki" user home directory .envrc - become_user: aki - ansible.builtin.command: - chdir: /home/aki - cmd: zsh -c "source ~/.asdf/asdf.sh && asdf direnv local" - creates: ~/.envrc - when: "'direnv' in asdf_plugins_names" - -- name: Discover "aki" user pip executable - become_user: aki - ansible.builtin.command: - cmd: zsh -c "source ~/.asdf/asdf.sh && direnv exec ~ which pip" - register: which_pip - changed_when: false - when: "'python' in asdf_plugins_names" - -- name: Set pip executable - ansible.builtin.set_fact: - pip_executable: "{{ which_pip.stdout }}" - when: "'python' in asdf_plugins_names" - -- name: Discover "aki" user npm prefix - become_user: aki - ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && direnv exec ~ npm prefix --global" - register: npm_prefix_result - changed_when: false - when: "'nodejs' in asdf_plugins_names" - -- name: Set npm binaries directory - ansible.builtin.set_fact: - npm_binaries_dir: "{{ npm_prefix_result.stdout }}/bin" - when: "'nodejs' in asdf_plugins_names" diff --git a/ansible/roles/common/tasks/npm.yml b/ansible/roles/common/tasks/npm.yml index 486a91548..619c341e2 100644 --- a/ansible/roles/common/tasks/npm.yml +++ b/ansible/roles/common/tasks/npm.yml @@ -6,8 +6,12 @@ - name: Install "aki" user global npm packages become_user: aki ansible.builtin.command: - cmd: > - zsh -c "source ~/.asdf/asdf.sh && - direnv exec ~ npm install --global {{ item }}" - creates: "{{ npm_binaries_dir }}/{{ item }}" - loop: "{{ package_names }}" + cmd: >- + zsh -c + "rtx exec -- + npm install --global {{ package_names | join(' ') }}" + register: npm_install + retries: 10 + delay: 2 + until: npm_install is success + changed_when: "'added' in npm_install.stdout" diff --git a/ansible/roles/common/tasks/rtx.yml b/ansible/roles/common/tasks/rtx.yml new file mode 100644 index 000000000..05b5d55b2 --- /dev/null +++ b/ansible/roles/common/tasks/rtx.yml @@ -0,0 +1,62 @@ +--- +- name: Set plugin names + ansible.builtin.set_fact: + rtx_plugins_names: "{{ rtx_plugins | map(attribute='name') | list }}" + +- name: Install "nodejs" rtx plugin dependencies + ansible.builtin.package: + name: + - dirmngr + - gpg + when: "'nodejs' in rtx_plugins_names" + +# Needed by the python plugin due to pyenv +# See: https://github.com/pyenv/pyenv/wiki#suggested-build-environment +- name: Install "python" rtx plugin dependencies + ansible.builtin.package: + name: + - libbz2-dev + - libffi-dev + - liblzma-dev + - libncursesw5-dev + - libsqlite3-dev + - libssl-dev + - libxml2-dev + - libxmlsec1-dev + - llvm + - tk-dev + - xz-utils + - zlib1g-dev + when: "'python' in rtx_plugins_names" + +- name: Install "aki" user rtx plugins + become_user: aki + ansible.builtin.command: + cmd: >- + zsh -c " + rtx use --global --yes + {{ + rtx_plugins | + map(attribute='name') | + zip(rtx_plugins | map(attribute='version') | map('default', 'latest')) | + map('join', '@') | + join(' ') + }}" + register: rtx_install + retries: 10 + delay: 2 + until: rtx_install is success + changed_when: "'installed' in rtx_install.stdout" + +- name: Discover "aki" user pip executable + become_user: aki + ansible.builtin.command: + cmd: zsh -c "rtx which pip" + register: which_pip + changed_when: false + when: "'python' in rtx_plugins_names" + +- name: Set pip executable + ansible.builtin.set_fact: + pip_executable: "{{ which_pip.stdout }}" + when: "'python' in rtx_plugins_names" diff --git a/ansible/roles/workstations/tasks/install-dev-tools.yml b/ansible/roles/workstations/tasks/install-dev-tools.yml index 85c09d69a..c2db593e1 100644 --- a/ansible/roles/workstations/tasks/install-dev-tools.yml +++ b/ansible/roles/workstations/tasks/install-dev-tools.yml @@ -3,14 +3,14 @@ ansible.builtin.package: name: vagrant -- name: Install "aki" user asdf dev tools +- name: Install "aki" user rtx dev tools ansible.builtin.import_role: name: common - tasks_from: asdf + tasks_from: rtx vars: - asdf_plugins: + rtx_plugins: - name: java - version: latest:temurin-18 + version: temurin - name: kotlin - name: groovy @@ -53,7 +53,19 @@ ansible.builtin.package: name: terraform -- name: Install python dev tools +- name: Install Node dev tools + ansible.builtin.import_role: + name: common + tasks_from: npm + vars: + package_names: + - eslint + - nx + - prettier + - svgo + - yarn + +- name: Install Python dev tools ansible.builtin.import_role: name: common tasks_from: pip diff --git a/docs/DEVELOPERS_GUIDE.md b/docs/DEVELOPERS_GUIDE.md index a82f0fa75..107721172 100644 --- a/docs/DEVELOPERS_GUIDE.md +++ b/docs/DEVELOPERS_GUIDE.md @@ -24,7 +24,7 @@ test this project. Install the following software - [just](https://github.com/casey/just) -- [asdf](https://github.com/asdf-vm/asdf) +- [rtx](https://github.com/jdx/rtx) - [![VirtualBox](images/virtualbox.svg) VirtualBox](https://www.virtualbox.org) ## Useful Commands diff --git a/justfile b/justfile index d1396a23b..ea5daafee 100755 --- a/justfile +++ b/justfile @@ -11,7 +11,7 @@ install: install-tools install-dependencies # Install tools install-tools: - asdf install + rtx install # Install dependencies install-dependencies: