From 965cb9f5671218f451ea70a55483e58c67888300 Mon Sep 17 00:00:00 2001 From: George Adams Date: Thu, 4 Jul 2024 14:55:30 +0100 Subject: [PATCH] add arg to remove unsupported Dockerfiles/versions (#584) --- .github/workflows/updater.yml | 2 +- generate_dockerfiles.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml index b9e2f38c2..d32183d52 100644 --- a/.github/workflows/updater.yml +++ b/.github/workflows/updater.yml @@ -25,7 +25,7 @@ jobs: run: "pip3 install -r requirements.txt" - name: Run updater - run: "python3 generate_dockerfiles.py" + run: "python3 generate_dockerfiles.py --force" - uses: gr2m/create-or-update-pull-request-action@86ec1766034c8173518f61d2075cc2a173fb8c97 # v1.9.4 env: diff --git a/generate_dockerfiles.py b/generate_dockerfiles.py index 5c786bebf..3708c3ceb 100644 --- a/generate_dockerfiles.py +++ b/generate_dockerfiles.py @@ -13,6 +13,8 @@ import os +import argparse +import shutil import requests_cache import requests import yaml @@ -20,6 +22,10 @@ requests_cache.install_cache("adoptium_cache", expire_after=3600) +parser = argparse.ArgumentParser( + description="Generate Dockerfiles for Eclipse Temurin images" +) + # Setup the Jinja2 environment env = Environment(loader=FileSystemLoader("docker_templates")) @@ -27,6 +33,11 @@ "User-Agent": "Adoptium Dockerfile Updater", } +# Flag for force removing old Dockerfiles +parser.add_argument("--force", action="store_true", help="Force remove old Dockerfiles") + +args = parser.parse_args() + def archHelper(arch, os_name): if arch == "aarch64" and os_name == "ubuntu": @@ -44,6 +55,15 @@ def archHelper(arch, os_name): return arch +# Remove old Dockerfiles if --force is set +if args.force: + # Remove all top level dirs that are numbers + for dir in os.listdir(): + if dir.isdigit(): + print(f"Removing {dir}") + shutil.rmtree(dir) + + # Load the YAML configuration with open("config/hotspot.yml", "r") as file: config = yaml.safe_load(file) @@ -87,7 +107,9 @@ def archHelper(arch, os_name): # If version doesn't equal 8, get the more accurate version number if version != 8: - openjdk_version = "jdk-" + release["version_data"]["openjdk_version"] + openjdk_version = ( + "jdk-" + release["version_data"]["openjdk_version"] + ) # if openjdk_version contains -LTS remove it if "-LTS" in openjdk_version: openjdk_version = openjdk_version.replace("-LTS", "")