-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromeos_docker.sh
executable file
·63 lines (56 loc) · 2.19 KB
/
chromeos_docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Copyright 2021-2023 Satadru Pramanik
# Copyright 2023 Maximilian Downey Twiss
# SPDX-License-Identifier: GPL-3.0-or-later
name="${1}"
milestone="${2}"
: "${REPOSITORY:=satmandu}"
echo " name: ${name}"
echo " milestone: ${milestone}"
echo " REPOSITORY: ${REPOSITORY}"
setup_base () {
url="$(jq -r .\""${name}"\"[\""Recovery Images"\"][\""${milestone}"\"] boards.json)"
cached_image="$(echo ${url} | sed "s/https:\/\/dl.google.com\/dl\/edgedl\/chromeos\/recovery\/chromeos_//" | sed 's/_r.*//')"
if [[ ! -f "${cached_image}.tar" ]] ; then
echo "Cached image not found for ${cached_image}"
# Download image
curl --progress-bar --retry 3 -Lf "${url}" -o "${cached_image}".zip || ( echo "Download failed" && kill $$ )
# Unzip the image
7z x "${cached_image}".zip -so > "${cached_image}".bin
# Extract the filesystem directly into a tarball for importing into docker
virt-tar-out -a "${cached_image}".bin / "${cached_image}".tar
# Clean up after ourselves
rm -f "${cached_image}".zip "${cached_image}".bin
# If we don't already have the image cached, we don't already have it imported into docker and pushed to the repository
docker import "${cached_image}".tar --platform "${PLATFORM}" "${REPOSITORY}"/crewbase:"${name}".m"${milestone}"
docker push "${REPOSITORY}"/crewbase:"${name}".m"${milestone}"
else
echo "Cached image found for ${cached_image}, skipping download, import and push."
fi
}
get_arch () {
kernel_arch="$(jq -r .\""${name}\""[\""Kernel ABI"\"] boards.json)"
case $kernel_arch in
x86_64) PLATFORM="linux/amd64";;
x86) PLATFORM="linux/386";;
arm) PLATFORM="linux/arm";;
aarch64) PLATFORM="linux/arm64";;
esac
CREW_KERNEL_VERSION="$(jq -r .\""${name}\""[\""Kernel Version"\"] boards.json)"
}
build_docker_image () {
docker buildx create --name builder --driver docker-container --use
docker buildx build \
--push \
--platform ${PLATFORM} \
--build-arg CREWBASE=${REPOSITORY}/crewbase:${name}.m${milestone} \
--build-arg CREW_KERNEL_VERSION=$CREW_KERNEL_VERSION \
--tag ${REPOSITORY}/crewbuild:${name}.m${milestone} \
.
}
main () {
get_arch
setup_base
build_docker_image
}
main