-
Notifications
You must be signed in to change notification settings - Fork 28
/
docker-package.sh
executable file
·69 lines (61 loc) · 1.98 KB
/
docker-package.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
68
69
#! /usr/bin/env bash
#
# Build Debian package in a Docker container
#
function getDebianVersionString {
# Set Debian version string derived from
# Python version string
pyVersion=$1
# Split into major, minor and debug version
vMajor="$(cut -d'.' -f1 <<<$pyVersion)"
vMinor="$(cut -d'.' -f2 <<<$pyVersion)"
vDebug="$(cut -d'.' -f3 <<<$pyVersion)"
# Length of debug string
lDebug=${#vDebug}
# Flag that is True if debug string needs fixing
fixVDebugFlag=False
# Locate position of 1st non-numeric character
# in debug string
re='^[0-9]+$'
for i in $(seq 1 ${#vDebug}); do
echo $i
char="${vDebug:i-1:1}"
if [[ $char =~ $re ]] ; then
splitpos=$i
else
fixVDebugFlag=True
break
fi
done
# Insert tilde in debug string if needed
if [ $fixVDebugFlag = "True" ] ; then
vDebugDebian=${vDebug:0:$splitpos}"~"${vDebug:$splitpos:$lDebug}
else
vDebugDebian=$vDebug
fi
# Construct Debian version string
deb_version="$vMajor.$vMinor.$vDebugDebian"
}
set -e
# Get build platform as 1st argument, and collect project metadata
image="${1:?You MUST provide a docker image name e.g. debian:stretch}"; shift
dist_id=${image%%:*}
codename=${image#*:}
pypi_name="$(./setup.py --name)"
pypi_version="$(./setup.py --version)"
# Generate Debian version string
getDebianVersionString $pypi_version
pkgname=$pypi_name
tag=$pypi_name-$dist_id-$codename
# Build in Docker container, save results, and show package info
rm -f dist/${pkgname}?*${pypi_version//./?}*${codename}*.*
docker build --tag $tag \
--build-arg "DIST_ID=$dist_id" \
--build-arg "CODENAME=$codename" \
--build-arg "PKGNAME=$pkgname" \
--build-arg "VERSION=$pypi_version" \
-f Dockerfile.build \
"$@" .
mkdir -p dist
docker run -v "$PWD/dist":/dist --rm $tag cp --force "../opf-jpylyzer_${deb_version}_all.deb" /dist
ls -lh dist/opf?*${pkgname}?*${deb_version//./?}*.*