Skip to content

Commit 3e9d5bc

Browse files
committed
feat: Improve reproducibility of AppImage builds.
Also add a verifier script so the AppImage build can be verified locally. The current 0.8.3 release is a big mess, so we can't actually test this. 0.8.4 should be better, so we can test it there.
1 parent 4112161 commit 3e9d5bc

5 files changed

Lines changed: 497 additions & 39 deletions

File tree

‎bin/check_release‎

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import ast
33
import os
44
import re
5-
import subprocess
5+
import subprocess # nosec
66
import sys
7-
from typing import cast
8-
from typing import List
9-
from typing import Optional
7+
from typing import List, Optional, cast
108

119
import requests
1210

@@ -15,10 +13,14 @@ def github_repo() -> str:
1513
repo = os.environ.get("GITHUB_REPOSITORY")
1614
if repo:
1715
return repo
18-
return (subprocess.run(
19-
["git", "remote", "get-url", "upstream"],
20-
check=True,
21-
capture_output=True).stdout.decode("utf-8").strip().split(":")[1])
16+
return (
17+
subprocess.run(
18+
["git", "remote", "get-url", "upstream"], check=True, capture_output=True
19+
)
20+
.stdout.decode("utf-8")
21+
.strip()
22+
.split(":")[1]
23+
)
2224

2325

2426
def release_github() -> Optional[str]:
@@ -72,9 +74,12 @@ def release_milestone() -> str:
7274
sys.exit(1)
7375

7476
return print_semver(
75-
sorted(v for v in tuple(
76-
parse_semver(cast(str, ms["title"])) for ms in milestones)
77-
if v)[0])
77+
sorted(
78+
v
79+
for v in tuple(parse_semver(cast(str, ms["title"])) for ms in milestones)
80+
if v
81+
)[0]
82+
)
7883

7984

8085
def release_pr_milestone() -> Optional[str]:
@@ -98,14 +103,18 @@ def release_local(path: str) -> tuple[Optional[str], str, bool]:
98103
with open(os.path.join(path, "BUILD.bazel"), "r") as fh:
99104
bzl = ast.parse(fh.read(), filename=path)
100105
for stmt in bzl.body:
101-
if (isinstance(stmt, ast.Expr)
102-
and isinstance(stmt.value, ast.Call)
103-
and isinstance(stmt.value.func, ast.Name)
104-
and stmt.value.func.id == "haskell_library"):
106+
if (
107+
isinstance(stmt, ast.Expr)
108+
and isinstance(stmt.value, ast.Call)
109+
and isinstance(stmt.value.func, ast.Name)
110+
and stmt.value.func.id == "haskell_library"
111+
):
105112
for arg in stmt.value.keywords:
106-
if (arg.arg == "version"
107-
and isinstance(arg.value, ast.Constant)
108-
and isinstance(arg.value.s, str)):
113+
if (
114+
arg.arg == "version"
115+
and isinstance(arg.value, ast.Constant)
116+
and isinstance(arg.value.s, str)
117+
):
109118
return arg.value.s, "BUILD.bazel", True
110119

111120
if os.path.exists(os.path.join(path, "configure.ac")):
@@ -147,24 +156,34 @@ def main(prog: str, args: List[str]) -> None:
147156
print(f"Local release: {local_release} ({local_origin})")
148157

149158
if local_required and gh_release and gh_release != local_release:
150-
print(f"\nFAIL: GitHub draft release {gh_release} does not match "
151-
f"{local_origin} {local_release}")
159+
print(
160+
f"\nFAIL: GitHub draft release {gh_release} does not match "
161+
f"{local_origin} {local_release}"
162+
)
152163
sys.exit(1)
153164
if local_required and ms_release != local_release:
154-
print(f"\nFAIL: Next GitHub Milestone release {ms_release} does not "
155-
f"match {local_origin} {local_release}")
165+
print(
166+
f"\nFAIL: Next GitHub Milestone release {ms_release} does not "
167+
f"match {local_origin} {local_release}"
168+
)
156169
sys.exit(1)
157170
if local_required and pr_release and pr_release != local_release:
158-
print(f"\nFAIL: PR milestone {pr_release} does not match "
159-
f"{local_origin} {local_release}")
171+
print(
172+
f"\nFAIL: PR milestone {pr_release} does not match "
173+
f"{local_origin} {local_release}"
174+
)
160175
sys.exit(1)
161176
if gh_release and gh_release != ms_release:
162-
print(f"\nFAIL: GitHub draft release {gh_release} does not match "
163-
f"next GitHub Milestone release {ms_release}")
177+
print(
178+
f"\nFAIL: GitHub draft release {gh_release} does not match "
179+
f"next GitHub Milestone release {ms_release}"
180+
)
164181
sys.exit(1)
165182
if pr_release and pr_release != ms_release:
166-
print(f"\nFAIL: PR milestone {pr_release} does not match "
167-
f"next GitHub Milestone release {ms_release}")
183+
print(
184+
f"\nFAIL: PR milestone {pr_release} does not match "
185+
f"next GitHub Milestone release {ms_release}"
186+
)
168187
sys.exit(1)
169188

