Skip to content

Commit 1fd56c1

Browse files
author
Artem Ermoshkin
committed
.deb package caching
1 parent 3765f16 commit 1fd56c1

5 files changed

Lines changed: 221 additions & 109 deletions

File tree

.github/workflows/release_publish.yaml

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,68 +39,33 @@ jobs:
3939
submodules: true
4040
ref: ${{ steps.tag.outputs.ref }}
4141

42+
- name: Prepare Debian package cache key
43+
id: deb-package-cache-key
44+
shell: bash
45+
run: |
46+
echo "prefix=ubuntu-24.04-deb-packages-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'contrib/**', 'include/**', 'library/**', 'plugins/**', 'scripts/build_cpack_deb_packages.sh', 'scripts/generate-debian-directory.sh', 'scripts/googleapis_deb/**', 'src/**', 'third_party/api-common-protos/**', 'tools/**', 'util/**') }}" >> "$GITHUB_OUTPUT"
47+
48+
- name: Restore Debian package build cache
49+
uses: actions/cache/restore@v4
50+
with:
51+
path: |
52+
.deb-ccache
53+
build_googleapis_deb
54+
build-deb
55+
key: ${{ steps.deb-package-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}
56+
restore-keys: |
57+
${{ steps.deb-package-cache-key.outputs.prefix }}-
58+
ubuntu-24.04-deb-packages-
59+
4260
- name: Build .deb packages in Ubuntu 24.04 container
4361
shell: bash
4462
run: |
45-
mkdir -p artifacts
63+
mkdir -p artifacts .deb-ccache build_googleapis_deb build-deb
4664
docker run --rm --network host \
65+
-e CCACHE_DIR=/source/.deb-ccache \
4766
-v "$PWD:/source" \
4867
ubuntu:24.04 \
49-
bash -c '
50-
set -e
51-
export DEBIAN_FRONTEND=noninteractive
52-
apt-get update
53-
apt-get install -y \
54-
build-essential \
55-
cmake \
56-
pkg-config \
57-
git \
58-
libidn11-dev \
59-
libssl-dev \
60-
zlib1g-dev \
61-
libprotobuf-dev \
62-
protobuf-compiler \
63-
libgrpc++-dev \
64-
protobuf-compiler-grpc \
65-
libbrotli-dev \
66-
liblz4-dev \
67-
libzstd-dev \
68-
libbz2-dev \
69-
libxxhash-dev \
70-
libsnappy-dev \
71-
libdouble-conversion-dev \
72-
libgtest-dev \
73-
libre2-dev \
74-
libc-ares-dev \
75-
rapidjson-dev \
76-
python3 \
77-
python3-six \
78-
ragel \
79-
yasm
80-
81-
cd /source
82-
cmake -S scripts/googleapis_deb -B build_googleapis_deb -DCMAKE_INSTALL_PREFIX=/usr/share/yandex
83-
cmake --build build_googleapis_deb -j$(nproc)
84-
cmake --build build_googleapis_deb --target package
85-
dpkg -i build_googleapis_deb/*.deb
86-
87-
./scripts/generate-debian-directory.sh
88-
cmake -S . -B build-deb \
89-
-DCMAKE_BUILD_TYPE=Release \
90-
-DYDB_SDK_INSTALL=ON \
91-
-DYDB_SDK_EXAMPLES=OFF \
92-
-DYDB_SDK_TESTS=OFF \
93-
-DYDB_SDK_ENABLE_OTEL_METRICS=ON \
94-
-DYDB_SDK_ENABLE_OTEL_TRACE=ON \
95-
-DBUILD_SHARED_LIBS=OFF \
96-
-DYDB_SDK_USE_SYSTEM_GOOGLEAPIS=ON \
97-
-DCMAKE_INSTALL_PREFIX=/usr/share/yandex \
98-
-DCMAKE_PREFIX_PATH="/usr/share/yandex"
99-
cmake --build build-deb --target package -j$(nproc)
100-
101-
cp build_googleapis_deb/*.deb /source/artifacts/
102-
cp build-deb/*.deb /source/artifacts/
103-
'
68+
bash /source/scripts/build_cpack_deb_packages.sh /source/artifacts
10469
10570
- name: Smoke-test generated .deb packages
10671
shell: bash

.github/workflows/tests.yaml

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -262,72 +262,51 @@ jobs:
262262
with:
263263
submodules: true
264264

265+
- name: Prepare Debian package cache key
266+
id: deb-package-cache-key
267+
shell: bash
268+
run: |
269+
echo "prefix=ubuntu-24.04-deb-packages-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'contrib/**', 'include/**', 'library/**', 'plugins/**', 'scripts/build_cpack_deb_packages.sh', 'scripts/generate-debian-directory.sh', 'scripts/googleapis_deb/**', 'src/**', 'third_party/api-common-protos/**', 'tools/**', 'util/**') }}" >> "$GITHUB_OUTPUT"
270+
265271
- name: Validate dpkg-buildpackage
266272
shell: bash
267273
run: |
268274
./scripts/test_dpkg_buildpackage.sh
269275
276+
- name: Restore Debian package build cache
277+
id: deb-package-cache
278+
uses: actions/cache/restore@v4
279+
with:
280+
path: |
281+
.deb-ccache
282+
build_googleapis_deb
283+
build-deb
284+
key: ${{ steps.deb-package-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}
285+
restore-keys: |
286+
${{ steps.deb-package-cache-key.outputs.prefix }}-
287+
ubuntu-24.04-deb-packages-
288+
270289
- name: Build CPack .deb packages
271290
shell: bash
272291
run: |
292+
mkdir -p .deb-ccache build_googleapis_deb build-deb
273293
docker run --rm --network host \
294+
-e CCACHE_DIR=/source/.deb-ccache \
274295
-v "$PWD:/source" \
275296
ubuntu:24.04 \
276-
bash -c '
277-
set -e
278-
export DEBIAN_FRONTEND=noninteractive
279-
apt-get update
280-
apt-get install -y \
281-
build-essential \
282-
cmake \
283-
pkg-config \
284-
git \
285-
libidn11-dev \
286-
libssl-dev \
287-
zlib1g-dev \
288-
libprotobuf-dev \
289-
protobuf-compiler \
290-
libgrpc++-dev \
291-
protobuf-compiler-grpc \
292-
libbrotli-dev \
293-
liblz4-dev \
294-
libzstd-dev \
295-
libbz2-dev \
296-
libxxhash-dev \
297-
libsnappy-dev \
298-
libdouble-conversion-dev \
299-
libgtest-dev \
300-
libre2-dev \
301-
libc-ares-dev \
302-
rapidjson-dev \
303-
python3 \
304-
python3-six \
305-
ragel \
306-
yasm
307-
308-
cd /source
309-
cmake -S scripts/googleapis_deb -B build_googleapis_deb -DCMAKE_INSTALL_PREFIX=/usr/share/yandex
310-
cmake --build build_googleapis_deb -j$(nproc)
311-
cmake --build build_googleapis_deb --target package
312-
dpkg -i build_googleapis_deb/*.deb
313-
314-
./scripts/generate-debian-directory.sh
315-
cmake -S . -B build-deb \
316-
-DCMAKE_BUILD_TYPE=Release \
317-
-DYDB_SDK_INSTALL=ON \
318-
-DYDB_SDK_EXAMPLES=OFF \
319-
-DYDB_SDK_TESTS=OFF \
320-
-DYDB_SDK_ENABLE_OTEL_METRICS=ON \
321-
-DYDB_SDK_ENABLE_OTEL_TRACE=ON \
322-
-DBUILD_SHARED_LIBS=OFF \
323-
-DYDB_SDK_USE_SYSTEM_GOOGLEAPIS=ON \
324-
-DCMAKE_INSTALL_PREFIX=/usr/share/yandex \
325-
-DCMAKE_PREFIX_PATH="/usr/share/yandex"
326-
cmake --build build-deb --target package -j$(nproc)
327-
cp build_googleapis_deb/*.deb build-deb/
328-
'
297+
bash /source/scripts/build_cpack_deb_packages.sh /source/build-deb
329298
330299
- name: Smoke-test generated .deb packages
331300
shell: bash
332301
run: |
333302
./scripts/test_deb_packages.sh build-deb
303+
304+
- name: Save Debian package build cache
305+
if: github.event_name != 'pull_request' && success() && steps.deb-package-cache.outputs.cache-hit != 'true'
306+
uses: actions/cache/save@v4
307+
with:
308+
path: |
309+
.deb-ccache
310+
build_googleapis_deb
311+
build-deb
312+
key: ${{ steps.deb-package-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}

.github/workflows/warmup_cache.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,47 @@ jobs:
8181
with:
8282
path: build
8383
key: ${{ steps.coverage-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}
84+
85+
deb-packages:
86+
name: Build Debian packages and cache artifacts
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
with:
92+
submodules: true
93+
- name: Prepare Debian package cache key
94+
id: deb-package-cache-key
95+
shell: bash
96+
run: |
97+
echo "prefix=ubuntu-24.04-deb-packages-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'contrib/**', 'include/**', 'library/**', 'plugins/**', 'scripts/build_cpack_deb_packages.sh', 'scripts/generate-debian-directory.sh', 'scripts/googleapis_deb/**', 'src/**', 'third_party/api-common-protos/**', 'tools/**', 'util/**') }}" >> "$GITHUB_OUTPUT"
98+
- name: Restore Debian package build cache
99+
id: deb-package-cache
100+
uses: actions/cache/restore@v4
101+
with:
102+
path: |
103+
.deb-ccache
104+
build_googleapis_deb
105+
build-deb
106+
key: ${{ steps.deb-package-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}
107+
restore-keys: |
108+
${{ steps.deb-package-cache-key.outputs.prefix }}-
109+
ubuntu-24.04-deb-packages-
110+
- name: Build CPack .deb packages
111+
shell: bash
112+
run: |
113+
mkdir -p .deb-ccache build_googleapis_deb build-deb
114+
docker run --rm --network host \
115+
-e CCACHE_DIR=/source/.deb-ccache \
116+
-v "$PWD:/source" \
117+
ubuntu:24.04 \
118+
bash /source/scripts/build_cpack_deb_packages.sh /source/build-deb
119+
- name: Save Debian package build cache
120+
if: steps.deb-package-cache.outputs.cache-hit != 'true'
121+
uses: actions/cache/save@v4
122+
with:
123+
path: |
124+
.deb-ccache
125+
build_googleapis_deb
126+
build-deb
127+
key: ${{ steps.deb-package-cache-key.outputs.prefix }}-${{ github.run_id }}-${{ github.run_attempt }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ __pycache__/
5050
/build
5151
/build_*
5252
/build-*
53+
/.deb-ccache/
54+
/artifacts/
5355

5456
.idea/
5557
.vscode/
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SOURCE_DIR="${SOURCE_DIR:-/source}"
5+
if [ ! -d "$SOURCE_DIR" ]; then
6+
SOURCE_DIR=$(dirname "$(realpath "$0")")/..
7+
SOURCE_DIR=$(realpath "$SOURCE_DIR")
8+
fi
9+
10+
OUTPUT_DIR="${1:-build-deb}"
11+
12+
cd "$SOURCE_DIR"
13+
mkdir -p "$OUTPUT_DIR"
14+
OUTPUT_DIR=$(realpath "$OUTPUT_DIR")
15+
16+
export DEBIAN_FRONTEND=noninteractive
17+
export CCACHE_DIR="${CCACHE_DIR:-/root/.ccache}"
18+
mkdir -p "$CCACHE_DIR"
19+
20+
if [ "${YDB_DEB_INSTALL_DEPS:-1}" = "1" ]; then
21+
apt-get update
22+
apt-get install -y --no-install-recommends \
23+
build-essential \
24+
ccache \
25+
cmake \
26+
pkg-config \
27+
git \
28+
libidn11-dev \
29+
libssl-dev \
30+
zlib1g-dev \
31+
libprotobuf-dev \
32+
protobuf-compiler \
33+
libgrpc++-dev \
34+
protobuf-compiler-grpc \
35+
libbrotli-dev \
36+
liblz4-dev \
37+
libzstd-dev \
38+
libbz2-dev \
39+
libxxhash-dev \
40+
libsnappy-dev \
41+
libdouble-conversion-dev \
42+
libgtest-dev \
43+
libre2-dev \
44+
libc-ares-dev \
45+
rapidjson-dev \
46+
python3 \
47+
python3-six \
48+
ragel \
49+
yasm
50+
fi
51+
52+
touch_existing_sources() {
53+
for path in "$@"; do
54+
if [ -e "$path" ]; then
55+
find "$path" -type f -exec touch {} +
56+
fi
57+
done
58+
}
59+
60+
rm -f build_googleapis_deb/*.deb build-deb/*.deb "$OUTPUT_DIR"/*.deb 2>/dev/null || true
61+
62+
if command -v ccache >/dev/null 2>&1; then
63+
ccache --zero-stats >/dev/null || true
64+
CMAKE_COMPILER_LAUNCHER_ARGS=(
65+
-DCMAKE_C_COMPILER_LAUNCHER=ccache
66+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
67+
)
68+
else
69+
CMAKE_COMPILER_LAUNCHER_ARGS=()
70+
fi
71+
72+
# Restored build-cache archives can have outputs newer than the checkout.
73+
# Touch package inputs so the incremental build cannot hide source changes.
74+
touch_existing_sources scripts/googleapis_deb third_party/api-common-protos
75+
cmake -S scripts/googleapis_deb -B build_googleapis_deb \
76+
-DCMAKE_INSTALL_PREFIX=/usr/share/yandex \
77+
"${CMAKE_COMPILER_LAUNCHER_ARGS[@]}"
78+
cmake --build build_googleapis_deb -j"$(nproc)"
79+
cmake --build build_googleapis_deb --target package
80+
dpkg -i build_googleapis_deb/*.deb
81+
82+
./scripts/generate-debian-directory.sh
83+
84+
touch_existing_sources \
85+
CMakeLists.txt \
86+
cmake \
87+
contrib \
88+
include \
89+
library \
90+
plugins \
91+
scripts/build_cpack_deb_packages.sh \
92+
scripts/generate-debian-directory.sh \
93+
src \
94+
third_party \
95+
tools \
96+
util
97+
98+
cmake -S . -B build-deb \
99+
-DCMAKE_BUILD_TYPE=Release \
100+
-DYDB_SDK_INSTALL=ON \
101+
-DYDB_SDK_EXAMPLES=OFF \
102+
-DYDB_SDK_TESTS=OFF \
103+
-DYDB_SDK_ENABLE_OTEL_METRICS=ON \
104+
-DYDB_SDK_ENABLE_OTEL_TRACE=ON \
105+
-DBUILD_SHARED_LIBS=OFF \
106+
-DYDB_SDK_USE_SYSTEM_GOOGLEAPIS=ON \
107+
-DCMAKE_INSTALL_PREFIX=/usr/share/yandex \
108+
-DCMAKE_PREFIX_PATH="/usr/share/yandex" \
109+
"${CMAKE_COMPILER_LAUNCHER_ARGS[@]}"
110+
cmake --build build-deb --target package -j"$(nproc)"
111+
112+
cp -f build_googleapis_deb/*.deb "$OUTPUT_DIR"/
113+
if [ "$(realpath build-deb)" != "$OUTPUT_DIR" ]; then
114+
cp -f build-deb/*.deb "$OUTPUT_DIR"/
115+
fi
116+
117+
if command -v ccache >/dev/null 2>&1; then
118+
ccache --show-stats || true
119+
fi
120+
121+
chmod -R a+rwX "$CCACHE_DIR" build_googleapis_deb build-deb "$OUTPUT_DIR" debian 2>/dev/null || true
122+
ls -la "$OUTPUT_DIR"

0 commit comments

Comments
 (0)