-
Notifications
You must be signed in to change notification settings - Fork 18
/
bt-qemu-docker
executable file
·123 lines (97 loc) · 3.61 KB
/
bt-qemu-docker
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash -e
# Author: Yannick Heneault [email protected]
#
# This file is part of buildtasks.
#
# Buildtasks is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
warning() { echo "WARNING [$(basename $0)]: $@"; }
info() { echo "INFO [$(basename $0)]: $@"; }
usage() {
cat<<EOF
Syntax: $(basename $0) [--publish] appname-version
Converts appliance appname-version to docker
Arguments::
appname-version - e.g., core-14.2-jessie-amd64
Options::
--publish - if set, image will be uploaded to docker index
and metadata will be publish; also assumes
'--mark-as-latest'.
--docker-publish - if set, image will be uploaded to docker index
--mark-as-latest - if set, the :latest tag will point to the
newly build image
Environment::
BT_DEBUG - turn on debugging
EOF
exit 1
}
while [ "$1" != "" ]; do
case $1 in
--help|-h ) usage;;
--publish) publish="yes"; mark_as_latest="yes";;
--docker-publish) docker_publish="yes";;
--mark-as-latest) mark_as_latest="yes";;
*) if [ -n "$appver" ]; then usage; else appver=$1; fi ;;
esac
shift
done
[ -n "$appver" ] || usage
[ -n "$publish" ] || warning "--publish was not specified"
[ -n "$BT_DEBUG" ] && set -x
export BT=$(dirname $(readlink -f $0))
export BT_CONFIG=$BT/config
. $BT_CONFIG/common.cfg
. $BT_CONFIG/docker.cfg
if [ "$publish" == "yes" ]; then
[ -n "$BT_PUBLISH_META" ] || fatal "BT_PUBLISH_META not set"
else
warning "--publish was not specified"
fi
parsed_appname_version=$($BT/bin/parse-appname-version $appver)
read appname appversion codename arch <<< "$parsed_appname_version"
export BT_VERSION=${appversion}-${codename}-${arch}
export RELEASE="debian/$codename"
os_arch=$(dpkg --print-architecture)
[ "amd64" == "$os_arch" ] || fatal "only amd64 is supported"
[ -n "$BT_DOCKER_NAME" ] || fatal "BT_DOCKER_NAME not set"
[ -n "$BT_DOCKER_USER" ] || fatal "BT_DOCKER_USER not set"
[ -n "$BT_DOCKER_PASS" ] || fatal "BT_DOCKER_PASS not set"
[ -n "$BT_DOCKER_MAIL" ] || fatal "BT_DOCKER_MAIL not set"
O=$BT_BUILDS/docker
mkdir -p $O
# hack for cloudtasks issues with pre command
if [ ! -e /root/docker-setup.done ]; then
/turnkey/buildtasks/bin/docker-setup
touch /root/docker-setup.done
fi
# make sure docker daemon is running
service docker start
ports=$(grep "^$appname:" $BT_CONFIG/docker.ports | sed "s|^$appname: ||")
[ -n "$ports" ] || fatal "no ports defined for $appname"
qcowfile=turnkey-${appname}-${BT_VERSION}.qcow2
name=turnkey-${appname}-${BT_VERSION}
cd $O
# create docker image
appversion=$(echo $BT_VERSION | cut -d "-" -f 1)
dockername=$BT_DOCKER_USER/${appname}-${arch}-qemu-${os_arch}:${appversion}
$BT/bin/docker-qemu-bundle $qcowfile $dockername $ports
# publish if specified
if [ "$publish" == "yes" ] || [ "$docker_publish" == "yes" ]; then
while true; do
if docker push $dockername; then
if [ "$mark_as_latest" == "yes" ]; then
docker tag $dockername "$BT_DOCKER_USER/${appname}-${arch}-qemu-${os_arch}:latest"
docker push "$BT_DOCKER_USER/${appname}-${arch}-qemu-${os_arch}:latest"
break
else
break
fi
else
echo "autoresume push: sleeping for 5 seconds"
sleep 5
fi
done
fi