Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up jlmkr.py into smaller files as-is #233

Merged
merged 58 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
109491c
Initialize developer environment
jonct Jul 13, 2024
47f332b
Introduce a formal build system
jonct Jul 15, 2024
de5223f
Shift script path awareness to the exterior zipapp
jonct Jul 15, 2024
351cef7
Extract the config file parser
jonct Jul 15, 2024
34f2164
Name modules in snake_case
jonct Jul 15, 2024
18150bf
Bypass root ownership check by setting JLMKR_DEBUG
jonct Jul 15, 2024
c155404
Run basic lint/style check during build action
jonct Jul 15, 2024
b25c964
Extract jail dataset utils
jonct Jul 15, 2024
2718c89
Extract more config parser
jonct Jul 15, 2024
a6c5ebb
Extract more config parser
jonct Jul 15, 2024
461cdf7
Extract parent dataset utils
jonct Jul 15, 2024
f2a020f
Extract console utils
jonct Jul 15, 2024
1461af8
Extract list action
jonct Jul 15, 2024
36ba561
Extract filesystem path inference utils
jonct Jul 15, 2024
b7a6fdd
Extract chroot utils
jonct Jul 15, 2024
673e77e
Extract more jail dataset utils
jonct Jul 15, 2024
3a83392
Extract file utils
jonct Jul 15, 2024
c523974
Extract start action
jonct Jul 15, 2024
ef479d7
Extract stop action
jonct Jul 15, 2024
d26e8cc
Extract restart action
jonct Jul 15, 2024
dbb3dd4
Extract exec action
jonct Jul 15, 2024
f686bbb
Extract shell action
jonct Jul 15, 2024
f29e0bc
Extract status action
jonct Jul 15, 2024
a08149d
Extract log action
jonct Jul 15, 2024
a0c0599
Extract download utils
jonct Jul 15, 2024
ff2416b
Extract images action
jonct Jul 15, 2024
fbf6e4d
Extract default configuration data
jonct Jul 15, 2024
1c0a7a4
Extract create action
jonct Jul 15, 2024
58e8b10
Extract remove action
jonct Jul 15, 2024
25100ef
Extract text editor utils
jonct Jul 15, 2024
7e6754c
Extract edit action
jonct Jul 15, 2024
3125b13
Rename dataset utils
jonct Jul 15, 2024
2feb873
Extract startup action
jonct Jul 15, 2024
3a0fb92
Extract command-line dispatch
jonct Jul 15, 2024
b52e5a4
Nip and tuck; tidy and sort
jonct Jul 15, 2024
49f751f
Restore CLI dependencies
jonct Jul 15, 2024
9eddfce
Fix CLI non-root developer mode
jonct Jul 15, 2024
8769d30
Restore config parser dependencies
jonct Jul 15, 2024
22cb05a
Restore dataset util dependency
jonct Jul 15, 2024
c554673
Restore download util dependencies
jonct Jul 15, 2024
80f6c0e
Remove unused dependency from zip builder
jonct Jul 15, 2024
7e07121
Realign create action dependencies
jonct Jul 15, 2024
a1aaea8
Drop unused edit action dependency
jonct Jul 15, 2024
6d64562
Restore list action dependency
jonct Jul 15, 2024
8dae934
Drop unused restart action dependencies
jonct Jul 15, 2024
c41ac9c
Restore start action dependencies
jonct Jul 15, 2024
a385453
Improve the developer bootstrap docs
jonct Jul 15, 2024
d4bc1c8
Add missing imports
Jip-Hop Jul 16, 2024
2266d89
Restore jlmkr.py to make tests happy
Jip-Hop Jul 16, 2024
1679d27
Chown files as root
Jip-Hop Jul 16, 2024
9bdcfed
Fix import
Jip-Hop Jul 16, 2024
2256d31
Run jlmkr as zipapp
Jip-Hop Jul 16, 2024
5e78f3e
Fail early
Jip-Hop Jul 16, 2024
67f3f45
Add apt-get update
Jip-Hop Jul 16, 2024
9d10898
Use python 3.11
Jip-Hop Jul 16, 2024
22ea984
Upload build artifact
Jip-Hop Jul 16, 2024
962b238
Remove Hatch
Jip-Hop Jul 16, 2024
0b96723
Update README.md
Jip-Hop Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Inspiration from <https://github.com/pypa/hatch/issues/669>

