Skip to content

Commit 5aa4506

Browse files
author
Douglas Greiman
authored
Create Debian packages for GCP Python interpreters (GoogleCloudPlatform#140)
We build binary packages directly, rather than building from a source package as the standard Debian Python packages are.
1 parent 8995620 commit 5aa4506

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Package: ${DEB_PACKAGE_NAME}
2+
Version: ${DEB_PACKAGE_VERSION}
3+
Section: python
4+
Priority: optional
5+
Architecture: amd64
6+
Maintainer: Douglas Greiman <dgreiman@google.com>
7+
Description: Interactive high-level object-oriented language (version ${SHORT_VERSION})
8+
Python is a high-level, interactive, object-oriented language. Its ${SHORT_VERSION} version
9+
includes an extensive class library with lots of goodies for
10+
network programming, system administration, sounds and graphics.
11+
Depends: libbz2-1.0,
12+
libc6,
13+
libdb5.3,
14+
libexpat1,
15+
libffi6,
16+
liblzma5,
17+
libmpdec2,
18+
libncursesw5,
19+
libreadline6,
20+
libsqlite3-0,
21+
libssl1.0.0,
22+
libtinfo5,
23+
mime-support,
24+
zlib1g
25+
Homepage: https://www.python.org

python-interpreter-builder/Dockerfile.in

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -yq \
1010
debhelper \
1111
dpkg-dev \
1212
gcc \
13+
gettext-base \
1314
libbluetooth-dev \
1415
libbz2-dev \
1516
libdb-dev \
@@ -43,10 +44,17 @@ ENV LANG C.UTF-8
4344

4445
# Add build scripts
4546
ADD scripts /scripts
47+
ADD DEBIAN /DEBIAN
4648

4749
# Build the Python interpreters
48-
RUN /scripts/build-python-3.5.sh
49-
RUN /scripts/build-python-3.6.sh
50+
RUN mkdir -p /opt/packages && \
51+
echo -n "" > /opt/packages/packages.txt
52+
53+
RUN /scripts/build-python-3.5.sh && \
54+
/scripts/package-python.sh 3.5.4 "1gcp~${TAG}"
55+
56+
RUN /scripts/build-python-3.6.sh && \
57+
/scripts/package-python.sh 3.6.2 "1gcp~${TAG}"
5058

5159
# Tar the interpreters. Tarring is needed because docker cp doesn't handle
5260
# links correctly.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
set -x
5+
6+
function usage {
7+
echo "Usage: $0 long_version tag
8+
Create .deb package file for a Python interpreter with
9+
long_version: (x.y.z) Interpreter version
10+
tag: version suffix unique to this build
11+
" >&2
12+
exit 1
13+
}
14+
# Process command line
15+
if [ -z "${1:+set}" -o -z "${2:+set}" ]; then
16+
usage
17+
fi
18+
LONG_VERSION=$1
19+
BUILD_TAG=$2
20+
SHORT_VERSION=${1%.*}
21+
22+
# Compute version specs
23+
DEB_PACKAGE_NAME=gcp-python${SHORT_VERSION}
24+
# Can't have - (hyphen) in debian revision as per
25+
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
26+
DEBIAN_REVISION=${BUILD_TAG//-/.}
27+
DEB_PACKAGE_VERSION=${LONG_VERSION}-${DEBIAN_REVISION}
28+
29+
PACKAGE_DIR=/opt/packages
30+
# E.g. gcp-python3.6_3.6.2-1gcp~2017.07.25.110644_amd64.deb
31+
DEB_FILENAME=${DEB_PACKAGE_NAME}_${DEB_PACKAGE_VERSION}_amd64.deb
32+
33+
# Create directory for intermediate files
34+
SCRATCH_DIR=$(mktemp --directory)
35+
cd "${SCRATCH_DIR}"
36+
37+
# Synthesize Debian control file. Note that the "Depends:" is
38+
# currently Debian8-specific, and lacks version specifiers present in
39+
# the standard Debian Python packages.
40+
export DEB_PACKAGE_NAME DEB_PACKAGE_VERSION SHORT_VERSION
41+
envsubst </DEBIAN/control.in >control \
42+
'${DEB_PACKAGE_NAME} ${DEB_PACKAGE_VERSION} ${SHORT_VERSION}'
43+
44+
# Generate components of .deb archive
45+
tar czf control.tar.gz control
46+
tar czf data.tar.gz "/opt/python${SHORT_VERSION}"
47+
echo "2.0" >debian-binary
48+
49+
# Generate final .deb.
50+
mkdir -p "${PACKAGE_DIR}"
51+
ar rcD "${PACKAGE_DIR}/${DEB_FILENAME}" \
52+
debian-binary control.tar.gz data.tar.gz
53+
rm debian-binary control.tar.gz data.tar.gz
54+
55+
# Validate .deb
56+
dpkg --install --dry-run "${PACKAGE_DIR}/${DEB_FILENAME}"
57+
58+
# Add to list
59+
echo "${DEB_FILENAME}" >> "${PACKAGE_DIR}/packages.txt"

0 commit comments

Comments
 (0)