Skip to content

Commit

Permalink
role nginx_uwsgi: fix build dependencies
Browse files Browse the repository at this point in the history
role uv: register uv python paths
  • Loading branch information
dometto committed Oct 10, 2024
1 parent aa42120 commit 753eb7c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/roles/nginx_uwsgi.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Python application is assumed to be installed already in the location `uwsgi

## Description

The playbook can be run in two modes:
The role can be executed in two modes:

1. (Default) Install `uwsgi` and its Python3 plugin via the system package manager (`apt`).
2. Use a pre-existing `uwsgi` installation in a `venv`. To use this mode, set the `uwsgi_venv` variable to the location of venv already containing `uwsgi`.
Expand Down
8 changes: 8 additions & 0 deletions docs/roles/uv.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Aditionally, a script `/usr/local/bin/uv_pip` is installed, which is essentially

The role also supports creating venvs and installing desired Python versions (see below).

The role will set a fact `uv_python_paths`, which contains a dict containing the location of the python interpreter for each requested versions. For example:

```
uv_python_paths: {
'3.11': '/root/.local/share/uv/cpython-xxxxx/bin/python3'
}
```

## Variables

- `uv_vens`: List of dicts describing virtual environments to be initialized with `uv`. Each item in the dict is expected to contain a `python` and `path` attribute: the former determines which Python verison to use for the venv, while the latter is the location of the venv. Example: `{ path: '/tmp/foo', python: '3.11' }`. __Note__: Python versions are installed if necessary.
Expand Down
7 changes: 1 addition & 6 deletions playbooks/flask_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
set_fact:
uwsgi_proxy_config: "{{ _uwsgi_proxy_config }}"

- name: Set auth info variable if present
- name: Set auth info variable if auth basic is set
when: flask_app_auth == 'basic'
set_fact:
_flask_app_auth_info:
Expand All @@ -69,11 +69,6 @@
password: "{{ flask_app_password | default('') }}"
no_log: true

- name: Set auth info variable if not present
when: not flask_app_auth == 'basic'
set_fact:
_flask_app_auth_info: "{{ omit }}"

- name: Clone repo
tags: molecule-idempotence-notest
git:
Expand Down
9 changes: 9 additions & 0 deletions playbooks/roles/nginx_uwsgi/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
galaxy_info:
author: Dawa Ometto (Utrecht University)
description: Setup uwsgi application service using nginx provided by SRC-Nginx component.
license: GPLv3
min_ansible_version: '2.9'
platforms:
- name: Ubuntu
versions:
- all
8 changes: 0 additions & 8 deletions playbooks/roles/nginx_uwsgi/molecule/venv/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
- build-essential
- python3-dev

- name: Create venv
ansible.builtin.pip:
name:
- wheel
- uwsgi
state: present
virtualenv: /var/www/uwsgi/example/venv

- name: Run external components
ansible.builtin.include_tasks: ../_run_external_components.yml
loop:
Expand Down
21 changes: 16 additions & 5 deletions playbooks/roles/nginx_uwsgi/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@

- name: Install uwsgi
when: uwsgi_venv
pip:
name:
- uwsgi
state: present # only install if not yet present, otherwise keep existing
virtualenv: "{{ uwsgi_venv }}"
block:

- name: Ensure build requirements for uwsgi present
when: ansible_os_family == 'Debian'
package:
name:
- build-essential
- python3-dev

- name: Install uwsgi via pip
pip:
name:
- wheel
- uwsgi
state: present # only install if not yet present, otherwise keep existing
virtualenv: "{{ uwsgi_venv }}"

- name: Configure uwsgi reverse proxy in nginx
include_role:
Expand Down
19 changes: 17 additions & 2 deletions playbooks/roles/uv/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pipx_install_systemwide_packages:
- uv
pipx_install_location: "{{ uu_pipx_bin }}"
pipx_install_systemwide_profile: '' # deactivate adding uv path to /etc/profile
pipx_install_systemwide_profile: '' # deactivate adding uv path to /etc/profile. We're creating aliases instead.

- name: Install uv alias
file:
Expand All @@ -27,11 +27,26 @@
#!/bin/bash
/usr/local/bin/uv pip "$@"
- name: Define python versions to be installed
set_fact:
uv_python_versions_install: "{{ (uv_python_versions + (uv_venvs | map(attribute='python') | list)) | unique }}"

- name: Install desired python version
command: "uv python install {{ item }}"
register: _install_desired_python
changed_when: '"Found existing installation" not in _install_desired_python.stderr'
with_items: "{{ (uv_python_versions + (uv_venvs | map(attribute='python') | list)) | unique }}"
with_items: "{{ uv_python_versions_install }}"

- name: Set uv python install path facts step 1
shell: "uv python find {{ item }}"
changed_when: false
register: "_uv_python_finds"
with_items: "{{ uv_python_versions_install }}"

- name: Set uv python install path facts step 2
set_fact:
uv_python_paths: "{{ (uv_python_paths | default({})) | combine({ item.item: item.stdout }) }}"
with_items: "{{ _uv_python_finds.results }}"

- name: Create venvs
command:
Expand Down

0 comments on commit 753eb7c

Please sign in to comment.