Skip to content

Commit c231272

Browse files
authored
build: standardize release asset naming (#1729)
* build: standardize release asset naming (#1728) Rework build.sh so released assets have stable, predictable names that are easy to automate against: - drop the generated timestamp from tarball names - drop the "-binary" infix from tarball names - name macOS tarballs with "darwin" (matches GOOS) instead of "osx" - drop the version from .rpm/.deb filenames; the release download URL already carries it. Package metadata still records version + epoch - build arm64 .rpm and .deb in addition to amd64, using each ecosystem's arch convention (x86_64/aarch64 for rpm, amd64/arm64 for deb) - stop publishing the bare "gh-ost" binary; it was just the last build (darwin/arm64) and was ambiguous. Tarballs and packages cover every OS/arch - emit a SHA256SUMS manifest so downloads can be verified with `sha256sum -c SHA256SUMS` Resulting assets: gh-ost-{linux,darwin}-{amd64,arm64}.tar.gz gh-ost.{x86_64,aarch64}.rpm gh-ost.{amd64,arm64}.deb SHA256SUMS Also refactor build() to take GOOS/GOARCH directly, share common fpm flags via an array, and update the README build.sh description. * build: simplify packaging Dockerfile and dock script (#1728) Slim down the release packaging tooling: - Dockerfile.packaging: collapse the per-package RUN layers into one, drop packages already provided by the golang:bookworm base (git, tar, curl, gcc, g++, bash) and the unused rsync, and drop the legacy GOPATH src layout (the build is module-mode). Only ruby/ruby-dev/build-essential (for fpm) and rpm (for rpmbuild) are installed now. - Use a multi-stage build with a `scratch` artifacts stage so `docker build --output type=local` exports the assets straight to the host. This drops the intermediate container, bind mount, -it TTY and find|xargs cp dance from `script/dock pkg`. - build.sh: stage the fpm package tree in the system temp dir instead of under $buildpath, so it never lands among the exported release artifacts.
1 parent 64a6e3d commit c231272

4 files changed

Lines changed: 68 additions & 46 deletions

File tree

Dockerfile.packaging

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
FROM golang:1.25.9-bookworm
1+
FROM golang:1.25.9-bookworm AS build
22

3-
RUN apt-get update
4-
RUN apt-get install -y ruby ruby-dev rubygems build-essential
5-
RUN gem install fpm
6-
ENV GOPATH=/tmp/go
3+
# build.sh shells out to fpm to produce the .deb/.rpm packages. fpm is a Ruby
4+
# gem (needs ruby + ruby-dev + a C toolchain), and the rpm target needs
5+
# rpmbuild from the `rpm` package. Everything else build.sh uses (git, tar,
6+
# gcc, bash, ...) already ships in the golang:bookworm base image.
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends ruby ruby-dev build-essential rpm \
9+
&& rm -rf /var/lib/apt/lists/* \
10+
&& gem install --no-document fpm
711

8-
RUN apt-get install -y curl
9-
RUN apt-get install -y rsync
10-
RUN apt-get install -y gcc
11-
RUN apt-get install -y g++
12-
RUN apt-get install -y bash
13-
RUN apt-get install -y git
14-
RUN apt-get install -y tar
15-
RUN apt-get install -y rpm
16-
17-
RUN mkdir -p $GOPATH/src/github.com/github/gh-ost
18-
WORKDIR $GOPATH/src/github.com/github/gh-ost
12+
WORKDIR /gh-ost
1913
COPY . .
2014
RUN bash build.sh
15+
16+
# Export-only stage: `docker build --target artifacts --output type=local,dest=...`
17+
# writes just the release assets to the host, no intermediate container needed.
18+
FROM scratch AS artifacts
19+
COPY --from=build /tmp/gh-ost-release/ /

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Please see [Coding gh-ost](doc/coding-ghost.md) for a guide to getting started d
9797

9898
`gh-ost` is a Go project; it is built with Go `1.15` and above. To build on your own, use either:
9999
- [script/build](https://github.com/github/gh-ost/blob/master/script/build) - this is the same build script used by CI hence the authoritative; artifact is `./bin/gh-ost` binary.
100-
- [build.sh](https://github.com/github/gh-ost/blob/master/build.sh) for building `tar.gz` artifacts in `/tmp/gh-ost-release`
100+
- [build.sh](https://github.com/github/gh-ost/blob/master/build.sh) for building the release artifacts (`tar.gz` archives plus `.rpm`/`.deb` packages and a `SHA256SUMS` manifest) in `/tmp/gh-ost-release`
101101

102102
Generally speaking, `master` branch is stable, but only [releases](https://github.com/github/gh-ost/releases) are to be used in production.
103103

build.sh

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,61 @@
33
RELEASE_VERSION=
44
buildpath=
55

6+
# Create a scratch tree to stage the package filesystem for fpm. It lives in the
7+
# system temp dir, not $buildpath, so it never lands among the release artifacts.
68
function setuptree() {
7-
b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1
9+
b=$( mktemp -d ) || return 1
810
mkdir -p $b/gh-ost
911
mkdir -p $b/gh-ost/usr/bin
1012
echo $b
1113
}
1214

1315
function build {
14-
osname=$1
15-
osshort=$2
16-
GOOS=$3
17-
GOARCH=$4
16+
GOOS=$1
17+
GOARCH=$2
1818

1919
if ! go version | egrep -q 'go1\.(1[5-9]|[2-9][0-9]{1})' ; then
2020
echo "go version must be 1.15 or above"
2121
exit 1
2222
fi
2323

24-
echo "Building ${osname}-${GOARCH} binary"
24+
echo "Building ${GOOS}-${GOARCH} binary"
2525
export GOOS
2626
export GOARCH
2727
CGO_ENABLED="${CGO_ENABLED:-0}" go build -ldflags "$ldflags" -o "$buildpath/$target" go/cmd/gh-ost/main.go
2828

2929
if [ $? -ne 0 ]; then
30-
echo "Build failed for ${osname} ${GOARCH}."
30+
echo "Build failed for ${GOOS} ${GOARCH}."
3131
exit 1
3232
fi
3333

34-
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${GOARCH}-${timestamp}.tar.gz $target)
34+
(cd $buildpath && tar cfz ./gh-ost-${GOOS}-${GOARCH}.tar.gz $target)
3535

36-
# build RPM and deb for Linux, x86-64 only
37-
if [ "$GOOS" == "linux" ] && [ "$GOARCH" == "amd64" ] ; then
36+
# build RPM and deb packages for Linux
37+
if [ "$GOOS" == "linux" ] ; then
3838
echo "Creating Distro full packages"
39+
case "$GOARCH" in
40+
amd64) rpm_arch=x86_64 ; deb_arch=amd64 ;;
41+
arm64) rpm_arch=aarch64 ; deb_arch=arm64 ;;
42+
*) rpm_arch=$GOARCH ; deb_arch=$GOARCH ;;
43+
esac
3944
builddir=$(setuptree)
4045
cp $buildpath/$target $builddir/gh-ost/usr/bin
4146
cd $buildpath
42-
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m 'GitHub' --description "GitHub's Online Schema Migrations for MySQL " --url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0" -C $builddir/gh-ost --prefix=/ -t rpm --rpm-rpmbuild-define "_build_id_links none" --rpm-os linux .
43-
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m 'GitHub' --description "GitHub's Online Schema Migrations for MySQL " --url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0" -C $builddir/gh-ost --prefix=/ -t deb --deb-no-default-config-files .
47+
48+
fpm_opts=(
49+
-v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost
50+
-m 'GitHub' --description "GitHub's Online Schema Migrations for MySQL "
51+
--url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0"
52+
-C "$builddir/gh-ost" --prefix=/
53+
)
54+
fpm "${fpm_opts[@]}" -t rpm -a "${rpm_arch}" -p "gh-ost.${rpm_arch}.rpm" --rpm-rpmbuild-define "_build_id_links none" --rpm-os linux .
55+
fpm "${fpm_opts[@]}" -t deb -a "${deb_arch}" -p "gh-ost.${deb_arch}.deb" --deb-no-default-config-files .
4456
cd -
4557
fi
58+
59+
# Drop the bare binary so only tarballs and packages are published as release assets
60+
rm -f "$buildpath/$target"
4661
}
4762

4863
main() {
@@ -60,22 +75,23 @@ main() {
6075

6176
buildpath=/tmp/gh-ost-release
6277
target=gh-ost
63-
timestamp=$(date "+%Y%m%d%H%M%S")
6478
ldflags="-X main.AppVersion=${RELEASE_VERSION} -X main.GitCommit=${GIT_COMMIT}"
6579

6680
mkdir -p ${buildpath}
6781
rm -rf ${buildpath:?}/*
68-
build GNU/Linux linux linux amd64
69-
build GNU/Linux linux linux arm64
70-
build macOS osx darwin amd64
71-
build macOS osx darwin arm64
72-
73-
bin_files=$(find $buildpath/gh-ost* -type f -maxdepth 1)
74-
echo "Binaries found in:"
75-
echo "$bin_files"
76-
82+
build linux amd64
83+
build linux arm64
84+
build darwin amd64
85+
build darwin arm64
86+
87+
# Generate a SHA256SUMS manifest with basenames only, so a downloaded set can be
88+
# verified in place with `sha256sum -c SHA256SUMS` (no absolute build paths leak in).
89+
# The name has no gh-ost prefix, so it self-excludes from the gh-ost* glob below.
7790
echo "Checksums:"
78-
(shasum -a256 $bin_files 2>/dev/null)
91+
( cd "$buildpath" && shasum -a256 gh-ost* | tee SHA256SUMS )
92+
93+
echo "Release assets:"
94+
ls -1 "$buildpath"
7995

8096
echo "Build Success!"
8197
}

script/dock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22

3+
set -e
4+
35
# Usage:
4-
# dock <test|packages> [arg]
5-
# dock test: build gh-ost & run unit and integration tests
6-
# docker pkg [target-path]: build gh-ost release packages and copy to target path (default path: /tmp/gh-ost-release)
6+
# dock <test|pkg> [arg]
7+
# dock test: build gh-ost & run unit and integration tests
8+
# dock pkg [target-path]: build gh-ost release packages and write them to
9+
# target-path (default: /tmp/gh-ost-release)
710

811
command="$1"
912

@@ -14,12 +17,16 @@ case "$command" in
1417
;;
1518
"pkg")
1619
packages_path="${2:-/tmp/gh-ost-release}"
17-
docker_target="gh-ost-packaging"
18-
docker build . -f Dockerfile.packaging -t "${docker_target}" && docker run --rm -it -v "${packages_path}:/tmp/pkg" "${docker_target}:latest" bash -c 'find /tmp/gh-ost-release/ -maxdepth 1 -type f | xargs cp -t /tmp/pkg'
20+
# BuildKit exports the artifacts stage straight to the host; no intermediate
21+
# container, bind mount, or copy step needed. Requires BuildKit (default in
22+
# modern Docker; set DOCKER_BUILDKIT=1 on older daemons).
23+
DOCKER_BUILDKIT=1 docker build . -f Dockerfile.packaging \
24+
--target artifacts --output "type=local,dest=${packages_path}"
1925
echo "packages generated on ${packages_path}:"
2026
ls -l "${packages_path}"
2127
;;
2228
*)
23-
>&2 echo "Usage: dock dock <test|alpine|packages> [arg]"
29+
>&2 echo "Usage: dock <test|pkg> [target-path]"
2430
exit 1
31+
;;
2532
esac

0 commit comments

Comments
 (0)