Skip to content

Commit efd37de

Browse files
authored
Merge pull request #599 from influxdata/BNP_race_checks
feat: implement race and static-binary checks
2 parents f4f62f9 + 3928099 commit efd37de

File tree

2 files changed

+94
-3
lines changed

2 files changed

+94
-3
lines changed

.circleci/config.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ master_filter: &master_filter
99
only:
1010
- master
1111

12+
ubuntu_machine: &ubuntu_machine
13+
machine:
14+
image: ubuntu-2004:202111-02
15+
docker_layer_caching: true
16+
1217
workflows:
1318
version: 2
1419
ci:
@@ -20,6 +25,12 @@ workflows:
2025
version: ["2.0", "2.1", "2.2", "2.3"]
2126
- publish_docker_images:
2227
<<: *master_filter
28+
- test-influxdb-binaries:
29+
matrix:
30+
parameters:
31+
product:
32+
- "influxdb/1.9/data"
33+
- "influxdb/1.9/meta"
2334

2435
jobs:
2536
build:
@@ -31,15 +42,16 @@ jobs:
3142
- run: bash circle-test.sh
3243

3344
test-influxdb:
34-
machine:
35-
image: ubuntu-2004:202111-01
45+
<<: *ubuntu_machine
3646
parameters:
3747
version:
3848
type: string
3949
enum: ["2.0", "2.1", "2.2", "2.3"]
4050
steps:
4151
- checkout
42-
- run: sudo apt-get update && sudo apt-get install -y jq
52+
- run: |
53+
sudo apt-get update &&
54+
sudo apt-get install -y jq
4355
- run: bash influxdb/test/test-2x-e2e.sh << parameters.version >>
4456
- store_artifacts:
4557
path: influxdb/test/logs
@@ -74,3 +86,14 @@ jobs:
7486
name: Do Enterprise Release
7587
command: |
7688
.circleci/scripts/do-enterprise-release
89+
90+
test-influxdb-binaries:
91+
<<: *ubuntu_machine
92+
parameters:
93+
product:
94+
type: string
95+
steps:
96+
- checkout
97+
- run:
98+
name: Validate Docker Image Binaries
99+
command: influxdb/test/test-binaries << parameters.product >>

influxdb/test/test-binaries

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
set -o errexit \
3+
-o nounset \
4+
-o pipefail
5+
6+
function build_local_image()
7+
{
8+
# ${1} -> directory
9+
# ${2} -> tag
10+
pushd "${1}"
11+
12+
docker build -t "${2}" .
13+
14+
popd
15+
}
16+
17+
# ${1} -> product
18+
build_local_image "${1}" "influxdb-test"
19+
20+
read -d '' -r PROGRAM <<'EOF' || true
21+
set -o errexit \
22+
-o nounset \
23+
-o pipefail \
24+
-o xtrace
25+
26+
export DEBIAN_FRONTEND=noninteractive
27+
apt-get update
28+
apt-get install --yes binutils
29+
30+
function test_race()
31+
{
32+
# ${1} -> target
33+
if grep --quiet 'WARNING\: DATA RACE' <<<"$(strings "${1}")"
34+
then
35+
printf 'Race-enabled binary detected: %s\n' "${1}" >&2 ; exit 1
36+
fi
37+
}
38+
39+
function test_static()
40+
{
41+
# ${1} -> target
42+
43+
# `ldd` has the disadavantage that it cannot differentiate between a binary
44+
# without a dynamic section and garbage. `file` requires somewhat brittle
45+
# string parsing. `readelf` + `grep` circumvents both of these problems.
46+
if ! readelf --dynamic "${1}" | \
47+
grep --silent 'There is no dynamic section in this file.'
48+
then
49+
printf 'Non-static binary detected: %s\n' "${1}" >&2 ; exit 1
50+
fi
51+
}
52+
53+
for target in \
54+
/usr/bin/influx \
55+
/usr/bin/influx_inspect \
56+
/usr/bin/influxd \
57+
/usr/bin/influxd-ctl \
58+
/usr/bin/influxd-meta
59+
do
60+
if [[ -x "${target}" ]]
61+
then
62+
test_race "${target}"
63+
test_static "${target}"
64+
fi
65+
done
66+
EOF
67+
68+
docker run -it "influxdb-test" bash -c "${PROGRAM}"

0 commit comments

Comments
 (0)