Skip to content

Commit

Permalink
Update release process of apt repo
Browse files Browse the repository at this point in the history
With the new release process, Bazel APT repo will now support
installing Bazel at a specific version.
Users can run "apt-get install bazel=1.0.0", can call "bazel" from command line.

We also publish side-by-side packages named "bazel-<version>", which
made it possible to install multiple Bazel versions at the same time.
Users can run "apt-get install bazel-1.0.0", then call "bazel-1.0.0" from command line.
This will support #10272

Closes #10278.

PiperOrigin-RevId: 281723964
  • Loading branch information
meteorcloudy authored and copybara-github committed Nov 21, 2019
1 parent 91bf399 commit 3162705
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
91 changes: 91 additions & 0 deletions scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,93 @@ function ensure_gpg_secret_key_imported() {
fi
}

# Generate new content of Release file
function print_new_release_content() {
local distribution="$1"
# Print the headers of the original Release file
cat <<EOF
Origin: Bazel Authors
Label: Bazel
Codename: $1
Date: $(date -u "+%a, %d %b %Y %H:%M:%S UTC")
Architectures: amd64
Components: jdk1.8
Description: Bazel APT Repository
EOF
metadata_files=("jdk1.8/binary-amd64/Packages" "jdk1.8/binary-amd64/Packages.gz" "jdk1.8/binary-amd64/Release" "jdk1.8/source/Sources.gz" "jdk1.8/source/Release")
# Re-generate hashes for all metadata fiels
echo MD5Sum:
for file in ${metadata_files[*]}; do
path="dists/${distribution}/$file"
echo "" "$(md5sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file"
done
echo SHA1:
for file in ${metadata_files[*]}; do
path="dists/${distribution}/$file"
echo "" "$(sha1sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file"
done
echo SHA256:
for file in ${metadata_files[*]}; do
path="dists/${distribution}/$file"
echo "" "$(sha256sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file"
done
}

# Merge metadata with previous distribution
function merge_previous_dists() {
local distribution="$1"
# Download the metadata info from previous distrubution
mkdir -p previous
gsutil -m cp -r "gs://bazel-apt/dists" "./previous"

# Merge Packages and Packages.gz file
cat "previous/dists/${distribution}/jdk1.8/binary-amd64/Packages" >> "dists/${distribution}/jdk1.8/binary-amd64/Packages"
gzip -9c "dists/${distribution}/jdk1.8/binary-amd64/Packages" > "dists/${distribution}/jdk1.8/binary-amd64/Packages.gz"

# Merge Sources.gz file
gunzip "previous/dists/${distribution}/jdk1.8/source/Sources.gz"
gunzip "dists/${distribution}/jdk1.8/source/Sources.gz"
cat "previous/dists/${distribution}/jdk1.8/source/Sources" >> "dists/${distribution}/jdk1.8/source/Sources"
gzip -9c "dists/${distribution}/jdk1.8/source/Sources" > "dists/${distribution}/jdk1.8/source/Sources.gz"
rm -f "dists/${distribution}/jdk1.8/source/Sources"

# Update Release file
print_new_release_content "${distribution}" > "dists/${distribution}/Release.new"
mv "dists/${distribution}/Release.new" "dists/${distribution}/Release"

# Generate new signatures for Release file
rm -f "dists/stable/InRelease" "dists/stable/Release.gpg"
gpg --output "dists/stable/InRelease" --clear-sign "dists/stable/Release"
gpg --output "dists/stable/Release.gpg" --detach-sign "dists/stable/Release"
}

# Create a debian package with version in package name and add it to the repo
function add_versioned_deb_pkg() {
local distribution="$1"
local deb_pkg_name="$2"
# Extract the original package
mkdir -p deb-old
dpkg-deb -R "${deb_pkg_name}" deb-old

# Get bazel version
bazel_version=$(grep "Version:" deb-old/DEBIAN/control | cut -d " " -f2)
bazel_version=${bazel_version/\~/}

# Generate new control file
mkdir -p deb-new/DEBIAN
sed "s/Package:\ bazel/Package:\ bazel-${bazel_version}/g" "deb-old/DEBIAN/control" > "deb-new/DEBIAN/control"

# Rename the actual Bazel binary to bazel-${bazel_version}
mkdir -p deb-new/usr/bin
cp "deb-old/usr/bin/bazel-real" "deb-new/usr/bin/bazel-${bazel_version}"

# Re-pack the debian package and add it to the repo
versioned_deb_pkg_name="bazel-${bazel_version}-versioned-package-amd64.deb"
chmod -R 0755 deb-new
dpkg-deb -b deb-new "${versioned_deb_pkg_name}"
reprepro -C jdk1.8 includedeb "${distribution}" "${versioned_deb_pkg_name}"
}

function create_apt_repository() {
mkdir conf
cat > conf/distributions <<EOF
Expand Down Expand Up @@ -259,6 +346,10 @@ EOF
reprepro -C jdk1.8 includedeb "${distribution}" "${deb_pkg_name}"
reprepro -C jdk1.8 includedsc "${distribution}" "${deb_dsc_name}"

add_versioned_deb_pkg "${distribution}" "${deb_pkg_name}"

merge_previous_dists "${distribution}"

gsutil -m cp -r dists pool "gs://bazel-apt"
}

Expand Down
7 changes: 3 additions & 4 deletions scripts/packages/debian/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//scripts:__subpackages__"],
)

load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")

pkg_tar(
name = "bazel-bin",
srcs = [
Expand Down Expand Up @@ -69,7 +69,7 @@ genrule(
pkg_deb(
name = "bazel-debian",
architecture = "amd64",
built_using = "bazel (HEAD)",
built_using = "bazel",
conffiles = [
"etc/bash_completion.d/bazel",
"etc/bazel.bazelrc",
Expand All @@ -80,7 +80,6 @@ pkg_deb(
"g++",
"zlib1g-dev",
"unzip",
"python",
],
description_file = "description",
homepage = "http://bazel.build",
Expand Down

0 comments on commit 3162705

Please sign in to comment.