Skip to content

Commit

Permalink
Merge pull request #752 from VallariAg/pypi-cli
Browse files Browse the repository at this point in the history
Create "ceph-nvmeof" CLI command to use nvmeof-cli
  • Loading branch information
VallariAg authored Jul 23, 2024
2 parents 668c32c + 6f36404 commit 4006d19
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Publishes official python package at https://pypi.org/project/ceph-nvmeof/
# This is official release, and will be pushed to pypi when a new tag is pushed in repo.
# Usage: pip install ceph-nvmeof==1.2.15

# Also publishes dev python package at https://test.pypi.org/p/ceph-nvmeof
# This is for dev releases, and will be pushed to test pypi on all merges to "devel" branch.
# Usage: `pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ceph-nvmeof==1.2.15`

name: Publish release to PyPI
on:
push:
tags:
- '*'
branches:
- 'devel'
release:
types:
- published
workflow_dispatch:
inputs:
python_version:
description: 'Python Version'
required: false
type: string
pdm_version:
description: 'PDM Version'
required: false
type: string
pypi_env:
description: 'Push to test.pypi (dev) or pypi (prod). And `dev-debug-version` pushes to test.pypi with a test package version.'
required: true
default: 'dev'
type: choice
options:
- dev
- prod
- dev-debug-version
ref:
description: 'Build using this branch, tag or SHA'
required: false
type: string

env:
DEFAULT_PYTHON: ${{ inputs.python_version || '3.9' }}
DEFAULT_PDM: ${{ inputs.pdm_version || '2.7.4' }}
REF: ${{ inputs.ref || 'devel' }}

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{env.REF}}
- uses: pdm-project/setup-pdm@v3
with:
python-version: ${{env.DEFAULT_PYTHON}}
version: ${{env.DEFAULT_PDM}}

- name: Sync Dependencies
run: pdm sync -v --no-isolation --no-self --no-editable
- name: Compile Protocol Buffers
run: pdm run protoc

- name: Set current date as env variable
run: echo "NOW=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: (DEBUG) Set dev version number
# For debug-release, set version "<current_release>dev<timestamp>" (eg 1.2.15.dev20240710183756)
# (to avoid messing current releases versions like 1.2.15).
run: |
NEW_VERSION="$(pdm show --version).dev$NOW"
sed -i "s/^version = \".*\"/version = \"${NEW_VERSION}\"/" pyproject.toml
if: (inputs.pypi_env && inputs.pypi_env == 'dev-debug-version')
- name: Build package
run: pdm build --config-setting="--build-number=$NOW" --no-sdist

- name: Publish package distributions to PyPI
run: pdm publish --no-build
if: ( github.event_name == 'release' && github.event.action == 'published' ) || (github.event_name == 'workflow_dispatch' && inputs.pypi_env == 'prod')

- name: Publish package distributions to Test PyPI
run: pdm publish --no-build -r testpypi
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (inputs.pypi_env == 'dev' || inputs.pypi_env == 'dev-debug-version'))
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ The same configuration can also be manually run:
cephnvmf host add --subsystem nqn.2016-06.io.spdk:cnode1 --host "*"
```
These can also be run by setting environment variables `CEPH_NVMEOF_SERVER_ADDRESS` and `CEPH_NVMEOF_SERVER_PORT` before running nvmeof-cli commands, example:
```
export CEPH_NVMEOF_SERVER_ADDRESS=x.x.x.x
export CEPH_NVMEOF_SERVER_PORT=5500
// using containers
docker-compose run --it <container_image> subsystem add --subsystem nqn.2016-06.io.spdk:cnode1
// using pypi package
ceph-nvmeof subsystem add --subsystem nqn.2016-06.io.spdk:cnode1
```
### Mounting the NVMe-oF volume
Expand Down Expand Up @@ -357,6 +367,15 @@ Python wheel exported to:
/tmp/ceph_nvmeof-0.0.1-py3-none-any.whl
```

To install nvmeof-cli as a CLI tool from the above Python wheel package, (or alternatively only build the cli package):
```
make export-python
pip install /tmp/ceph_nvmeof-0.0.1-py3-none-any.whl
ceph-nvmeof // use nvmeof-cli tool!
```

This can also be installed from https://pypi.org/project/ceph-nvmeof/, by running `pip3 install ceph-nvmeof`.

### Development containers

To avoid having to re-build container on every code change, developer friendly containers are provided:
Expand Down
4 changes: 2 additions & 2 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def __init__(self):
required=False)
self.parser.add_argument(
"--server-address",
default="localhost",
default=(os.getenv('CEPH_NVMEOF_SERVER_ADDRESS') or "localhost"),
type=str,
help="Server address",
)
self.parser.add_argument(
"--server-port",
default=5500,
default=int(os.getenv('CEPH_NVMEOF_SERVER_PORT') or "5500"),
type=int,
help="Server port",
)
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ test = [
# documentation = ""
repository = "https://github.com/ceph/ceph-nvmeof.git"
# changelog = ""

[project.scripts]
ceph-nvmeof = "control.cli:main"

0 comments on commit 4006d19

Please sign in to comment.