Skip to content

Commit

Permalink
coreos-ostree-importer: support OCI archives
Browse files Browse the repository at this point in the history
FCOS rawhide is now producing archives in the new OCI format. We have to
use `rpm-ostree ex-container import` to extract those.

Closes: coreos#145
  • Loading branch information
jlebon committed Oct 7, 2021
1 parent ff24355 commit 95dd753
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion coreos-ostree-importer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN dnf update -y
RUN dnf -y install \
fedora-messaging \
python-requests \
ostree \
rpm-ostree \
strace

# Configure a umask of 0002 which will allow for the group permissions
Expand Down
19 changes: 12 additions & 7 deletions coreos-ostree-importer/coreos_ostree_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def process(self, message: fedora_messaging.api.Message):
return

# Import the OSTree commit to the specified repo. We'll use
# a temporary directory to untar the repo into.
# a temporary directory to unpack the repo into.
with tempfile.TemporaryDirectory() as tmpdir:
# If the target repo is the prod repo the commit could
# already have been imported into the compose repo. If it
Expand All @@ -145,7 +145,7 @@ def process(self, message: fedora_messaging.api.Message):
source_repo_path = KNOWN_OSTREE_REPOS["compose"]
else:
# Grab the file from a web url and then pull local
untar_file_from_url(url=commit_url, tmpdir=tmpdir, sha256sum=sha256sum)
unpack_file_from_url(url=commit_url, tmpdir=tmpdir, sha256sum=sha256sum)
source_repo_path = tmpdir

# variables that are used in sanity checks below
Expand Down Expand Up @@ -271,8 +271,8 @@ def get_sha256sum(filepath: str) -> str:
return h.hexdigest()


def untar_file_from_url(url: str, tmpdir: str, sha256sum: str):
filename = "ostree.tar"
def unpack_file_from_url(url: str, tmpdir: str, sha256sum: str):
filename = "ostree-archive"
filepath = os.path.join(tmpdir, filename)

# Grab file from the url
Expand All @@ -284,9 +284,14 @@ def untar_file_from_url(url: str, tmpdir: str, sha256sum: str):
if sha256sum != calcuatedsum:
raise Exception("Checksums do not match: " f"{sha256sum} != {calcuatedsum}")

# Untar the file into the temporary directory
with tarfile.open(filepath) as tar:
tar.extractall(path=tmpdir)
if url.endswith(".ociarchive"):
runcmd(["ostree", "init", "--repo", tmpdir, "--mode=bare-user"])
runcmd(["rpm-ostree", "ex-container", "import", "--repo", tmpdir,
f"ostree-unverified-image:oci-archive:{filepath}"])
else:
# Assume tar and untar the file into the temporary directory
with tarfile.open(filepath) as tar:
tar.extractall(path=tmpdir)


def ostree_pull_local(srcrepo: str, dstrepo: str, branch: str, commit: str):
Expand Down

0 comments on commit 95dd753

Please sign in to comment.