11#! /usr/bin/env bash
2- #
3- # Builds the Docker image for the YDB Java SDK SLO workload.
4- #
5- # The script assembles a temporary build context containing two checkouts
6- # side by side — the SDK source tree and the ydb-java-examples checkout —
7- # and feeds that context to `docker build` using the Dockerfile shipped
8- # inside `ydb-java-examples/slo-workload/query/`.
9- #
10- # The Dockerfile takes care of building the SDK from source, installing it
11- # into an in-image local Maven repository, and then building the workload
12- # against that exact SDK version. So the script does not need any Maven /
13- # JDK setup on the host; only `docker` and standard POSIX tools.
14- #
15- # If the initial build fails and `--fallback-image` is provided, the script
16- # tags the fallback image as `--tag` and exits successfully. This mirrors
17- # the behaviour of the equivalent script in `ydb-go-sdk` and is used by the
18- # baseline build, where we want to keep going even if the historical commit
19- # can't be built any more.
202
213set -euo pipefail
224
@@ -26,20 +8,19 @@ Usage:
268 build-slo-image.sh \
279 --sdk <path> \
2810 --examples <path> \
11+ --workload <query|jdbc|spring-data-jdbc|spring-data-jpa> \
2912 --tag <docker-tag> \
13+ [--jdbc <path>] \
3014 [--fallback-image <docker-tag>]
3115
3216Options:
3317 --sdk Path to the ydb-java-sdk checkout to build against.
34- --examples Path to the ydb-java-examples checkout that owns the
35- SLO workload sources (must contain
36- slo-workload/query/Dockerfile).
37- --tag Docker tag to assign to the built image
38- (e.g. ydb-app-current).
18+ --examples Path to the ydb-java-examples checkout.
19+ --workload SLO workload module to build.
20+ --tag Docker tag to assign to the built image.
21+ --jdbc Path to ydb-jdbc-driver (required for JDBC workloads).
3922 --fallback-image If the initial Docker build fails, tag this image as
40- --tag and exit successfully. Useful for the baseline
41- build, which may be unable to compile a historical
42- SDK commit.
23+ --tag and exit successfully.
4324EOF
4425}
4526
@@ -50,7 +31,9 @@ die() {
5031
5132sdk_dir=" "
5233examples_dir=" "
34+ workload=" "
5335tag=" "
36+ jdbc_dir=" "
5437fallback_image=" "
5538
5639while [[ $# -gt 0 ]]; do
@@ -63,10 +46,18 @@ while [[ $# -gt 0 ]]; do
6346 examples_dir=" ${2:- } "
6447 shift 2
6548 ;;
49+ --workload)
50+ workload=" ${2:- } "
51+ shift 2
52+ ;;
6653 --tag)
6754 tag=" ${2:- } "
6855 shift 2
6956 ;;
57+ --jdbc)
58+ jdbc_dir=" ${2:- } "
59+ shift 2
60+ ;;
7061 --fallback-image)
7162 fallback_image=" ${2:- } "
7263 shift 2
@@ -81,40 +72,54 @@ while [[ $# -gt 0 ]]; do
8172 esac
8273done
8374
84- if [[ -z " $sdk_dir " || -z " $examples_dir " || -z " $tag " ]]; then
75+ if [[ -z " $sdk_dir " || -z " $examples_dir " || -z " $workload " || -z " $ tag" ]]; then
8576 usage
8677 die " Incomplete argument set"
8778fi
8879
80+ case " $workload " in
81+ query|jdbc|spring-data-jdbc|spring-data-jpa)
82+ ;;
83+ * )
84+ die " Unsupported workload: $workload "
85+ ;;
86+ esac
87+
88+ if [[ " $workload " != " query" && -z " $jdbc_dir " ]]; then
89+ die " --jdbc is required for workload ${workload} "
90+ fi
91+
8992[[ -d " $sdk_dir " ]] || die " --sdk does not exist: $sdk_dir "
9093[[ -d " $examples_dir " ]] || die " --examples does not exist: $examples_dir "
94+ if [[ -n " $jdbc_dir " ]]; then
95+ [[ -d " $jdbc_dir " ]] || die " --jdbc does not exist: $jdbc_dir "
96+ fi
9197
9298sdk_dir=" $( cd " $sdk_dir " && pwd) "
9399examples_dir=" $( cd " $examples_dir " && pwd) "
100+ if [[ -n " $jdbc_dir " ]]; then
101+ jdbc_dir=" $( cd " $jdbc_dir " && pwd) "
102+ fi
94103
95- dockerfile=" ${examples_dir} /slo-workload/query /Dockerfile"
104+ dockerfile=" ${examples_dir} /slo-workload/${workload} /Dockerfile"
96105[[ -f " $dockerfile " ]] || die " Dockerfile not found: $dockerfile "
97106
98- # Assemble a build context that contains the two checkouts side by side.
99- # We use hard links where possible to avoid copying large amounts of data;
100- # `cp -al` falls back to a regular copy when hard links aren't supported
101- # (e.g. across filesystems on the GitHub runner cache).
102107context_dir=" $( mktemp -d) "
103108trap ' rm -rf "$context_dir"' EXIT
104109
105110echo " Assembling build context in $context_dir "
106111echo " ydb-java-sdk: $sdk_dir "
107112echo " ydb-java-examples: $examples_dir "
113+ echo " workload: $workload "
108114echo " tag: $tag "
115+ if [[ -n " $jdbc_dir " ]]; then
116+ echo " ydb-jdbc-driver: $jdbc_dir "
117+ fi
109118
110119copy_tree () {
111120 local src=" $1 "
112121 local dst=" $2 "
113122 mkdir -p " $dst "
114- # The "/." suffix on src and "/" on dst asks cp to copy CONTENTS of src
115- # into dst, regardless of whether dst pre-existed. Without this, partial
116- # hardlink failures can leave dst partially populated and the fallback
117- # then nests src inside dst (dst/src/...) instead of overwriting.
118123 if cp -al " $src " /. " $dst " / 2> /dev/null; then
119124 return 0
120125 fi
@@ -123,23 +128,27 @@ copy_tree() {
123128
124129copy_tree " $sdk_dir " " $context_dir /ydb-java-sdk"
125130copy_tree " $examples_dir " " $context_dir /ydb-java-examples"
131+ if [[ -n " $jdbc_dir " ]]; then
132+ copy_tree " $jdbc_dir " " $context_dir /ydb-jdbc-driver"
133+ else
134+ mkdir -p " $context_dir /ydb-jdbc-driver"
135+ fi
126136
127- # Drop .git from each copied tree so it doesn't ship into image layers or
128- # confuse Maven plugins that probe for git metadata.
129- rm -rf " $context_dir /ydb-java-sdk/.git " " $context_dir /ydb-java-examples /.git"
137+ rm -rf " $context_dir /ydb-java-sdk/ .git" \
138+ " $context_dir /ydb-java-examples/. git" \
139+ " $context_dir /ydb-jdbc-driver /.git"
130140
131- # Fail fast with a clear message if the layout is wrong (e.g. because of a
132- # silent copy failure on the runner).
133141for required in \
134142 " $context_dir /ydb-java-sdk/pom.xml" \
135- " $context_dir /ydb-java-examples/slo-workload/query /Dockerfile"
143+ " $context_dir /ydb-java-examples/slo-workload/${workload} /Dockerfile"
136144do
137145 [[ -f " $required " ]] || die " Build context missing required file: $required "
138146done
139147
140- echo " Build context layout:"
141- ls -la " $context_dir "
142- echo " ydb-java-sdk: $( ls -1 " $context_dir /ydb-java-sdk" | wc -l) entries"
148+ if [[ " $workload " != " query" ]]; then
149+ [[ -f " $context_dir /ydb-jdbc-driver/pom.xml" ]] \
150+ || die " Build context missing required file: $context_dir /ydb-jdbc-driver/pom.xml"
151+ fi
143152
144153set +e
145154docker build \
0 commit comments