Add (optional) automatic docker pruning after update

This commit is contained in:
kjeld Schouten-Lebbing 2022-01-19 17:37:14 +01:00
parent 126125c377
commit 768854df4f
No known key found for this signature in database
GPG Key ID: 4CDAD4A532BC1EDB
3 changed files with 17 additions and 1 deletions

View File

@ -19,5 +19,6 @@ Additional options are available:
- `trueupdate -h` for the CLI help page - `trueupdate -h` for the CLI help page
- `trueupdate -s` or ` trueupdate --sync` to sync the catalogs before running auto-update - `trueupdate -s` or ` trueupdate --sync` to sync the catalogs before running auto-update
- `trueupdate -p` or ` trueupdate --prune` to prune (remove) old docker images after running auto-update
- `trueupdate --catalog CATALOGNAME` where CATALOGNAME is the name of the catalog you want to process in caps - `trueupdate --catalog CATALOGNAME` where CATALOGNAME is the name of the catalog you want to process in caps
- `trueupdate --versioning SCHEME` where SCHEME is the highest semver version you want to process. options: `patch`, `minor` and `major` - `trueupdate --versioning SCHEME` where SCHEME is the highest semver version you want to process. options: `patch`, `minor` and `major`

View File

@ -7,7 +7,7 @@ README_MD = open(join(dirname(abspath(__file__)), "README.md")).read()
setup( setup(
name="trueupdate", name="trueupdate",
version="2.0.2", version="2.1.0",
# The packages that constitute your project. # The packages that constitute your project.
# For my project, I have only one - "pydash". # For my project, I have only one - "pydash".

View File

@ -81,10 +81,12 @@ def process_args():
global CATALOG global CATALOG
global SEMVER global SEMVER
global SYNC global SYNC
global PRUNE
parser = argparse.ArgumentParser(description='Update TrueNAS SCALE Apps') parser = argparse.ArgumentParser(description='Update TrueNAS SCALE Apps')
parser.add_argument('--catalog', nargs='?', default='ALL', help='name of the catalog you want to process in caps. Or "ALL" to render all catalogs.') parser.add_argument('--catalog', nargs='?', default='ALL', help='name of the catalog you want to process in caps. Or "ALL" to render all catalogs.')
parser.add_argument('--versioning', nargs='?', default='minor', help='Name of the versioning scheme you want to update. Options: major, minor or patch. Defaults to minor') parser.add_argument('--versioning', nargs='?', default='minor', help='Name of the versioning scheme you want to update. Options: major, minor or patch. Defaults to minor')
parser.add_argument('-s', '--sync', action="store_true", help='sync catalogs before trying to update') parser.add_argument('-s', '--sync', action="store_true", help='sync catalogs before trying to update')
parser.add_argument('-p', '--prune', action="store_true", help='prune old docker images after update')
args = parser.parse_args() args = parser.parse_args()
CATALOG = args.catalog CATALOG = args.catalog
VERSIONING = args.versioning VERSIONING = args.versioning
@ -92,6 +94,10 @@ def process_args():
SYNC = True SYNC = True
else: else:
SYNC = False SYNC = False
if args.prune:
PRUNE = True
else:
PRUNE = False
def sync_catalog(): def sync_catalog():
if SYNC: if SYNC:
@ -102,6 +108,15 @@ def sync_catalog():
print (lines) print (lines)
print (process.stdout.read()) print (process.stdout.read())
def docker_prune():
if PRUNE:
print("Pruning old docker images...\n")
process = subprocess.Popen(["docker", "image ", "prune", "-a", "-f"], stdout=subprocess.PIPE)
while process.poll() is None:
lines = process.stdout.readline()
print (lines)
print (process.stdout.read())
def run(): def run():
process_args() process_args()
print("Starting TrueCharts App updater...\n") print("Starting TrueCharts App updater...\n")