Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kas: add caching for metadata layers from git #2

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ on:

env:
BUILDDIR: gh
DL_DIR: ${{ vars.BUILD_DL_DIR }}
SSTATE_DIR: ${{ vars.BUILD_SSTATE_DIR }}

jobs:
prepare:
runs-on: [self-hosted, linux, x64]
steps:
- name: Clean up
run: rm -fR $BUILDDIR
- uses: actions/checkout@v3
- name: cache metadata layers
run: ./ci/update-repos
env:
LAYERCACHE: ${{ vars.PERSISTENT_DIR }}/layers

build:
needs: [prepare]
Expand Down Expand Up @@ -96,10 +99,14 @@ jobs:
# the container image needs to be effectively hardcoded, it seems.
image: ghcr.io/theyoctojester/devcontainer-base-yoep:main
volumes:
- ${{ vars.KAS_DL_DIR }}:${{ vars.BUILD_DL_DIR }}
- ${{ vars.KAS_SSTATE_DIR }}:${{ vars.BUILD_SSTATE_DIR }}
- ${{ vars.PERSISTENT_DIR }}/downloads:${{ vars.BUILD_DL_DIR }}
- ${{ vars.PERSISTENT_DIR }}/sstate-cache:${{ vars.BUILD_SSTATE_DIR }}
- ${{ vars.PERSISTENT_DIR }}/layers:${{ vars.BUILD_LAYERCACHE_DIR }}
options: --user ${{ vars.KAS_UID }}:${{ vars.KAS_GID }}
steps:
- uses: actions/checkout@v3
- name: enter build dir and build
run: mkdir -p $BUILDDIR/${{ matrix.board }} && cd $BUILDDIR/${{ matrix.board }} && kas build ../../kas/${{ matrix.board }}.yml
env:
DL_DIR: ${{ vars.BUILD_DL_DIR}}
SSTATE_DIR: ${{ vars.BUILD_SSTATE_DIR}}
KAS_REPO_REF_DIR: ${{ vars.BUILD_LAYERCACHE_DIR}}
run: mkdir -p $BUILDDIR/${{ matrix.board }} && cd $BUILDDIR/${{ matrix.board }} && kas build ../../kas/${{ matrix.board }}.yml
65 changes: 65 additions & 0 deletions ci/update-repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env python3

# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches

import sys
import os
import shutil
import subprocess
import pathlib

def repo_shortname(url):
# Taken from Kas (Repo.__getattr__) to ensure the logic is right
from urllib.parse import urlparse
url = urlparse(url)
return ('{url.netloc}{url.path}'
.format(url=url)
.replace('@', '.')
.replace(':', '.')
.replace('/', '.')
.replace('*', '.'))

repositories = (
"https://git.yoctoproject.org/git/poky",
"https://git.openembedded.org/meta-openembedded",
"https://git.yoctoproject.org/git/meta-virtualization",
"https://github.com/kraj/meta-clang",
"https://github.com/mendersoftware/meta-mender",
"https://github.com/agherzan/meta-raspberrypi",
"https://github.com/OE4T/meta-tegra.git",
"https://github.com/Freescale/meta-freescale",
"https://github.com/Freescale/meta-freescale-distro",
"https://github.com/Freescale/meta-freescale-3rdparty",
"https://git.openembedded.org/openembedded-core",
"https://git.openembedded.org/bitbake",
"https://git.yoctoproject.org/git/meta-yocto",
)

if __name__ == "__main__":
if "LAYERCACHE" not in os.environ:
print("LAYERCACHE needs to be set")
sys.exit(1)

base_repodir = pathlib.Path(os.environ["LAYERCACHE"])
failed = False

for repo in repositories:
repodir = base_repodir / repo_shortname(repo)

if "CI_CLEAN_REPOS" in os.environ:
print("Cleaning %s..." % repo)
shutil.rmtree(repodir, ignore_errors=True)

if repodir.exists():
try:
print("Updating %s..." % repo)
subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True)
except subprocess.CalledProcessError as e:
print(e)
failed = True
else:
print("Cloning %s..." % repo)
subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)

if failed:
sys.exit(128)
Loading