From ba892246415609db46b2520187d4c2fae8578de8 Mon Sep 17 00:00:00 2001 From: fosslinux Date: Mon, 13 Jan 2025 19:47:27 +1100 Subject: [PATCH] Modify GH actions to support mirror --- .github/workflows/bwrap.yml | 46 +++++++++++++++---------------------- lib/simple_mirror.py | 9 ++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.github/workflows/bwrap.yml b/.github/workflows/bwrap.yml index 6aa3c01b..058e71cb 100644 --- a/.github/workflows/bwrap.yml +++ b/.github/workflows/bwrap.yml @@ -32,20 +32,24 @@ jobs: uses: actions/cache/restore@v4 with: path: | - distfiles + mirror + mirror-state key: cache-${{ hashFiles('steps/*/sources') }} + restore-keys: | + cache- - name: Get sources if: steps.cache.outputs.cache-hit != 'true' - run: ./download-distfiles.sh + run: mkdir -p mirror mirror-state && ./mirror.sh mirror mirror-state - name: Cache sources if: steps.cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: path: | - distfiles + mirror + mirror-state key: cache-${{ hashFiles('steps/*/sources') }} - name: Run bootstrap - run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass1 + run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass1 --mirror file://${PWD}/mirror - name: Archive created packages if: failure() # archive failed builds progress uses: actions/upload-artifact@v4 @@ -87,18 +91,12 @@ jobs: uses: actions/cache/restore@v4 with: path: | - distfiles - key: cache-${{ hashFiles('steps/*/sources') }} - - name: Get sources - if: steps.cache.outputs.cache-hit != 'true' - run: ./download-distfiles.sh - - name: Cache sources - if: steps.cache.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 - with: - path: | - distfiles + mirror + mirror-state key: cache-${{ hashFiles('steps/*/sources') }} + fail-on-cache-miss: true + - name: Copy distfiles + run: ./download-distfiles.sh file:///${PWD}/mirror - name: Run bootstrap run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass2 - name: Archive created packages @@ -142,20 +140,14 @@ jobs: uses: actions/cache/restore@v4 with: path: | - distfiles - key: cache-${{ hashFiles('steps/*/sources') }} - - name: Get sources - if: steps.cache.outputs.cache-hit != 'true' - run: ./download-distfiles.sh - - name: Cache sources - if: steps.cache.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 - with: - path: | - distfiles + mirror + mirror-state key: cache-${{ hashFiles('steps/*/sources') }} + fail-on-cache-miss: true + - name: Copy distfiles + run: ./download-distfiles.sh file:///${PWD}/mirror - name: Run bootstrap - run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass3 + run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass3 --mirror file://${PWD}/mirror - name: Archive created packages if: always() # archive both failed and successful builds uses: actions/upload-artifact@v4 diff --git a/lib/simple_mirror.py b/lib/simple_mirror.py index 414c2646..e33ef072 100644 --- a/lib/simple_mirror.py +++ b/lib/simple_mirror.py @@ -1,13 +1,22 @@ +#!/usr/bin/env python3 +""" +This creates a simple "mirror" from a directory +""" +# SPDX-License-Identifier: GPL-3.0-or-later +# SPDX-FileCopyrightText: 2025 fosslinux + import http.server import socketserver class SimpleMirror(socketserver.TCPServer): + """Simple HTTP mirror from a directory""" def __init__(self, directory: str): self.directory = directory super().__init__(("localhost", 0), self._handler) @property def port(self): + """Port the HTTP server of the mirror is running on""" return self.server_address[1] def _handler(self, *args, **kwargs):