Skip to content
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
17 changes: 4 additions & 13 deletions src/cmd-build
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ fi
image_config_checksum=$(< "${image_input}" sha256sum_str)
if [ -n "${previous_build}" ]; then
previous_image_input_checksum=$(jq -r '.["coreos-assembler.image-input-checksum"]' < "${previous_builddir}/meta.json")
previous_image_genver=$(jq -r '.["coreos-assembler.image-genver"]' < "${previous_builddir}/meta.json")
fi
echo "Image Config checksum: ${image_config_checksum}"

Expand Down Expand Up @@ -277,14 +276,8 @@ fi

image_input_checksum=$( (echo "${commit}" && echo "${image_config_checksum}") | sha256sum_str)
echo "New image input checksum: ${image_input_checksum}"
version=$(ostree --repo="${tmprepo}" show --print-metadata-key=version "${commit}" | sed -e "s,',,g")
if [ "${previous_commit}" = "${commit}" ] && [ -n "${previous_image_genver:-}" ]; then
image_genver=$((previous_image_genver + 1))
buildid="${version}"-"${image_genver}"
else
image_genver=0
buildid="${version}"
fi
init_build_meta_json "${commit}" tmp/
buildid=$(jq -r '.["buildid"]' < tmp/meta.json)
echo "New build ID: ${buildid}"

"${dn}"/write-commit-object "${tmprepo}" "${commit}" "$(pwd)"
Expand Down Expand Up @@ -333,14 +326,12 @@ fi
# summary could have double quotes: https://github.com/coreos/coreos-assembler/issues/327
#
# shellcheck disable=SC2046 disable=SC2086
cat > tmp/meta.json <<EOF
cat > tmp/buildmeta.json <<EOF
{
"buildid": "${buildid}",
"name": "${name}",
"summary": "${summary//\"/\\\"}",
"coreos-assembler.build-timestamp": "${build_timestamp}",
"coreos-assembler.image-config-checksum": "${image_config_checksum}",
"coreos-assembler.image-genver": "${image_genver}",
"coreos-assembler.image-input-checksum": "${image_input_checksum}",
"coreos-assembler.code-source": "${src_location}",
"coreos-assembler.container-config-git": $(jq -M '.git' ${PWD}/coreos-assembler-config-git.json)
Expand Down Expand Up @@ -378,7 +369,7 @@ fi

# Merge all the JSON; note that we want ${composejson} first
# since we may be overriding data from a previous build.
cat "${composejson}" "${overridesjson}" tmp/meta.json tmp/diff.json tmp/images.json tmp/cosa-image.json "${commitmeta_input_json}" | jq -s add > meta.json
cat "${composejson}" "${overridesjson}" tmp/meta.json tmp/buildmeta.json tmp/diff.json tmp/images.json tmp/cosa-image.json "${commitmeta_input_json}" | jq -s add > meta.json

# Filter out `ref` if it's temporary
if [ -n "${ref_is_temp}" ]; then
Expand Down
10 changes: 10 additions & 0 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,16 @@ from cosalib.builds import Builds
print(Builds('${workdir:-$(pwd)}').get_build_dir('${buildid}'))")
}

init_build_meta_json() {
local ostree_commit=$1; shift
local dir=$1; shift
(python3 -c "
import sys
sys.path.insert(0, '${DIR}')
from cosalib.builds import Builds
print(Builds('${workdir:-$(pwd)}').init_build_meta_json('${ostree_commit}', '${dir}'))")
}

get_latest_qemu() {
local latest builddir
latest=$(get_latest_build)
Expand Down
37 changes: 37 additions & 0 deletions src/cosalib/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
Builds interacts with builds.json
"""

import json
import os
import semver
import gi

gi.require_version('OSTree', '1.0')
from gi.repository import Gio, OSTree

from cosalib.cmdlib import (
get_basearch,
Expand Down Expand Up @@ -84,6 +89,38 @@ def insert_build(self, build_id, basearch=None):
]
})

def init_build_meta_json(self, ostree_commit, destdir):
"""
Given a new ostree version, initialize a new coreos-assembler
build by writing a `meta.json` in destdir.
"""
repopath = os.path.join(self._workdir, 'tmp/repo')
r = OSTree.Repo.new(Gio.File.new_for_path(repopath))
r.open(None)
[_, rev] = r.resolve_rev(ostree_commit, True)
[_, commit, _] = r.load_commit(rev)
commitmeta = commit.get_child_value(0)
version = commitmeta.unpack()['version']
image_genver = 0
buildid = version
genver_key = 'coreos-assembler.image-genver'
if not self.is_empty():
previous_buildid = self.get_latest()
metapath = self.get_build_dir(previous_buildid) + '/meta.json'
with open(metapath) as f:
previous_buildmeta = json.load(f)
previous_commit = previous_buildmeta['ostree-commit']
previous_image_genver = int(previous_buildmeta[genver_key])
if previous_commit == ostree_commit:
image_genver = previous_image_genver + 1
buildid = f"{version}-{image_genver}"
meta = {
'buildid': buildid,
genver_key: image_genver
}
with open(destdir + '/meta.json', 'w') as f:
json.dump(meta, f)

def bump_timestamp(self):
self._data['timestamp'] = rfc3339_time()
self.flush()
Expand Down