Modify GH actions to support mirror

This commit is contained in:
fosslinux 2025-01-13 19:47:27 +11:00
parent 7d50a224c6
commit ba89224641
2 changed files with 28 additions and 27 deletions

View file

@ -32,20 +32,24 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
with: with:
path: | path: |
distfiles mirror
mirror-state
key: cache-${{ hashFiles('steps/*/sources') }} key: cache-${{ hashFiles('steps/*/sources') }}
restore-keys: |
cache-
- name: Get sources - name: Get sources
if: steps.cache.outputs.cache-hit != 'true' 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 - name: Cache sources
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4 uses: actions/cache/save@v4
with: with:
path: | path: |
distfiles mirror
mirror-state
key: cache-${{ hashFiles('steps/*/sources') }} key: cache-${{ hashFiles('steps/*/sources') }}
- name: Run bootstrap - 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 - name: Archive created packages
if: failure() # archive failed builds progress if: failure() # archive failed builds progress
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@ -87,18 +91,12 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
with: with:
path: | path: |
distfiles mirror
key: cache-${{ hashFiles('steps/*/sources') }} mirror-state
- 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
key: cache-${{ hashFiles('steps/*/sources') }} key: cache-${{ hashFiles('steps/*/sources') }}
fail-on-cache-miss: true
- name: Copy distfiles
run: ./download-distfiles.sh file:///${PWD}/mirror
- name: Run bootstrap - name: Run bootstrap
run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass2 run: ./rootfs.py --bwrap --external-sources --build-kernels --cores 2 --internal-ci pass2
- name: Archive created packages - name: Archive created packages
@ -142,20 +140,14 @@ jobs:
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
with: with:
path: | path: |
distfiles mirror
key: cache-${{ hashFiles('steps/*/sources') }} mirror-state
- 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
key: cache-${{ hashFiles('steps/*/sources') }} key: cache-${{ hashFiles('steps/*/sources') }}
fail-on-cache-miss: true
- name: Copy distfiles
run: ./download-distfiles.sh file:///${PWD}/mirror
- name: Run bootstrap - 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 - name: Archive created packages
if: always() # archive both failed and successful builds if: always() # archive both failed and successful builds
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View file

@ -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 <fosslinux@aussies.space>
import http.server import http.server
import socketserver import socketserver
class SimpleMirror(socketserver.TCPServer): class SimpleMirror(socketserver.TCPServer):
"""Simple HTTP mirror from a directory"""
def __init__(self, directory: str): def __init__(self, directory: str):
self.directory = directory self.directory = directory
super().__init__(("localhost", 0), self._handler) super().__init__(("localhost", 0), self._handler)
@property @property
def port(self): def port(self):
"""Port the HTTP server of the mirror is running on"""
return self.server_address[1] return self.server_address[1]
def _handler(self, *args, **kwargs): def _handler(self, *args, **kwargs):