Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dedal
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EBRAINS RI
Tech Hub
Platform
EBRAINS Software Distribution
dedal
Merge requests
!1
feat: restructure repo into a proper Python tool/library
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat: restructure repo into a proper Python tool/library
esd
into
koutakia
Overview
11
Commits
4
Pipelines
39
Changes
22
Merged
Eric Müller
requested to merge
esd
into
koutakia
2 months ago
Overview
6
Commits
4
Pipelines
39
Changes
22
Expand
0
0
Merge request reports
Compare
koutakia
version 37
6471bd2d
1 month ago
version 36
51cb05a1
1 month ago
version 35
690852c3
1 month ago
version 34
4b598294
1 month ago
version 33
46264bb6
1 month ago
version 32
58a541f4
1 month ago
version 31
73883963
1 month ago
version 30
55ec6ff5
1 month ago
version 29
874a94f8
1 month ago
version 28
0f881e4b
1 month ago
version 27
c69d58ca
1 month ago
version 26
10398158
1 month ago
version 25
010437bc
1 month ago
version 24
9d51404c
2 months ago
version 23
4f9e820e
2 months ago
version 22
bf1e6e85
2 months ago
version 21
a7d40965
2 months ago
version 20
123055f0
2 months ago
version 19
5150d5a6
2 months ago
version 18
f3d4d30a
2 months ago
version 17
50c4e660
2 months ago
version 16
67eeb025
2 months ago
version 15
0016d7d9
2 months ago
version 14
e0302b9c
2 months ago
version 13
1866ef87
2 months ago
version 12
dc325573
2 months ago
version 11
6abd25ad
2 months ago
version 10
a6414b41
2 months ago
version 9
b084c3ed
2 months ago
version 8
30ee78ff
2 months ago
version 7
a46245d2
2 months ago
version 6
c478539c
2 months ago
version 5
ca5e7356
2 months ago
version 4
306c54c9
2 months ago
version 3
01d33623
2 months ago
version 2
8d5a6a49
2 months ago
version 1
559956f1
2 months ago
koutakia (base)
and
latest version
latest version
0c03c2d4
4 commits,
1 month ago
version 37
6471bd2d
3 commits,
1 month ago
version 36
51cb05a1
6 commits,
1 month ago
version 35
690852c3
6 commits,
1 month ago
version 34
4b598294
6 commits,
1 month ago
version 33
46264bb6
7 commits,
1 month ago
version 32
58a541f4
6 commits,
1 month ago
version 31
73883963
6 commits,
1 month ago
version 30
55ec6ff5
7 commits,
1 month ago
version 29
874a94f8
6 commits,
1 month ago
version 28
0f881e4b
6 commits,
1 month ago
version 27
c69d58ca
7 commits,
1 month ago
version 26
10398158
6 commits,
1 month ago
version 25
010437bc
5 commits,
1 month ago
version 24
9d51404c
4 commits,
2 months ago
version 23
4f9e820e
4 commits,
2 months ago
version 22
bf1e6e85
3 commits,
2 months ago
version 21
a7d40965
2 commits,
2 months ago
version 20
123055f0
2 commits,
2 months ago
version 19
5150d5a6
3 commits,
2 months ago
version 18
f3d4d30a
21 commits,
2 months ago
version 17
50c4e660
20 commits,
2 months ago
version 16
67eeb025
19 commits,
2 months ago
version 15
0016d7d9
18 commits,
2 months ago
version 14
e0302b9c
17 commits,
2 months ago
version 13
1866ef87
16 commits,
2 months ago
version 12
dc325573
15 commits,
2 months ago
version 11
6abd25ad
14 commits,
2 months ago
version 10
a6414b41
13 commits,
2 months ago
version 9
b084c3ed
12 commits,
2 months ago
version 8
30ee78ff
11 commits,
2 months ago
version 7
a46245d2
10 commits,
2 months ago
version 6
c478539c
9 commits,
2 months ago
version 5
ca5e7356
8 commits,
2 months ago
version 4
306c54c9
7 commits,
2 months ago
version 3
01d33623
6 commits,
2 months ago
version 2
8d5a6a49
5 commits,
2 months ago
version 1
559956f1
4 commits,
2 months ago
22 files
+
374
−
35
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
22
Search (e.g. *.vue) (Ctrl+P)
dedal/build_cache/BuildCacheManager.py
0 → 100644
+
113
−
0
Options
import
os
import
oras.client
from
pathlib
import
Path
from
dedal.build_cache.BuildCacheManagerInterface
import
BuildCacheManagerInterface
from
dedal.logger.logger_builder
import
get_logger
from
dedal.utils.utils
import
clean_up
class
BuildCacheManager
(
BuildCacheManagerInterface
):
"""
This class aims to manage the push/pull/delete of build cache files
"""
def
__init__
(
self
,
auth_backend
=
'
basic
'
,
insecure
=
False
):
self
.
logger
=
get_logger
(
__name__
,
BuildCacheManager
.
__name__
)
self
.
home_path
=
Path
(
os
.
environ
.
get
(
"
HOME_PATH
"
,
os
.
getcwd
()))
self
.
registry_project
=
os
.
environ
.
get
(
"
REGISTRY_PROJECT
"
)
self
.
_registry_username
=
str
(
os
.
environ
.
get
(
"
REGISTRY_USERNAME
"
))
self
.
_registry_password
=
str
(
os
.
environ
.
get
(
"
REGISTRY_PASSWORD
"
))
self
.
registry_host
=
str
(
os
.
environ
.
get
(
"
REGISTRY_HOST
"
))
# Initialize an OrasClient instance.
# This method utilizes the OCI Registry for container image and artifact management.
# Refer to the official OCI Registry documentation for detailed information on the available authentication methods.
# Supported authentication types may include basic authentication (username/password), token-based authentication,
self
.
client
=
oras
.
client
.
OrasClient
(
hostname
=
self
.
registry_host
,
auth_backend
=
auth_backend
,
insecure
=
insecure
)
self
.
client
.
login
(
username
=
self
.
_registry_username
,
password
=
self
.
_registry_password
)
self
.
oci_registry_path
=
f
'
{
self
.
registry_host
}
/
{
self
.
registry_project
}
/cache
'
def
upload
(
self
,
out_dir
:
Path
):
"""
This method pushed all the files from the build cache folder into the OCI Registry
"""
build_cache_path
=
self
.
home_path
/
out_dir
# build cache folder must exist before pushing all the artifacts
if
not
build_cache_path
.
exists
():
self
.
logger
.
error
(
f
"
Path
{
build_cache_path
}
not found.
"
)
for
sub_path
in
build_cache_path
.
rglob
(
"
*
"
):
if
sub_path
.
is_file
():
rel_path
=
str
(
sub_path
.
relative_to
(
build_cache_path
)).
replace
(
str
(
sub_path
.
name
),
""
)
target
=
f
"
{
self
.
registry_host
}
/
{
self
.
registry_project
}
/cache:
{
str
(
sub_path
.
name
)
}
"
try
:
self
.
logger
.
info
(
f
"
Pushing folder
'
{
sub_path
}
'
to ORAS target
'
{
target
}
'
...
"
)
self
.
client
.
push
(
files
=
[
str
(
sub_path
)],
target
=
target
,
# save in manifest the relative path for reconstruction
manifest_annotations
=
{
"
path
"
:
rel_path
},
disable_path_validation
=
True
,
)
self
.
logger
.
info
(
f
"
Successfully pushed
{
sub_path
.
name
}
"
)
except
Exception
as
e
:
self
.
logger
.
error
(
f
"
An error occurred while pushing:
{
e
}
"
)
# todo to be discussed hot to delete the build cache after being pushed to the OCI Registry
# clean_up([str(build_cache_path)], self.logger)
def
list_tags
(
self
):
"""
This method retrieves all tags from an OCI Registry
"""
try
:
return
self
.
client
.
get_tags
(
self
.
oci_registry_path
)
except
Exception
as
e
:
self
.
logger
.
error
(
f
"
Failed to list tags:
{
e
}
"
)
return
None
def
download
(
self
,
in_dir
:
Path
):
"""
This method pulls all the files from the OCI Registry into the build cache folder
"""
build_cache_path
=
self
.
home_path
/
in_dir
# create the buildcache dir if it does not exist
os
.
makedirs
(
build_cache_path
,
exist_ok
=
True
)
tags
=
self
.
list_tags
()
if
tags
is
not
None
:
for
tag
in
tags
:
ref
=
f
"
{
self
.
registry_host
}
/
{
self
.
registry_project
}
/cache:
{
tag
}
"
# reconstruct the relative path of each artifact by getting it from the manifest
cache_path
=
\
self
.
client
.
get_manifest
(
f
'
{
self
.
registry_host
}
/
{
self
.
registry_project
}
/cache:
{
tag
}
'
)[
'
annotations
'
][
'
path
'
]
try
:
self
.
client
.
pull
(
ref
,
# missing dirs to output dir are created automatically by OrasClient pull method
outdir
=
str
(
build_cache_path
/
cache_path
),
overwrite
=
True
)
self
.
logger
.
info
(
f
"
Successfully pulled artifact
{
tag
}
.
"
)
except
Exception
as
e
:
self
.
logger
.
error
(
f
"
Failed to pull artifact
{
tag
}
:
{
e
}
"
)
def
delete
(
self
):
"""
Deletes all artifacts from an OCI Registry based on their tags.
This method removes artifacts identified by their tags in the specified OCI Registry.
It requires appropriate permissions to delete artifacts from the registry.
If the registry or user does not have the necessary delete permissions, the operation might fail.
"""
tags
=
self
.
list_tags
()
if
tags
is
not
None
:
try
:
self
.
client
.
delete_tags
(
self
.
oci_registry_path
,
tags
)
self
.
logger
.
info
(
f
"
Successfully deleted all artifacts form OCI registry.
"
)
except
RuntimeError
as
e
:
self
.
logger
.
error
(
f
"
Failed to delete artifacts:
{
e
}
"
)