name: Build

on:
push:
branches: ["**"]
pull_request:
branches: ["**"]

workflow_dispatch:

jobs:

build:
name: Build jlmkr tool
runs-on: ubuntu-24.04
strategy:
matrix:
python-version:
- "3.11" # TrueNAS SCALE 24.04 Dragonfish
steps:

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Set up pip cache
uses: actions/cache@v3
jonct marked this conversation as resolved.
Show resolved Hide resolved
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install Hatch
uses: pypa/hatch@install

- name: Run style check
run: hatch fmt --check
Jip-Hop marked this conversation as resolved.
Show resolved Hide resolved

# - name: Run unit tests
# run: hatch run +py=${{ matrix.python-version }} test:test

- name: Build distribution
run: hatch build -t zipapp -t appzip

# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# path:
# - dist/jlmkr
# - dist/jlmkr-*.zip
# if-no-files-found: error
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ jobs:
env:
PYTHONUNBUFFERED: 1
run: |
sudo chown 0:0 jlmkr.py ./test/test-jlmkr
sudo chown -R 0:0 src jlmkr.py ./test/test-jlmkr
sudo bash ./test/test-jlmkr
sudo ./test/test.sh
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only

dist/

# jail-specific
/.lxc/
/jails/
.DS_Store

# Mac-specific
.DS_Store
._.DS_Store

# <https://github.com/github/gitignore/blob/main/Python.gitignore>

/.venv/

__pycache__/
*.py[cod]

.pytest_cache/
.ruff_cache/
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,51 @@ TODO: write comparison between systemd-nspawn (without `jailmaker`), LXC, VMs, D

The rootfs image `jlmkr.py` downloads comes from the [Linux Containers Image server](https://images.linuxcontainers.org). These images are made for LXC. We can use them with systemd-nspawn too, although not all of them work properly. For example, the `alpine` image doesn't work well. If you stick with common systemd based distros (Debian, Ubuntu, Arch Linux...) you should be fine.

## Development

After cloning the project, navigate into its working directory and create a self-contained Python [virtual environment](https://packaging.python.org/en/latest/tutorials/installing-packages/#creating-and-using-virtual-environments). Traditionally you would do that using the following command. Unfortunately, TrueNAS SCALE has [left out](https://ixsystems.atlassian.net/browse/NAS-130029) a necessary library from the base installation and *this command will fail:*

python3 -m venv .venv

The following workaround should accomplish the same task in more steps.
```
python3 -m venv --without-pip .venv
curl -OL https://bootstrap.pypa.io/pip/pip.pyz
.venv/bin/python3 pip.pyz install pip
rm pip.pyz
```
*Note: This process and the resulting build environment will cache some items under `~/.local/share` in addition to the project directory.*

Activate the venv into your *current* shell session.

source .venv/bin/activate

Develop away. Note that when you're done, you can undo this activation and return to the system's default Python environment. Just call a function that activation has inserted into your shell session:

deactivate

For more information on Python standard venvs, go to [the source](https://packaging.python.org/en/latest/tutorials/installing-packages/#creating-and-using-virtual-environments).

### Hatching a build

While in an *active* session, install the [Hatch](https://hatch.pypa.io) project manager. This will load quite a flurry of dependencies, but will only do so into the new `.venv` directory. *(And a bit into self-managed directories under `~/.local/share`.)*

pip install hatch

Build the "zipapp" target. This will create a `dist/jlmkr` tool which is the direct descendant of Jip-Hop's original `jlmkr.py` script.

hatch build -t zipapp

Now build the "appzip" target. This bundles the tool, `README.md` and `LICENSING` into a downloadable zip archive.

hatch build -t appzip

If you make any changes *to the embedded builder plugins* that perform the above, then you will need to clear caches between builds. Otherwise and generally, you will not need to do so.

hatch env prune

Hatch has oodles more features yet to be explored, such as: automated testing, code coverage, and style checking. For now, we've gotten it building.

## Filing Issues and Community Support

When in need of help or when you think you've found a bug in `jailmaker`, [please start with reading this](https://github.com/Jip-Hop/jailmaker/discussions/135).
Expand Down
Loading
Loading