GitLab cache

This commit is contained in:
jpic 2020-01-26 20:02:29 +01:00
parent 4f405a8709
commit 47db32ad0c
6 changed files with 25 additions and 11 deletions

View File

@ -11,7 +11,11 @@ test:
build: build:
stage: test stage: test
image: yourlabs/podctl image: yourlabs/podctl
script: pip install . && podctl build script: pip install . && CACHE_DIR=$(pwd)/.cache podctl build
cache:
paths:
- .cache
key: cache
pypi: pypi:
stage: deploy stage: deploy

View File

@ -1,3 +1,4 @@
import os
import subprocess import subprocess
@ -42,11 +43,11 @@ class Packages:
raise Exception('Packages does not yet support this distro') raise Exception('Packages does not yet support this distro')
def build(self, script): def build(self, script):
cache = f'.cache/{self.mgr}' if 'CACHE_DIR' in os.environ:
script.mount( cache = os.path.join(os.getenv('CACHE_DIR'), self.mgr)
'$(pwd)/' + cache, else:
f'/var/cache/{self.mgr}' cache = os.path.join(os.getenv('HOME'), '.cache', self.mgr)
) script.mount(cache, f'/var/cache/{self.mgr}')
if self.mgr == 'apk': if self.mgr == 'apk':
# special step to enable apk cache # special step to enable apk cache

View File

@ -1,3 +1,6 @@
import os
class Pip: class Pip:
def __init__(self, *pip_packages, pip=None): def __init__(self, *pip_packages, pip=None):
self.pip_packages = pip_packages self.pip_packages = pip_packages
@ -16,7 +19,11 @@ class Pip:
_pip=pip2 _pip=pip2
fi fi
''') ''')
script.mount('.cache/pip', '/root/.cache/pip') if 'CACHE_DIR' in os.environ:
cache = os.path.join(os.getenv('CACHE_DIR'), 'pip')
else:
cache = os.path.join(os.getenv('HOME'), '.cache', 'pip')
script.mount(cache, '/root/.cache/pip')
script.run('sudo $_pip install --upgrade pip') script.run('sudo $_pip install --upgrade pip')
source = [p for p in self.pip_packages if p.startswith('/')] source = [p for p in self.pip_packages if p.startswith('/')]
if source: if source:

View File

@ -16,6 +16,8 @@ from unittest import mock
from podctl.visitors import packages from podctl.visitors import packages
packages.subprocess.check_call = mock.Mock() packages.subprocess.check_call = mock.Mock()
os.environ['CACHE_DIR'] = '/test'
def script_test(name, *visitors): def script_test(name, *visitors):
result = str(Container(*visitors).script('build')) result = str(Container(*visitors).script('build'))

View File

@ -16,8 +16,8 @@ mnt=$(buildah mount $ctr)
echo "Packages.pre_build" echo "Packages.pre_build"
echo "Packages.build" echo "Packages.build"
buildah run --user root $ctr -- mkdir -p /var/cache/apk buildah run --user root $ctr -- mkdir -p /var/cache/apk
mkdir -p $(pwd)/.cache/apk mkdir -p /test/apk
mount -o bind $(pwd)/.cache/apk $mnt/var/cache/apk mount -o bind /test/apk $mnt/var/cache/apk
mounts=("$mnt/var/cache/apk" "${mounts[@]}") mounts=("$mnt/var/cache/apk" "${mounts[@]}")
buildah run $ctr -- ln -s /var/cache/apk /etc/apk/cache buildah run $ctr -- ln -s /var/cache/apk /etc/apk/cache
old="$(find .cache/apk/ -name APKINDEX.* -mtime +3)" old="$(find .cache/apk/ -name APKINDEX.* -mtime +3)"

View File

@ -19,8 +19,8 @@ echo "Packages.pre_build"
echo "User.pre_build" echo "User.pre_build"
echo "Packages.build" echo "Packages.build"
buildah run --user root $ctr -- mkdir -p /var/cache/apk buildah run --user root $ctr -- mkdir -p /var/cache/apk
mkdir -p $(pwd)/.cache/apk mkdir -p /test/apk
mount -o bind $(pwd)/.cache/apk $mnt/var/cache/apk mount -o bind /test/apk $mnt/var/cache/apk
mounts=("$mnt/var/cache/apk" "${mounts[@]}") mounts=("$mnt/var/cache/apk" "${mounts[@]}")
buildah run $ctr -- ln -s /var/cache/apk /etc/apk/cache buildah run $ctr -- ln -s /var/cache/apk /etc/apk/cache
old="$(find .cache/apk/ -name APKINDEX.* -mtime +3)" old="$(find .cache/apk/ -name APKINDEX.* -mtime +3)"