Skip to content

Commit f70f7f4

Browse files
committed
Harden Docker scripts
Signed-off-by: dhoard <doug.hoard@gmail.com>
1 parent 19e38cf commit f70f7f4

10 files changed

+123
-26
lines changed
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) The Prometheus jmx_exporter Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
PWD="$PWD"
420
function exit_trap() {
5-
cd "${PWD}"
21+
cd "${PWD}" || exit
622
echo $?
723
}
824
trap exit_trap EXIT
@@ -13,12 +29,12 @@ function check_exit_code() {
1329
if [ "$?" != "0" ];
1430
then
1531
echo "Failed to pull Docker image ${1}";
16-
exit $?
32+
exit 1
1733
fi
1834
}
1935

20-
grep -v '^#' integration_tests/src/test/resources/java-docker-images.txt | while read -r LINE;
36+
while read -r LINE;
2137
do
2238
docker pull "${LINE}"
2339
check_exit_code "${LINE}"
24-
done
40+
done < <(grep -v '^#' integration_tests/src/test/resources/java-docker-images.txt)
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) The Prometheus jmx_exporter Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
PWD="$PWD"
420
function exit_trap() {
5-
cd "${PWD}"
21+
cd "${PWD}" || exit
622
echo $?
723
}
824
trap exit_trap EXIT
925
SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10-
cd "${SCRIPT_DIRECTORY}"
26+
cd "${SCRIPT_DIRECTORY}" || exit
1127

1228
function check_exit_code() {
1329
if [ "$?" != "0" ];
1430
then
1531
echo "Failed to pull Docker image ${1}";
16-
exit $?
32+
exit 1
1733
fi
1834
}
1935

20-
grep -v '^#' integration_tests/src/test/resources/prometheus-docker-images.txt | while read -r LINE;
36+
while read -r LINE;
2137
do
2238
docker pull "${LINE}"
2339
check_exit_code "${LINE}"
24-
done
40+
done < <(grep -v '^#' integration_tests/src/test/resources/prometheus-docker-images.txt)
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) The Prometheus jmx_exporter Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
PWD="$PWD"
420
function exit_trap() {
5-
cd "${PWD}"
21+
cd "${PWD}" || exit
622
echo $?
723
}
824
trap exit_trap EXIT
925
SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10-
cd "${SCRIPT_DIRECTORY}"
26+
cd "${SCRIPT_DIRECTORY}" || exit
1127

1228
function check_exit_code() {
1329
if [ "$?" != "0" ];
1430
then
15-
echo "Failed to pull Docker image ${1}";
16-
exit $?
31+
echo "Failed to execute ${1}";
32+
exit 1
1733
fi
1834
}
1935

2036
./pull-smoke-test-java-docker-images.sh
21-
./pull-smoke-test-prometheus-docker-images.sh
37+
check_exit_code "./pull-smoke-test-java-docker-images.sh"
38+
39+
./pull-smoke-test-prometheus-docker-images.sh
40+
check_exit_code "./pull-smoke-test-prometheus-docker-images.sh"
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) The Prometheus jmx_exporter Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
PWD="$PWD"
420
function exit_trap() {
5-
cd "${PWD}"
21+
cd "${PWD}" || exit
622
echo $?
723
}
824
trap exit_trap EXIT
925
SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10-
cd "${SCRIPT_DIRECTORY}"
26+
cd "${SCRIPT_DIRECTORY}" || exit
1127

1228
function check_exit_code() {
1329
if [ "$?" != "0" ];
1430
then
1531
echo "Failed to pull Docker image ${1}";
16-
exit $?
32+
exit 1
1733
fi
1834
}
1935

20-
grep -v '^#' integration_tests/src/test/resources/smoke-test-java-docker-images.txt | while read -r LINE;
36+
while read -r LINE;
2137
do
2238
docker pull "${LINE}"
2339
check_exit_code "${LINE}"
24-
done
40+
done < <(grep -v '^#' integration_tests/src/test/resources/smoke-test-java-docker-images.txt)

integration_test_suite/pull-smoke-test-prometheus-docker-images.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) The Prometheus jmx_exporter Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
PWD="$PWD"
420
function exit_trap() {
5-
cd "${PWD}"
21+
cd "${PWD}" || exit
622
echo $?
723
}
824
trap exit_trap EXIT
925
SCRIPT_DIRECTORY=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10-
cd "${SCRIPT_DIRECTORY}"
26+
cd "${SCRIPT_DIRECTORY}" || exit
1127

1228
function check_exit_code() {
1329
if [ "$?" != "0" ];
1430
then
1531
echo "Failed to pull Docker image ${1}";
16-
exit $?
32+
exit 1
1733
fi
1834
}
1935

run-quick-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# Bash script to build, package, and run a quick test
2121
#
2222

23+
set -e
24+
set -o pipefail
25+
2326
(
2427
export JAVA_DOCKER_IMAGES="amazoncorretto:25"
2528
export PROMETHEUS_DOCKER_IMAGES="prom/prometheus:v3.9.1"

run-regression-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# Bash script to build, package, and run the regression tests (all Docker containers)
2121
#
2222

23+
set -e
24+
set -o pipefail
25+
2326
(
2427
export JAVA_DOCKER_IMAGES=all
2528
export PROMETHEUS_DOCKER_IMAGES=all

run-smoke-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# Bash script to build, package, and run the smoke tests (smoke test Docker containers)
2121
#
2222

23+
set -e
24+
set -o pipefail
25+
2326
(
2427
unset JAVA_DOCKER_IMAGES
2528
unset PROMETHEUS_DOCKER_IMAGES

run-stress-test.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@
2121
# test suite continuously until there is a failure
2222
#
2323

24+
set -o pipefail
25+
2426
(
27+
export JAVA_DOCKER_IMAGES=all
28+
export PROMETHEUS_DOCKER_IMAGES=all
29+
2530
while true;
2631
do
2732
DATE=$(date)
2833
echo "STRESS-TEST-START ${DATE}"
2934

30-
export JAVA_DOCKER_IMAGES=all
31-
export PROMETHEUS_DOCKER_IMAGES=all
32-
3335
./mvnw clean verify
3436
if [[ "$?" -ne 0 ]];
3537
then
3638
DATE=$(date)
3739
echo "STRESS-TEST-FAILED ${DATE}"
38-
break
40+
exit 1
3941
fi
4042

4143
DATE=$(date)

run-targeted-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ if [[ "$#" -ne 2 ]]; then
2525
exit 1
2626
fi
2727

28+
set -e
29+
set -o pipefail
30+
2831
(
2932
export JAVA_DOCKER_IMAGES="$1"
3033
export PROMETHEUS_DOCKER_IMAGES="$2"

0 commit comments

Comments
 (0)