diff --git a/.github/actions/version-matrix/.gitignore b/.github/actions/version-matrix/.gitignore deleted file mode 100644 index f9606a37..00000000 --- a/.github/actions/version-matrix/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/venv diff --git a/.github/actions/version-matrix/action.yml b/.github/actions/version-matrix/action.yml deleted file mode 100644 index b40388a1..00000000 --- a/.github/actions/version-matrix/action.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: 'Version matrix' -description: 'Generate a version matrix' - -outputs: - matrix: - description: Generated version matrix - value: ${{ steps.generate-matrix.outputs.matrix }} - -runs: - using: 'composite' - steps: - - shell: bash - working-directory: .github/actions/version-matrix - run: | - python3 -m venv venv - source venv/bin/activate - pip3 install -r requirements.txt - - - shell: bash - id: generate-matrix - working-directory: .github/actions/version-matrix - run: | - echo "matrix=$(python3 build_versions.py)" >> $GITHUB_OUTPUT diff --git a/.github/actions/version-matrix/build_versions.py b/.github/actions/version-matrix/build_versions.py deleted file mode 100644 index 1ff49b5a..00000000 --- a/.github/actions/version-matrix/build_versions.py +++ /dev/null @@ -1,19 +0,0 @@ -import logging -import argparse -import sys -import os -import json - -from version_matrix import matrix_builder - -parser = argparse.ArgumentParser() -parser.add_argument("--verbose", "-v", action="count", default=0) -args = parser.parse_args() - -log_level = logging.WARNING - (2 if args.verbose > 2 else args.verbose) * 10 -log_format = "%(asctime)s [%(levelname)s]: %(message)s [%(threadName)s]" -logging.basicConfig(format=log_format, level=log_level, datefmt="%H:%M:%S", stream=sys.stderr) - -matrix = matrix_builder.build_matrix() - -print(json.dumps(matrix)) diff --git a/.github/actions/version-matrix/requirements.txt b/.github/actions/version-matrix/requirements.txt deleted file mode 100644 index 3cdfe427..00000000 --- a/.github/actions/version-matrix/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests == 2.32.4 -pylint == 2.14.3 \ No newline at end of file diff --git a/.github/actions/version-matrix/version_matrix/__init__.py b/.github/actions/version-matrix/version_matrix/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/.github/actions/version-matrix/version_matrix/constant.py b/.github/actions/version-matrix/version_matrix/constant.py deleted file mode 100644 index ab212f12..00000000 --- a/.github/actions/version-matrix/version_matrix/constant.py +++ /dev/null @@ -1,10 +0,0 @@ -"""These are constants used in detecting build versions to report for building""" - - -# PHP releases API endpoint -PHP_RELEASE_API = "https://www.php.net/releases/index.php?json" - -# Minimum PHP version number to build, ignoring -# anything older -PHP_MIN_MAJOR_VERSION = 7 -PHP_MIN_MINOR_VERSION = 0 diff --git a/.github/actions/version-matrix/version_matrix/matrix_builder.py b/.github/actions/version-matrix/version_matrix/matrix_builder.py deleted file mode 100644 index e8708957..00000000 --- a/.github/actions/version-matrix/version_matrix/matrix_builder.py +++ /dev/null @@ -1,93 +0,0 @@ -import threading -import logging - -from . import release_versions -from . import constant - - -def build_matrix() -> dict: - """ - Build the version matrix - - :return: None - """ - - threads = [] - matrix = {"short_sem_version": [], "include": []} - failures = [] - - for version in release_versions.list_all_versions(): - logging.info("Spawning check for version %s", version) - - thread = threading.Thread( - target=_check_version, - args=(version, matrix, failures), - name="BuildThread-" + version - ) - - threads.append(thread) - thread.start() - - logging.info("Waiting for all threads to finish...") - for thread in threads: - thread.join() - - # Sort versions - matrix["short_sem_version"].sort() - - return matrix - - -def _check_version(version_number: str, matrix: dict, failures: list): - """ - Check a particular version for freshness - - :param version_number: - :param matrix: - :param failures: - :param :username: - :param password: - :param repository: - :return: - """ - - try: - version_metadata = release_versions.fetch_version_metadata(version_number) - logging.debug(version_metadata) - - _append_version_entry( - version_metadata, - matrix, - ) - - _append_version_entry( - version_metadata, - matrix, - "zts", - ) - - except Exception: - failures.append(version_number) - - -def _append_version_entry(version_metadata: dict, matrix: dict, suffix: str = None): - """ - Append the desired version to the version matrix with the optional suffix - - :param version_metadata: - :param matrix: - :param epoch: - :param suffix: - :return: - """ - - metadata = "" - if suffix is not None: - metadata = "+" + suffix - - matrix["short_sem_version"].append(version_metadata["short_version"] + metadata) - matrix["include"].append({ - "short_sem_version": version_metadata["short_version"] + metadata, - "full_sem_version": version_metadata["full_version"] + metadata, - "short_version": version_metadata["short_version"], - }) diff --git a/.github/actions/version-matrix/version_matrix/release_versions.py b/.github/actions/version-matrix/version_matrix/release_versions.py deleted file mode 100644 index 8bf4b8a0..00000000 --- a/.github/actions/version-matrix/version_matrix/release_versions.py +++ /dev/null @@ -1,69 +0,0 @@ -import requests -import json -from datetime import datetime - -from . import constant - - -def list_all_versions() -> list: - """ - Fetch the latest versions of each PHP major/minor build - combination - - :return: - """ - - r = requests.get(constant.PHP_RELEASE_API) - latest_releases = json.loads(r.content) - - if r.status_code != 200: - raise Exception("Failed to fetch all versions for listing for matrix") - - for release in latest_releases: - major_version, minor_version, patch_version = latest_releases[release]["version"].split(".") - major_version_int = int(major_version) - minor_version_int = int(minor_version) - - while major_version_int == constant.PHP_MIN_MAJOR_VERSION and minor_version_int >= constant.PHP_MIN_MINOR_VERSION or \ - major_version_int > constant.PHP_MIN_MAJOR_VERSION and minor_version_int >= 0: - major_minor_version = major_version + "." + str(minor_version_int) - minor_version_int = minor_version_int - 1 - yield major_minor_version - - -def fetch_version_metadata(version_number: str) -> dict: - """ - Fetch version metadata for the version number passed - - :param version_number: - :return: - """ - - r = requests.get(constant.PHP_RELEASE_API, params={"version": version_number}) - version_metadata = json.loads(r.content) - - if r.status_code != 200: - raise Exception("Failed to fetch metadata for version") - - return { - "short_version": version_number, - "full_version": version_metadata['version'], - "release_date": _extract_release_datetime(version_metadata), - } - - -def _extract_release_datetime(version_metadata: dict) -> datetime: - """ - Extract the release timestamp from the version metadata - - :param version_metadata: - :return: - """ - - for date_format in ["%d %b %Y", "%d %B %Y"]: - try: - return datetime.strptime(version_metadata["date"], date_format) - except ValueError: - pass - - raise Exception("Failed to parse the datetime used in the release metadata") diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d12cdaf..005f1be6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: secrets: inherit with: matrix: ${{ needs.version_matrix.outputs.matrix }} - distribution: bookworm-slim + distribution: bookworm max-retries: 3 push: true @@ -43,6 +43,6 @@ jobs: secrets: inherit with: matrix: ${{ needs.version_matrix.outputs.matrix }} - distribution: bookworm-slim + distribution: bookworm max-retries: 0 push: false diff --git a/.github/workflows/subflow-detect-versions.yml b/.github/workflows/subflow-detect-versions.yml index bd8d7342..4b041986 100644 --- a/.github/workflows/subflow-detect-versions.yml +++ b/.github/workflows/subflow-detect-versions.yml @@ -24,4 +24,4 @@ jobs: - name: Detect versions id: generate-matrix - uses: ./.github/actions/version-matrix + uses: spaulg/php-version-matrix-action@main diff --git a/.gitignore b/.gitignore index 8060a824..fe45cae0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /internal/querybuilder /internal/telemetry /.env -/build \ No newline at end of file +/build +/work diff --git a/function_build_php_image.go b/function_build_php_image.go index cd68f3c7..633eb193 100644 --- a/function_build_php_image.go +++ b/function_build_php_image.go @@ -74,6 +74,7 @@ func (m *PhpDevContainers) BuildPhpImage( WithEnvVariable("DEBIAN_FRONTEND", "noninteractive"). WithExec([]string{"sh", "-c", "rm /var/lib/dpkg/info/libc-bin.*"}). WithExec([]string{"apt-get", "clean"}). + WithExec([]string{"rm", "-rf", "/var/lib/apt/lists/*"}). WithExec([]string{"apt", "update", "-y"}). WithExec([]string{"apt", "upgrade", "-y"}). WithExec([]string{"apt", "install", "-y", "libc-bin"}). diff --git a/function_build_php_packages.go b/function_build_php_packages.go index 15b9c3ea..bfcf5e69 100644 --- a/function_build_php_packages.go +++ b/function_build_php_packages.go @@ -2,9 +2,9 @@ package main import ( "context" - "github.com/spaulg/php-dev-containers/internal/dagger" "fmt" "github.com/dchest/uniuri" + "github.com/spaulg/php-dev-containers/internal/dagger" "runtime" "strings" ) @@ -22,11 +22,11 @@ type PhpVersion struct { func (m *PhpDevContainers) BuildPhpPackages( ctx context.Context, -// Source archive file path + // Source archive file path sourceArchive *dagger.File, -// List of architectures to build packages for, in addition to the native architecture -//+optional + // List of architectures to build packages for, in addition to the native architecture + //+optional architectures *string, ) (*dagger.Directory, error) { var err error @@ -71,6 +71,8 @@ func (m *PhpDevContainers) BuildPhpPackages( // Prepare environment container, err = container. WithEnvVariable("DEBIAN_FRONTEND", "noninteractive"). + WithExec([]string{"apt-get", "clean"}). + WithExec([]string{"rm", "-rf", "/var/lib/apt/lists/*"}). WithExec([]string{"apt", "update", "-y"}). WithExec([]string{"apt", "upgrade", "-y"}). WithExec([]string{"apt", "install", "-y", "build-essential", "devscripts", "quilt", "git", "sudo"}).