-
Notifications
You must be signed in to change notification settings - Fork 1
/
build
executable file
·107 lines (97 loc) · 4.94 KB
/
build
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
#!/bin/bash
# This script builds the container.
# It adds a fingerprint and revision automatically.
# You can pass extra arguments to the script to pass them to the docker build.
# You can also:
# * prefix the generated tag by setting PREFIX
# * auto prefix via rpm version by setting:
# * AUTO_PREFIX="rpm-version-release" and AUTO_PREFIX_PACKAGE=<rpmname>
# * auto prefix via apk version by setting:
# * AUTO_PREFIX="apk-version-release" and AUTO_PREFIX_PACKAGE=<apkname>
# * modify the autogenerated prefix by adding a bash snippet to to the
# variable AUTO_PREFIX_FILTER
# * NEW_BUILD=<anything> will force a new build reguardless of fingerprints.
# Used for bottstrapping.
# It needs the following variables set:
# * IMAGE_NAME - the full image name for the latest build.
# * DOCKER_TAG - the tag the latest build will get.
# * DOCKER_REPO - the repo the builds will go into.
# If SUBBUILD is in the environment, it will be passed to the docker build as
# an arg
set -e
echo "Build hook running"
if [ "x$SUBBUILD" != "x" ]; then
if [ "x$GPGKEY" != "x" ]; then
docker build --build-arg "SUBBUILD=$SUBBUILD" --no-cache --progress=plain --secret "id=gpg,src=$GPGKEY" -t tmp$$:1 . "$@"
else
docker build --build-arg "SUBBUILD=$SUBBUILD" -t tmp$$:1 . "$@"
fi
else
if [ "x$GPGKEY" != "x" ]; then
docker build --no-cache --progress=plain --secret "id=gpg,src=$GPGKEY" -t tmp$$:1 . "$@"
else
docker build -t tmp$$:1 . "$@"
fi
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
. $DIR/../common.sh
setupjq
if [ "x$PREFIX" == "x" ]; then
if [ "x$AUTO_PREFIX" == "xrpm-version" ]; then
PREFIX=$(docker run -i --rm --entrypoint='' tmp$$:1 rpm -q --queryformat '%{Version}' "$AUTO_PREFIX_PACKAGE")
fi
if [ "x$AUTO_PREFIX" == "xrpm-version-release" ]; then
PREFIX=$(docker run -i --rm --entrypoint='' tmp$$:1 rpm -q --queryformat '%{Version}-%{Release}' "$AUTO_PREFIX_PACKAGE")
fi
if [ "x$AUTO_PREFIX" == "xpip-version" ]; then
PREFIX=$(docker run -i --rm --entrypoint='' tmp$$:1 pip show "$AUTO_PREFIX_PACKAGE" 2>/dev/null | awk '{if($1 == "Version:"){print $2}}')
fi
if [ "x$AUTO_PREFIX" == "xapk-version" ]; then
PREFIX=$(docker run -i --rm --entrypoint='' tmp$$:1 apk info "$AUTO_PREFIX_PACKAGE" 2>/dev/null | head -n 1 | awk '{print $1}')
PREFIX=${PREFIX#"$AUTO_PREFIX_PACKAGE-"}
PREFIX=$(echo "$PREFIX" | awk -F- '{print $1}')
fi
if [ "x$AUTO_PREFIX" == "xapk-version-release" ]; then
PREFIX=$(docker run -i --rm --entrypoint='' tmp$$:1 apk info "$AUTO_PREFIX_PACKAGE" 2>/dev/null | head -n 1 | awk '{print $1}')
PREFIX=${PREFIX#"$AUTO_PREFIX_PACKAGE-"}
fi
if [ "x$AUTO_PREFIX" == "xrpmrepo-version" ]; then
setupxmlstarlet
export tc="tmp$$:3"
docker build --build-arg image="tmp$$:1" -t "$tc" -f "$DIR/../Dockerfile.fingerprinthelper" "$DIR/.."
PRIMARY=$(docker run -i --rm "$tc" /bin/sh -c 'cat /data/repodata/repomd.xml' | xmlstarlet sel -t -v '/_:repomd/_:data[@type="primary"]/_:location/@href')
PREFIX=$(docker run -i --rm "$tc" /bin/sh -c "cat /data/$PRIMARY" | zcat -f | xmlstarlet sel -t -m '/_:metadata/_:package[_:name="'"$AUTO_PREFIX_PACKAGE"'"]' -m '_:version' -v '@ver' -n)
docker rmi "$tc"
fi
if [ "x$AUTO_PREFIX" == "xrpmrepo-version-release" ]; then
setupxmlstarlet
export tc="tmp$$:3"
docker build --build-arg image="tmp$$:1" -t "$tc" -f "$DIR/../Dockerfile.fingerprinthelper" "$DIR/.."
PRIMARY=$(docker run -i --rm "$tc" /bin/sh -c 'cat /data/repodata/repomd.xml' | xmlstarlet sel -t -v '/_:repomd/_:data[@type="primary"]/_:location/@href')
PREFIX=$(docker run -i --rm "$tc" /bin/sh -c "cat /data/$PRIMARY" | zcat -f | xmlstarlet sel -t -m '/_:metadata/_:package[_:name="'"$AUTO_PREFIX_PACKAGE"'"]' -m '_:version' -v '@ver' -o '-' -v '@rel' -n)
docker rmi "$tc"
fi
if [ "x$AUTO_PREFIX" == "xfilecontent" ]; then
export tc="tmp$$:3"
docker build --build-arg image="tmp$$:1" -t "$tc" -f "$DIR/../Dockerfile.fingerprinthelper" "$DIR/.."
PREFIX=$(docker run -i --rm "$tc" /bin/sh -c "cat $AUTO_PREFIX_FILE")
docker rmi "$tc"
fi
if [ "x$AUTO_PREFIX_FILTER" != "x" ]; then
PREFIX=$(echo "$PREFIX" | eval "$AUTO_PREFIX_FILTER")
fi
if [ "x$AUTO_PREFIX" != "x" -a "x$PREFIX" == "x" ]; then
echo "Failed to generate prefix for an unknown reason."
exit -1
fi
fi
echo "PREFIX determined to be: $PREFIX"
echo "Adding fingerprint."
hubbuildtools/addfingerprint.sh tmp$$:1 tmp$$:2
# Fails if already uploaded to prevent a new version of the same contents
# from landing.
echo "Checking if this version already exists."
hubbuildtools/hubcompare.sh "$DOCKER_REPO" "$DOCKER_TAG" tmp$$:2
echo "Adding revision."
hubbuildtools/addrevision.sh tmp$$:2 "$DOCKER_REPO" "$DOCKER_TAG" "$IMAGE_NAME" "$PREFIX"
docker rmi tmp$$:1 tmp$$:2