Skip to content

Commit 9cb9bf1

Browse files
authored
Self-host via uv with pinned pyinfra (#18)
* Self-host via uv with pinned pyinfra Add a pyproject.toml + committed uv.lock so the repo boots with a single `uv sync`, and switch CI and example commands to `uv run pyinfra`. pyinfra is pinned to 3.7 via the lock file — bump with `uv lock --upgrade-package pyinfra`. * ci: pin actions to SHAs and set python 3.14 Pin actions/checkout, astral-sh/setup-uv, and docker/setup-buildx-action to commit SHAs to mitigate supply chain risk, and pin uv's Python to 3.14.
1 parent f172677 commit 9cb9bf1

8 files changed

Lines changed: 698 additions & 11 deletions

File tree

.github/workflows/test.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ jobs:
1313
inventory-file: inventories/docker.py
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-python@v4
16+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
17+
- uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5
1818
with:
19-
python-version: "3.12"
20-
- uses: docker/setup-buildx-action@v2
21-
- run: pip install pyinfra --pre
19+
enable-cache: true
20+
python-version: "3.14"
21+
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
22+
- name: Install pyinfra from uv.lock
23+
run: uv sync --frozen
2224
- run: ./docker-start.sh
2325
working-directory: ${{ matrix.dir }}
2426
- name: Run pyinfra deploy
25-
run: pyinfra -y ${{ matrix.inventory-file }} ${{ matrix.deploy-file }}
27+
run: uv run pyinfra -y ${{ matrix.inventory-file }} ${{ matrix.deploy-file }}
2628
working-directory: ${{ matrix.dir }}
2729
- run: ./docker-stop.sh
2830
working-directory: ${{ matrix.dir }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.vagrant*
2+
.venv/
3+
__pycache__/
4+
*.py[cod]

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
A set of documented & tested pyinfra deploys.
44

5+
## Getting started
6+
7+
This repository is self-hosted with [uv](https://docs.astral.sh/uv/) — no global pyinfra install required. After installing uv:
8+
9+
```sh
10+
# Create the virtualenv and install the pinned pyinfra version from uv.lock
11+
uv sync
12+
13+
# Run pyinfra via uv (picks up the locked pyinfra automatically)
14+
uv run pyinfra --version
15+
```
16+
17+
All example commands below can be prefixed with `uv run` — e.g. `uv run pyinfra inventories/docker.py deploy.py`.
18+
519
## Complete Deploys
620

721
### [`python-web-app`](./python-web-app)

deploy-functions/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Groups of operations can be defined within a Python function that can be re-used
44

55
```sh
66
# Run deploy functions
7-
pyinfra @docker/ubuntu:22.04 deploy.install_base_packages
8-
pyinfra @docker/ubuntu:22.04 deploy.setup_nginx
7+
uv run pyinfra @docker/ubuntu:22.04 deploy.install_base_packages
8+
uv run pyinfra @docker/ubuntu:22.04 deploy.setup_nginx
99

1010
# Run the combined, undecorated function
11-
pyinfra @docker/ubuntu:22.04 deploy.deploy_server
11+
uv run pyinfra @docker/ubuntu:22.04 deploy.deploy_server
1212
```
1313

1414
## Why use the `@deploy` decorator at all?

inventory-functions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Like operations inventories can also be defined using Python functions. This brings incredible flexibility allowing you to pull data from external systems using Python's package ecosystem to generate pyinfra inventories. The `inventory.py` contains a triaival example of this which can be executed like so:
44

55
```sh
6-
pyinfra inventory.make_docker_inventory exec uptime
6+
uv run pyinfra inventory.make_docker_inventory exec uptime
77
```
88

99
There are no restrictions on what the function itself does, so you can call basically anything Python packages provide access to. Some ideas:

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[project]
2+
name = "pyinfra-examples"
3+
version = "0.1.0"
4+
description = "A set of documented & tested pyinfra deploys."
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
license = { file = "LICENSE.md" }
8+
dependencies = [
9+
"pyinfra==3.7",
10+
]
11+
12+
[tool.uv]
13+
package = false

python-web-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This example sets up two servers one database and one webserver. The webserver i
1212
./docker-start.sh
1313

1414
# Run pyinfra against them
15-
pyinfra inventories/docker.py deploy.py
15+
uv run pyinfra inventories/docker.py deploy.py
1616

1717
# The app should now be accessible in browser on localhost:5000
1818
# (the app is just a fork of a tutorial: https://github.com/Fizzadar/Flask-Web-App-Tutorial)

uv.lock

Lines changed: 655 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)