-
Notifications
You must be signed in to change notification settings - Fork 32
/
docker_build.sh
executable file
·68 lines (56 loc) · 1.5 KB
/
docker_build.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
64
65
66
67
#!/bin/bash -e
# Currently includes jessie and stretch pbuilder roots
# docker image tag
VERSION="$(git log -1 --pretty=%h)"
# docker image name
IMAGE="opxhub/build"
# file where container id is saved for cleanup
CIDFILE=".cid"
cleanup () {
if [[ -e "${CIDFILE}" ]]; then
docker rm -f "$(cat ${CIDFILE})"
rm -f ${CIDFILE}
fi
}
trap cleanup EXIT
main() {
command -v docker >/dev/null 2>&1 || {
echo "You will need to install docker for this to work."
exit 1
}
docker build -t ${IMAGE}:base .
pbuilder_create jessie base stamp1
pbuilder_create stretch stamp1 "${VERSION}"
docker tag "${IMAGE}:${VERSION}" "${IMAGE}:latest"
}
pbuilder_create() {
# Create the pbuilder chroots.
#
# Since pyang is not (yet) available as a debian package, install it
# in the pbuilder chroot.
#
# There is an issue with docker/kernel/overlayfs/pbuilder: directory
# renames fail with a cross-device link error if the directory is on
# a lower layer. Work around this by combining all steps of chroot
# creation in one docker run invocation.
[[ $# != 3 ]] && return 1
dist="$1"
from_tag="$2"
to_tag="$3"
rm -f ${CIDFILE}
docker run \
--cidfile ${CIDFILE} \
--privileged \
-e ARCH=amd64 \
-e DIST="$dist" \
"${IMAGE}:${from_tag}" \
/pbuilder_create.sh
docker commit \
--change 'CMD ["bash"]' \
--change 'ENTRYPOINT ["/entrypoint.sh"]' \
"$(cat ${CIDFILE})" \
"${IMAGE}:${to_tag}"
docker rm -f "$(cat $CIDFILE)"
rm -f ${CIDFILE}
}
main