170189
print(f"\nPASS: Upcoming release version is {gh_release}")

‎platform/appimage/build.sh‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
# Fail out on error
88
set -exuo pipefail
99

10+
# https://stackoverflow.com/questions/72978485/git-submodule-update-failed-with-fatal-detected-dubious-ownership-in-reposit
11+
git config --global --add safe.directory '*'
12+
13+
# Ensure consistent file permissions
14+
umask 022
15+
16+
# Support reproducible builds
17+
if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then
18+
export SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)"
19+
fi
20+
1021
usage() {
1122
echo "$0 --src-dir SRC_DIR --project-name PROJECT_NAME [cmake args]"
1223
echo "Builds an app image in the CWD based off PROJECT_NAME installation at SRC_DIR"
@@ -60,24 +71,29 @@ if [ -z "${PROJECT_NAME+x}" ]; then
6071
exit 1
6172
fi
6273

63-
# https://stackoverflow.com/questions/72978485/git-submodule-update-failed-with-fatal-detected-dubious-ownership-in-reposit
64-
git config --global --add safe.directory '*'
65-
6674
# Check if we can git describe
6775
git describe --tags --match 'v*'
6876

6977
# directory paths
7078
readonly BUILD_DIR="$(realpath .)"
7179
readonly PROJECT_APP_DIR="$BUILD_DIR/$PROJECT_NAME.AppDir"
7280

81+
# Pin appimagetool version for reproducibility
82+
readonly APPIMAGE_TOOL_VERSION="940"
83+
readonly APPIMAGE_TOOL_URL="https://github.com/probonopd/go-appimage/releases/download/continuous/appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage"
84+
7385
rm -f appimagetool-*.AppImage
74-
wget "https://github.com/$(wget -q https://github.com/probonopd/go-appimage/releases/expanded_assets/continuous -O - | grep "appimagetool-.*-x86_64.AppImage" | head -n 1 | cut -d '"' -f 2)"
86+
wget "$APPIMAGE_TOOL_URL" -O "appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage"
7587
chmod +x appimagetool-*.AppImage
7688

77-
# https://github.com/probonopd/go-appimage/blob/fced8b8831039daa246ab355f4e2335074abc206/src/appimagetool/appdirtool.go#L400
78-
# This line in the appimagetool breaks musl DNS lookups (looking for /EEE/resolv.conf).
79-
./appimagetool-*.AppImage --appimage-extract
80-
sed -i -e 's!/EEE!/etc!g' squashfs-root/usr/bin/appimagetool
89+
# Extract tool to a isolated directory to avoid polluting the workspace/AppImage
90+
readonly TOOL_EXTRACT_DIR="$BUILD_DIR/tool-extract"
91+
rm -rf "$TOOL_EXTRACT_DIR"
92+
"./appimagetool-$APPIMAGE_TOOL_VERSION-x86_64.AppImage" --appimage-extract
93+
mv squashfs-root "$TOOL_EXTRACT_DIR"
94+
95+
# Patch the tool for musl compatibility
96+
sed -i -e 's!/EEE!/etc!g' "$TOOL_EXTRACT_DIR/usr/bin/appimagetool"
8197

8298
export PKG_CONFIG_PATH=/opt/buildhome/lib/pkgconfig
8399

@@ -92,13 +108,21 @@ cmake "$SRC_DIR" \
92108
-DCMAKE_INSTALL_PREFIX=/usr \
93109
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
94110
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
111+
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--build-id=none" \
95112
-B _build \
96113
"$@"
97114
cmake --build _build
98115
cmake --install _build --prefix "$PROJECT_NAME.AppDir/usr"
99116

100117
ccache --show-stats
101118

119+
# Normalize file permissions and timestamps for reproducibility
120+
echo "Normalizing AppDir..."
121+
find "$PROJECT_APP_DIR" -exec touch -h -d @"$SOURCE_DATE_EPOCH" {} +
122+
find "$PROJECT_APP_DIR" -type d -exec chmod 0755 {} +
123+
find "$PROJECT_APP_DIR" -type f -perm /0111 -exec chmod 0755 {} +
124+
find "$PROJECT_APP_DIR" -type f ! -perm /0111 -exec chmod 0644 {} +
125+
102126
export QTDIR=/opt/buildhome/qt
103127
export LD_LIBRARY_PATH="/opt/buildhome/lib:/opt/buildhome/lib64:$QTDIR/lib"
104128

@@ -109,12 +133,19 @@ cp -r "$QTDIR/plugins/platforms/libqwayland-generic.so" "$PROJECT_APP_DIR/$QTDIR
109133
# Copy the tls plugins to the app dir, needed for https connections.
110134
cp -r "$QTDIR/plugins/tls/" "$PROJECT_APP_DIR/$QTDIR/plugins/"
111135

112-
squashfs-root/AppRun -s deploy "$PROJECT_APP_DIR"/usr/share/applications/*.desktop
136+
"$TOOL_EXTRACT_DIR/AppRun" -s deploy "$PROJECT_APP_DIR"/usr/share/applications/*.desktop
113137

114138
# print all links not contained inside the AppDir
115139
LD_LIBRARY_PATH='' find "$PROJECT_APP_DIR" -type f -exec ldd {} \; 2>&1 | grep '=>' | grep -v "$PROJECT_APP_DIR"
116140

117-
squashfs-root/AppRun "$PROJECT_APP_DIR"
141+
# appimagetool (go-appimage) passes -fstime to mksquashfs, which conflicts with
142+
# SOURCE_DATE_EPOCH environment variable.
143+
(
144+
unset SOURCE_DATE_EPOCH
145+
"$TOOL_EXTRACT_DIR/AppRun" "$PROJECT_APP_DIR"
146+
)
118147

119-
APPIMAGE_FILE="$PROJECT_NAME-$(git rev-parse --short HEAD | head -c7)-$ARCH.AppImage"
148+
# Deterministic filename
149+
readonly SHA="$(git rev-parse --short HEAD | head -c7)"
150+
APPIMAGE_FILE="$PROJECT_NAME-$SHA-$ARCH.AppImage"
120151
sha256sum "$APPIMAGE_FILE" >"$APPIMAGE_FILE.sha256"

‎tools/verify_all.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
# Copyright © 2026 The TokTok team
4+
import argparse
5+
import os
6+
import subprocess # nosec
7+
import sys
8+
9+
# Add tools directory to path to allow importing lib and other tools
10+
tools_dir = os.path.dirname(os.path.abspath(__file__))
11+
if tools_dir not in sys.path:
12+
sys.path.append(tools_dir)
13+
14+
from lib import git
15+
16+
import verify_common
17+
18+
19+
def main() -> None:
20+
parser = argparse.ArgumentParser(
21+
description="Run all reproducibility verifications."
22+
)
23+
parser.add_argument("--tag", help="Tag to verify", default=git.current_tag())
24+
parser.add_argument(
25+
"--repo", help="Repository name", default=verify_common.get_default_repo()
26+
)
27+
args = parser.parse_args()
28+
29+
tag = args.tag
30+
repo = args.repo
31+
32+
scripts = [
33+
os.path.join(tools_dir, "verify_appimage.py"),
34+
]
35+
36+
failed = []
37+
for script in scripts:
38+
print(
39+
f"--- Running {os.path.basename(script)} for {repo} {tag} ---",
40+
file=sys.stderr,
41+
)
42+
cmd = [sys.executable, script, "--tag", tag, "--repo", repo]
43+
if subprocess.run(cmd).returncode != 0: # nosec
44+
failed.append(os.path.basename(script))
45+
46+
if failed:
47+
print(f"Verifications failed: {', '.join(failed)}", file=sys.stderr)
48+
sys.exit(1)
49+
else:
50+
print(f"All verifications passed for {repo} {tag}!", file=sys.stderr)
51+
sys.exit(0)
52+
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)