-
-
Notifications
You must be signed in to change notification settings - Fork 603
/
Copy pathbuild-capstan-base-image
executable file
·93 lines (74 loc) · 2.73 KB
/
build-capstan-base-image
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
program=$(basename $0)
set -e
if [ $# -lt 2 ]; then
echo "Build capstan base image"
echo "Usage: $program [image-name] [(<app|module>)(,<app|module>)*] [description]"
echo "Examples:"
echo " ./scripts/build-capstan-base-image cloudius/osv-base empty 'OSv base image for developers'"
echo " ./scripts/build-capstan-base-image cloudius/java8 openjdk8-zulu-full 'OSv base with Java 8'"
echo " ./scripts/build-capstan-base-image cloudius/python3 python3x 'OSv base with Python 3'"
exit 1
fi
name=$1
image=$2
description=$3
if [ -f /etc/os-release ]; then
platform=$(grep PRETTY_NAME /etc/os-release | cut -d = -f 2 | grep -o -P "[^\"]+")
elif [ -f /etc/lsb-release ]; then
platform=$(grep DISTRIB_DESCRIPTION /etc/lsb-release | cut -d = -f 2 | grep -o -P "[^\"]+")
else
platform="Unknown Linux"
fi
OSV_VERSION=$(scripts/osv-version.sh | cut -d - -f 1 | grep -Po "[^v]*")
OSV_COMMIT=$(scripts/osv-version.sh | grep -Po "\-g.*" | grep -oP "[^-g]*")
if [ "$OSV_COMMIT" != "" ]; then
version="$OSV_VERSION-$OSV_COMMIT"
fi
now=$(date +"%Y-%m-%dT%R:%S")
out=build/capstan/$name
index=$out/index.yaml
build="scripts/build image=$image"
mkdir -p $out
echo "==> Building '$name'..."
echo "format_version: 1" > $index
echo "version: $version" >> $index
echo "created: $now" >> $index
echo "description: $description" >> $index
echo "build: $build" >> $index
echo "platform: $platform" >> $index
$build
build_path=`realpath build/last`
qemuimage=$build_path/osv.qcow2
vboximage=$build_path/osv.vdi
vmwimage=$build_path/osv.vmdk
gceimage=$build_path/osv.tar.gz
capstan_local_repository=$HOME/.capstan/repository
# Generate QEMU image
ln -sf $build_path/usr.img $qemuimage
# Generate VBOX image
scripts/convert vdi
# Generate VMW image
scripts/convert vmdk
# Generate GCE image
scripts/gen-gce-tarball.sh
read -p "Copy base images into capstan local repository [y/N]? :" -n 1 -t 15 -s
echo
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
mkdir -p $capstan_local_repository/$name
cp $index $capstan_local_repository/$name/
cp $qemuimage $capstan_local_repository/$name/$(basename $name).qemu
cp $vboximage $capstan_local_repository/$name/$(basename $name).vbox
cp $vmwimage $capstan_local_repository/$name/$(basename $name).vmw
echo "Copied base images into $capstan_local_repository/$name/"
fi
gzip < $qemuimage > $out/$(basename $name).qemu.gz
gzip < $vboximage > $out/$(basename $name).vbox.gz
gzip < $vmwimage > $out/$(basename $name).vmw.gz
gce_url_file=$out/$(basename $name).gce
gce_tar_ball=$out/$(basename $name).gce.tar.gz
echo "gs://osv/$version/$(basename $name).gce.tar.gz" > $gce_url_file
gzip <$gce_url_file > $gce_url_file.gz
rm -f $gce_url_file $gce_tar_ball
mv -f $gceimage $gce_tar_ball
echo "==> '$name' image built to '$out'."