-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy and install Air Link as pip package (#10)
* deployment and installation assuming air link will be pip-installed * cleanup * add air-link script to pyproject.toml * add GitHub workflow * update readme * add license * add shields * code review * adjustments for Python3.8 * fix working directory
- Loading branch information
1 parent
45d6274
commit b276797
Showing
24 changed files
with
1,580 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Publish Release | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- v** | ||
|
||
jobs: | ||
pypi: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.x" | ||
|
||
- name: Set up Poetry | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: "1.8.3" | ||
|
||
- name: Get version | ||
id: get_version | ||
run: echo "VERSION=$(echo ${GITHUB_REF/refs\/tags\//})" >> $GITHUB_ENV | ||
|
||
- name: Set version | ||
run: poetry version ${{ env.VERSION }} | ||
|
||
- name: Publish PyPI package | ||
env: | ||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.LIVESYNC_PYPI_API_TOKEN }} | ||
run: poetry publish --build | ||
|
||
- name: Create GitHub release entry | ||
uses: softprops/action-gh-release@v1 | ||
id: create_release | ||
with: | ||
draft: true | ||
prerelease: false | ||
name: ${{ env.VERSION }} | ||
tag_name: ${{ env.VERSION }} | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
||
- name: Update version in pyproject.toml | ||
run: python .github/workflows/update_pyproject.py $(echo ${GITHUB_REF/refs\/tags\//}) | ||
|
||
- name: Commit and push changes | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git add pyproject.toml | ||
git commit -m "Update pyproject.toml" | ||
git push origin HEAD:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
import re | ||
import sys | ||
from pathlib import Path | ||
|
||
if __name__ == '__main__': | ||
path = Path('pyproject.toml') | ||
content = path.read_text(encoding='utf-8') | ||
version = sys.argv[1].removeprefix('v') | ||
content = re.sub(r'version = "[0-9]+\.[0-9]+\.[0-9]+-dev"', f'version = "{version}-dev"', content) | ||
path.write_text(content, encoding='utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Zauberzeug GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .main import main | ||
|
||
__all__ = [ | ||
'main', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
import getpass | ||
import logging | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from utils import run | ||
SERVICE_FILE = Path(__file__).parent / 'air_link.service' | ||
|
||
if not run.sudo_password: | ||
run.sudo_password = getpass.getpass(prompt='Enter sudo password: ') | ||
|
||
run.pip('install -r requirements.txt') | ||
|
||
run.sudo( | ||
'cp air_link.service /etc/systemd/system/air_link.service', | ||
'sed -i "s/USER/$USER/g" /etc/systemd/system/air_link.service', | ||
'systemctl daemon-reload', | ||
'systemctl enable air_link.service', | ||
'systemctl restart air_link.service', | ||
) | ||
def install() -> None: | ||
sudo_password = getpass.getpass(prompt='Enter sudo password: ') | ||
for cmd in [ | ||
f'cp {SERVICE_FILE} /etc/systemd/system/air_link.service', | ||
'sed -i "s/USER/$USER/g" /etc/systemd/system/air_link.service', | ||
'systemctl daemon-reload', | ||
'systemctl enable air_link.service', | ||
'systemctl restart air_link.service', | ||
]: | ||
sudo_cmd = f'sudo -S {cmd}' | ||
try: | ||
with subprocess.Popen(sudo_cmd, | ||
shell=True, | ||
stdin=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
encoding='utf8') as process: | ||
process.communicate(input=sudo_password + '\n') | ||
if process.wait() != 0: | ||
return | ||
except subprocess.CalledProcessError as e: | ||
logging.error(f'failed to run {sudo_cmd}: {e.output}') | ||
return | ||
except Exception as e: | ||
logging.exception(f'failed to run {sudo_cmd}: {e}') | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
import argparse | ||
|
||
from app import create_main_page, setup_ssh | ||
from nicegui import app, ui | ||
from .install import install | ||
from .run import run | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logging.getLogger('watchfiles').setLevel(logging.WARNING) | ||
|
||
if app.storage.general.get('air_link_token'): | ||
app.on_startup(setup_ssh) | ||
def main() -> None: | ||
parser = argparse.ArgumentParser( | ||
'Air Link', description='SSH access, diagnostics and administration for edge devices.') | ||
parser.add_argument('action', choices=['install', 'run'], help='action to perform', default='run') | ||
args = parser.parse_args() | ||
|
||
create_main_page() | ||
if args.action == 'run': | ||
run() | ||
|
||
ui.run( | ||
title='Air Link', | ||
favicon='⛑', | ||
reload=False, | ||
on_air=app.storage.general.get('air_link_token', False), | ||
) | ||
if args.action == 'install': | ||
install() |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
|
||
from nicegui import app, ui | ||
|
||
from .main_page import create_page | ||
from .ssh import setup | ||
|
||
|
||
def run() -> None: | ||
logging.basicConfig(level=logging.INFO) | ||
logging.getLogger('watchfiles').setLevel(logging.WARNING) | ||
|
||
on_air = app.storage.general.get('air_link_token', False) | ||
if on_air: | ||
app.on_startup(setup) | ||
|
||
create_page() | ||
|
||
ui.run(title='Air Link', favicon='⛑', reload=False, on_air=on_air) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.