Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit 6359a20

Browse files
authored
feat: implement quickstart example (#1318)
Refactor the existing test to verify the installed version of the libraries was usable with an example (which also tests the same thing). This example can be a good starting point for application developers that want to create Bazel or CMake projects using google-cloud-cpp-spanner. Most of the changes are in the CI scripts to actually compile this new example.
1 parent 53e5257 commit 6359a20

23 files changed

+225
-273
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ci/
22
cmake-out/
33
cmake-build-*/
4+
quickstart/

ci/etc/kokoro/install/project-config.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
7979
8080
# Verify that the installed files are actually usable
8181
WORKDIR /home/build/test-install-cmake
82-
COPY ci/test-install /home/build/test-install-cmake
83-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
82+
COPY quickstart /home/build/test-install-cmake
8483
# Disable pkg-config with CMake to verify it is not used in package discovery.
8584
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
8685
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/etc/kokoro/install/run-installed-programs.sh

100644100755
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,47 @@
1717
CONFIG_DIRECTORY="${KOKORO_GFILE_DIR:-/dev/shm}"
1818
readonly CONFIG_DIRECTORY
1919
if [[ -f "${CONFIG_DIRECTORY}/spanner-integration-tests-config.sh" ]]; then
20+
echo "================================================================"
21+
echo "Testing a program built with spanner-as-a-dependency $(date)"
22+
echo "================================================================"
2023
source "${CONFIG_DIRECTORY}/spanner-integration-tests-config.sh"
2124

25+
gcloud auth activate-service-account --key-file \
26+
"${CONFIG_DIRECTORY}/spanner-credentials.json"
27+
28+
# Pick one of the instances at random
29+
mapfile -t INSTANCES < <(gcloud "--project=${GOOGLE_CLOUD_PROJECT}" \
30+
spanner instances list --filter=NAME:test-instance --format='csv(name)[no-heading]')
31+
readonly INSTANCES
32+
GOOGLE_CLOUD_CPP_SPANNER_INSTANCE="${INSTANCES[$(( RANDOM % ${#INSTANCES} ))]}"
33+
export GOOGLE_CLOUD_CPP_SPANNER_INSTANCE
34+
readonly GOOGLE_CLOUD_CPP_SPANNER_INSTANCE
35+
echo "Searching for quickstart-db database in ${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}"
36+
if gcloud "--project=${GOOGLE_CLOUD_PROJECT}" \
37+
spanner databases list "--instance=${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}" | grep -q quickstart-db; then
38+
echo "Quickstart database (quickstart-db) already exists in ${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}"
39+
else
40+
echo "Creating quickstart-db database in ${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}"
41+
# Ignore errors because it could be that another builds creates it
42+
# simultaneously.
43+
gcloud "--project=${GOOGLE_CLOUD_PROJECT}" \
44+
spanner databases create "--instance=${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}" quickstart-db || true
45+
fi
46+
2247
run_args=(
2348
# Remove the container after running
2449
"--rm"
2550

2651
# Set the environment variables for the test program.
2752
"--env" "GOOGLE_APPLICATION_CREDENTIALS=/c/spanner-credentials.json"
2853
"--env" "GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}"
29-
"--env" "RUN_SLOW_INTEGRATION_TESTS=${RUN_SLOW_INTEGRATION_TESTS:-no}"
30-
"--env" "GOOGLE_CLOUD_CPP_SPANNER_INSTANCE=${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}"
31-
"--env" "GOOGLE_CLOUD_CPP_SPANNER_IAM_TEST_SA=${GOOGLE_CLOUD_CPP_SPANNER_IAM_TEST_SA}"
3254

3355
# Mount the config directory as a volume in `/c`
3456
"--volume" "${CONFIG_DIRECTORY}:/c"
3557
)
3658
echo "================================================================"
3759
echo "Run test program against installed libraries ${DISTRO}."
38-
docker run "${run_args[@]}" "${INSTALL_RUN_IMAGE}" "/i/spanner_install_test"
60+
docker run "${run_args[@]}" "${INSTALL_RUN_IMAGE}" "/i/quickstart" \
61+
"${GOOGLE_CLOUD_PROJECT}" "${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}" quickstart-db
3962
echo "================================================================"
4063
fi

ci/kokoro/docker/build-in-docker-bazel-dependency.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ if [[ -n "${BAZEL_CONFIG}" ]]; then
5252
bazel_args+=(--config "${BAZEL_CONFIG}")
5353
fi
5454

55-
cp -r ci/test-install /var/tmp/test-install
56-
cp google/cloud/spanner/integration_tests/spanner_install_test.cc /var/tmp/test-install
57-
cd /var/tmp/test-install
55+
cd quickstart
5856

5957
echo "================================================================"
6058
echo "Fetching dependencies $(date)"
@@ -68,22 +66,20 @@ echo "================================================================"
6866
"${BAZEL_BIN}" build "${bazel_args[@]}" \
6967
-- //...:all
7068

71-
if [[ -r "/c/spanner-integration-tests-config.sh" ]]; then
69+
# shellcheck disable=SC1091
70+
if [[ -f "/c/spanner-integration-tests-config.sh" ]]; then
7271
echo "================================================================"
73-
echo "Running the dependent program $(date)"
72+
echo "Testing a program built with spanner-as-a-dependency $(date)"
7473
echo "================================================================"
75-
# shellcheck disable=SC1091
7674
source "/c/spanner-integration-tests-config.sh"
7775

78-
# Run the integration tests using Bazel to drive them.
76+
# Run the program using the command-line parameters.
7977
env "GOOGLE_APPLICATION_CREDENTIALS=/c/spanner-credentials.json" \
80-
"GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}" \
81-
"GOOGLE_CLOUD_CPP_SPANNER_INSTANCE=${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}" \
82-
"GOOGLE_CLOUD_CPP_SPANNER_IAM_TEST_SA=${GOOGLE_CLOUD_CPP_SPANNER_IAM_TEST_SA}" \
83-
"${BAZEL_BIN}" run \
78+
"${BAZEL_BIN}" run \
8479
"${bazel_args[@]}" \
8580
"--spawn_strategy=local" \
86-
-- //...:all
81+
:quickstart -- "${GOOGLE_CLOUD_PROJECT}" "${GOOGLE_CLOUD_CPP_SPANNER_INSTANCE}" quickstart-db
82+
8783
fi
8884

8985
echo "================================================================"

ci/kokoro/install/Dockerfile.centos-7

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
152152

153153
# Verify that the installed files are actually usable
154154
WORKDIR /home/build/test-install-cmake
155-
COPY ci/test-install /home/build/test-install-cmake
156-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
155+
COPY quickstart /home/build/test-install-cmake
157156
# Disable pkg-config with CMake to verify it is not used in package discovery.
158157
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
159158
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/kokoro/install/Dockerfile.centos-8

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
131131

132132
# Verify that the installed files are actually usable
133133
WORKDIR /home/build/test-install-cmake
134-
COPY ci/test-install /home/build/test-install-cmake
135-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
134+
COPY quickstart /home/build/test-install-cmake
136135
# Disable pkg-config with CMake to verify it is not used in package discovery.
137136
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
138137
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/kokoro/install/Dockerfile.debian-buster

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
9292

9393
# Verify that the installed files are actually usable
9494
WORKDIR /home/build/test-install-cmake
95-
COPY ci/test-install /home/build/test-install-cmake
96-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
95+
COPY quickstart /home/build/test-install-cmake
9796
# Disable pkg-config with CMake to verify it is not used in package discovery.
9897
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
9998
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/kokoro/install/Dockerfile.debian-stretch

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
126126

127127
# Verify that the installed files are actually usable
128128
WORKDIR /home/build/test-install-cmake
129-
COPY ci/test-install /home/build/test-install-cmake
130-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
129+
COPY quickstart /home/build/test-install-cmake
131130
# Disable pkg-config with CMake to verify it is not used in package discovery.
132131
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
133132
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/kokoro/install/Dockerfile.fedora

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
100100

101101
# Verify that the installed files are actually usable
102102
WORKDIR /home/build/test-install-cmake
103-
COPY ci/test-install /home/build/test-install-cmake
104-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
103+
COPY quickstart /home/build/test-install-cmake
105104
# Disable pkg-config with CMake to verify it is not used in package discovery.
106105
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
107106
RUN cmake --build /i -- -j "${NCPU:-4}"

ci/kokoro/install/Dockerfile.opensuse-leap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
147147

148148
# Verify that the installed files are actually usable
149149
WORKDIR /home/build/test-install-cmake
150-
COPY ci/test-install /home/build/test-install-cmake
151-
COPY google/cloud/spanner/integration_tests/spanner_install_test.cc /home/build/test-install-cmake
150+
COPY quickstart /home/build/test-install-cmake
152151
# Disable pkg-config with CMake to verify it is not used in package discovery.
153152
RUN env -u PKG_CONFIG_PATH cmake -H. -B/i
154153
RUN cmake --build /i -- -j "${NCPU:-4}"

0 commit comments

Comments
 (0)