Skip to content

Commit

Permalink
Add ansible changes for running with uv
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Nov 4, 2024
1 parent 1fbb736 commit d54ec9c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 40 deletions.
96 changes: 66 additions & 30 deletions ansible/_add_system_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
become: true
tags: [python]

- name: Install python libraries
ansible.builtin.apt:
pkg:
- python3.12
- python3.12-venv
- python3.12-dev
- python-is-python3
state: present
update_cache: true
become: true
when: install_system_reqs is true
tags: [python]

- name: Install mariadb libraries for python
ansible.builtin.apt:
pkg:
Expand All @@ -19,42 +32,65 @@
update_cache: true
become: true
when: install_system_reqs is true
tags: [wip]
tags: [mariadb]

- name: Download node source script
ansible.builtin.get_url:
url: "https://deb.nodesource.com/setup_18.x"
dest: "/tmp/setup_18.x.sh"
mode: "0755"
- name: Check if FNM is already installed
ansible.builtin.stat:
path: "/home/deploy/.local/share/fnm/fnm"
register: fnm_installed
when: install_node is true
tags: [fnm-install]

- name: Run node installer as root
ansible.builtin.command: "bash /tmp/setup_18.x.sh"
- name:
ansible.builtin.debug:
var: fnm_installed
when: install_node is true
become: true
tags: [fnm-install]

- name: Download FNM install (Fast Node Manager) script
ansible.builtin.get_url:
url: "https://fnm.vercel.app/install"
dest: "/tmp/fnm.install.sh"
mode: "0755"
when: install_node is true and fnm_installed.stat.exists is false
tags: [fnm-install]

- name: Run FNM install script
ansible.builtin.command: "bash /tmp/fnm.install.sh"
when: install_node is true and fnm_installed.stat.exists is false
tags: [fnm-install]

# FNM relies on a set of environment variables to be set in the shell.
# So we call fnm
- name: Install node and npm
ansible.builtin.apt:
pkg:
- nodejs
state: present
update_cache: true
become: true
when: install_node is true
ansible.builtin.shell: |
set -o pipefail
eval "$(fnm env)"
fnm use --install-if-missing 22
args:
executable: "/usr/bin/bash"
# set the PATH to include the fnm binary
environment:
PATH: "/home/deploy/.local/share/fnm/:{{ ansible_env.PATH }}"
when: install_node is true and fnm_installed.stat.exists is true
tags: [fnm-install]

- name: Install python libraries
ansible.builtin.apt:
pkg:
- python3.11
- python3.11-venv
- python3.11-dev
- python-is-python3
state: present
update_cache: true
become: true
when: install_system_reqs is true
tags: [python]
- name: Download uv install script
ansible.builtin.get_url:
url: "https://astral.sh/uv/install.sh"
dest: "/tmp/uv.install.sh"
mode: "0755"
when: install_uv is true
tags: [uv-install]

- name: Check if uv is already installed
ansible.builtin.stat:
path: "/home/deploy/.cargo/bin/uv"
register: uv_installed
when: install_uv is true
tags: [uv-install]

- name: Install libraries for handling dependencies
ansible.builtin.command: "python3.11 -m pip install uv wheel"
- name: Install uv for managing python dependencies
ansible.builtin.shell: "bash /tmp/uv.install.sh"
when: install_system_reqs is true
tags: [uv-install]
17 changes: 8 additions & 9 deletions ansible/_install_deploy_dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
---
- name: Set up a virtual environment for this project
ansible.builtin.command: "python3.11 -m venv .venv"
ansible.builtin.command: /home/deploy/.cargo/bin/uv venv
args:
chdir: "{{ project_root }}/current"
changed_when: false
tags: [uv]

- name: Install python dependencies with uv
ansible.builtin.shell: |
source .venv/bin/activate
python3.11 -m pip install uv
uv pip install -r requirements/requirements.linux.generated.txt
ansible.builtin.shell: /home/deploy/.cargo/bin/uv sync
args:
chdir: "{{ project_root }}/current"
executable: "/usr/bin/bash"
tags: [uv]

- name: Update node deps for building tailwind
ansible.builtin.shell: |
source .venv/bin/activate
dotenv run -- python3.11 ./manage.py tailwind update
/home/deploy/.cargo/bin/uv run dotenv run -- ./manage.py tailwind update
args:
chdir: "{{ project_root }}/current"
executable: "/usr/bin/bash"
when: update_front_end_deps is true
tags: [uv]

- name: Install node deps for building tailwind
ansible.builtin.shell: |
source .venv/bin/activate
dotenv run -- python3.11 ./manage.py tailwind install
/home/deploy/.cargo/bin/uv run dotenv run -- ./manage.py tailwind install
args:
executable: "/usr/bin/bash"
chdir: "{{ project_root }}/current"
changed_when: false
tags: [uv]
1 change: 1 addition & 0 deletions ansible/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

- name: Install dependencies for python and js
ansible.builtin.include_tasks: "_install_deploy_dependencies.yml"
tags: [uv, uv-install]

- name: Assemble assets and related files
ansible.builtin.include_tasks: "_assemble_deploy_assets.yml"
Expand Down
3 changes: 2 additions & 1 deletion ansible/provision_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
install_system_reqs: true
# decide about installing a recent version of node
install_node: true
install_uv: true
# run an update of our front dependencies as part of the deploy. This is better
# handled in source control, but if the front end will not build in deployment, this
# is a workaround
Expand All @@ -32,7 +33,7 @@
- name: Install all system dependencies
ansible.builtin.include_tasks: "_add_system_dependencies.yml"
when: install_system_reqs is true
tags: [python]
tags: [python, fnm-install, uv-install]

- name: Install all deploy dependencies
ansible.builtin.include_tasks: "_install_deploy_dependencies.yml"
Expand Down

0 comments on commit d54ec9c

Please sign in to comment.