Skip to content

Commit 0e3f838

Browse files
author
Alexander Rogalskiy
committed
Updates on files
1 parent a74ea02 commit 0e3f838

File tree

10 files changed

+154
-41
lines changed

10 files changed

+154
-41
lines changed

scripts/diff_json.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Copyright (C) 2022 SensibleMetrics, Inc. (http://sensiblemetrics.io/)
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Usage example: /bin/sh ./scripts/diff_json.sh <file1> <file2>
17+
18+
set -o errexit
19+
set -o nounset
20+
set -o pipefail
21+
22+
BLUE='\033[1;34m'
23+
GREEN='\033[0;32m'
24+
RED='\033[0;31m'
25+
NC='\033[0m'
26+
BOLD='\033[1m'
27+
28+
if ! command -v jq &> /dev/null
29+
then
30+
echo
31+
echo "#### ERROR ####"
32+
echo "####"
33+
echo "#### Please install the 'jq' tool before being able to use this script"
34+
echo "#### and https://stedolan.github.io/jq/download"
35+
echo "####"
36+
echo "###############"
37+
exit 1
38+
fi
39+
40+
set -e
41+
42+
file1=$(mktemp --suffix=.json)
43+
file2=$(mktemp --suffix=.json)
44+
45+
onError() {
46+
rm "$file1"
47+
rm "$file2"
48+
}
49+
trap 'onError' ERR
50+
51+
jq -S '.' "$1" > "$file1"
52+
jq -S '.' "$2" > "$file2"
53+
diff "$file1" "$file2"

scripts/docker-build.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-build.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
@@ -25,7 +27,10 @@ readonly IMAGE_REPOSITORY="${IMAGE_REPOSITORY:-$DEFAULT_IMAGE_REPOSITORY}"
2527
readonly IMAGE_TAG="${IMAGE_TAG:-$DEFAULT_IMAGE_TAG}"
2628
readonly GIT_SHA=$(git rev-parse HEAD)
2729

28-
cd "$(dirname "$0")/.." || exit 1
30+
## BASE_DIR stores base directory
31+
BASE_DIR=$(dirname "$0")/..
32+
# DOCKER_CMD stores docker command
33+
DOCKER_CMD=${DOCKER_CMD:-$(command -v docker 2> /dev/null || command -v podman 2> /dev/null || type -p docker)}
2934

3035
main() {
3136
echo 'Building docker container...'
@@ -36,10 +41,15 @@ main() {
3641

3742
# docker file path
3843
local file
39-
file="./distribution/docker-images/${tag}.Dockerfile"
44+
file="${BASE_DIR}/distribution/docker-images/${tag}.Dockerfile"
4045

4146
# Build docker image
42-
docker build --rm -f "$file" -t "${IMAGE_REPOSITORY}:${IMAGE_TAG}" -t "${IMAGE_REPOSITORY}:${GIT_SHA}" .
47+
$DOCKER_CMD build \
48+
--rm \
49+
--file "$file" \
50+
--tag "${IMAGE_REPOSITORY}:${IMAGE_TAG}" \
51+
--tag "${IMAGE_REPOSITORY}:${GIT_SHA}" \
52+
"${BASE_DIR}"
4353
}
4454

4555
main "$@"

scripts/docker-compose-logs.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose-logs.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

2022
## setup base directory
21-
BASE_DIR=$(dirname "$0")
23+
BASE_DIR=$(dirname "$0")/..
24+
# DOCKER_COMPOSE_CMD stores docker compose command
25+
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
2226

2327
_exit() {
2428
(($# > 1)) && echo "${@:2}"
@@ -28,13 +32,7 @@ _exit() {
2832
main() {
2933
echo ">>> Logging docker containers..."
3034

31-
## save current working directory
32-
pushd "$BASE_DIR" &> /dev/null || _exit 1 "Unable to save current working directory"
33-
34-
docker-compose -f docker-compose.yml logs -t --follow
35-
36-
## restore previous working directory
37-
popd &> /dev/null || _exit 1 "Unable to restore current working directory"
35+
$DOCKER_COMPOSE_CMD --file "${BASE_DIR}/docker-compose.yml" logs -t --follow
3836
}
3937

4038
main "$@"

scripts/docker-compose-ps.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose-ps.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

20-
cd "$(dirname "$0")/.." || exit 1
22+
## setup base directory
23+
BASE_DIR=$(dirname "$0")/..
24+
# DOCKER_COMPOSE_CMD stores docker compose command
25+
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
2126

2227
main() {
2328
echo ">>> Processing status of docker containers..."
2429

25-
docker-compose -f docker-compose.yml ps
30+
$DOCKER_COMPOSE_CMD --file "${BASE_DIR}/docker-compose.yml" ps
2631
}
2732

2833
main "$@"

scripts/docker-compose-pull.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose-pull.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

20-
cd "$(dirname "$0")/.." || exit 1
22+
## setup base directory
23+
BASE_DIR=$(dirname "$0")/..
24+
# DOCKER_COMPOSE_CMD stores docker compose command
25+
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
2126

2227
main() {
2328
echo ">>> Pulling docker containers..."
2429

25-
docker-compose -f docker-compose.yml pull --include-deps --quiet
30+
$DOCKER_COMPOSE_CMD --file "${BASE_DIR}/docker-compose.yml" pull --include-deps --quiet
2631
}
2732

2833
main "$@"

scripts/docker-compose-start.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose-start.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

20-
cd "$(dirname "$0")/.." || exit 1
22+
## setup base directory
23+
BASE_DIR=$(dirname "$0")/..
24+
# DOCKER_COMPOSE_CMD stores docker compose command
25+
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
2126

2227
main() {
2328
echo ">>> Starting docker containers..."
2429

25-
docker-compose -f docker-compose.yml up --detach --build --force-recreate --renew-anon-volumes
30+
$DOCKER_COMPOSE_CMD --file "${BASE_DIR}/docker-compose.yml" up --detach --build --force-recreate --renew-anon-volumes
2631
}
2732

2833
main "$@"

scripts/docker-compose-stop.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose-stop.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
1921

20-
cd "$(dirname "$0")/.." || exit 1
22+
## setup base directory
23+
BASE_DIR=$(dirname "$0")/..
24+
# DOCKER_COMPOSE_CMD stores docker compose command
25+
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
2126

2227
main() {
2328
echo ">>> Stopping docker containers..."
2429

25-
docker-compose -f docker-compose.yml down --remove-orphans --volumes
30+
$DOCKER_COMPOSE_CMD --file "${BASE_DIR}/docker-compose.yml" down --remove-orphans --volumes
2631
}
2732

2833
main "$@"

scripts/docker-compose.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-compose.sh
17+
1618
# Case-insensitive globbing (used in pathname expansion)
1719
shopt -s nocaseglob
1820
# Append to the Bash history file, rather than overwriting it
@@ -34,7 +36,7 @@ set -o nounset
3436
set -o pipefail
3537

3638
## BASE_DIR stores base directory
37-
BASE_DIR=$(dirname "$0")
39+
BASE_DIR=$(dirname "$0")/..
3840
# DOCKER_COMPOSE_CMD stores docker compose command
3941
DOCKER_COMPOSE_CMD=${DOCKER_COMPOSE_CMD:-$(command -v docker-compose || command -v docker compose)}
4042

@@ -83,31 +85,41 @@ trap cleanup_err ERR
8385
docker_ps() {
8486
echo ">>> Processing status of docker containers..."
8587

86-
$DOCKER_COMPOSE_CMD -f $(BASE_DIR)/docker-compose.yml ps "$@"
88+
$DOCKER_COMPOSE_CMD \
89+
--file "${BASE_DIR}/docker-compose.yml" \
90+
ps "$@"
8791
}
8892

8993
docker_logs() {
9094
echo ">>> Logging docker containers..."
9195

92-
$DOCKER_COMPOSE_CMD -f $(BASE_DIR)/docker-compose.yml logs -t --follow "$@"
96+
$DOCKER_COMPOSE_CMD \
97+
--file "${BASE_DIR}/docker-compose.yml" \
98+
logs -t --follow "$@"
9399
}
94100

95101
docker_pull() {
96102
echo ">>> Pulling docker containers..."
97103

98-
$DOCKER_COMPOSE_CMD -f $(BASE_DIR)/docker-compose.yml pull --include-deps --quiet "$@"
104+
$DOCKER_COMPOSE_CMD \
105+
--file "${BASE_DIR}/docker-compose.yml" \
106+
pull --include-deps --quiet "$@"
99107
}
100108

101109
docker_start() {
102110
echo ">>> Starting docker containers..."
103111

104-
$DOCKER_COMPOSE_CMD -f $(BASE_DIR)/docker-compose.yml up --detach --build --force-recreate --renew-anon-volumes "$@"
112+
$DOCKER_COMPOSE_CMD \
113+
--file "${BASE_DIR}/docker-compose.yml" \
114+
up --detach --build --force-recreate --renew-anon-volumes "$@"
105115
}
106116

107117
docker_stop() {
108118
echo ">>> Stopping docker containers..."
109119

110-
$DOCKER_COMPOSE_CMD -f $(BASE_DIR)/docker-compose.yml down --remove-orphans --volumes "$@"
120+
$DOCKER_COMPOSE_CMD \
121+
--file "${BASE_DIR}/docker-compose.yml" \
122+
down --remove-orphans --volumes "$@"
111123
}
112124

113125
main() {

scripts/docker-rebuild.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Usage example: /bin/sh ./scripts/docker-rebuild.sh
17+
1618
set -o errexit
1719
set -o nounset
1820
set -o pipefail
@@ -25,21 +27,30 @@ readonly IMAGE_REPOSITORY="${IMAGE_REPOSITORY:-$DEFAULT_IMAGE_REPOSITORY}"
2527
readonly IMAGE_TAG="${IMAGE_TAG:-$DEFAULT_IMAGE_TAG}"
2628
readonly GIT_SHA=$(git rev-parse HEAD)
2729

28-
cd "$(dirname "$0")/.." || exit 1
30+
## setup base directory
31+
BASE_DIR=$(dirname "$0")/..
32+
# DOCKER_CMD stores docker command
33+
DOCKER_CMD=${DOCKER_CMD:-$(command -v docker 2> /dev/null || command -v podman 2> /dev/null || type -p docker)}
2934

3035
main() {
31-
echo 'Building docker container...'
36+
echo ">>> Rebuilding docker container..."
3237

3338
# docker file tag
3439
local tag
3540
tag="$1"
3641

3742
# docker file path
3843
local file
39-
file="./distribution/docker-images/${tag}.Dockerfile"
44+
file="${BASE_DIR}/distribution/docker-images/${tag}.Dockerfile"
4045

4146
# Build docker image
42-
docker build --rm -f "$file" -t "${IMAGE_REPOSITORY}:${IMAGE_TAG}" -t "${IMAGE_REPOSITORY}:${GIT_SHA}" docker-build.sh --no-cache=true .
47+
$DOCKER_CMD build \
48+
--rm \
49+
--file "$file" \
50+
--tag "${IMAGE_REPOSITORY}:${IMAGE_TAG}" \
51+
--tag "${IMAGE_REPOSITORY}:${GIT_SHA}" \
52+
--no-cache=true \
53+
"${BASE_DIR}"
4354
}
4455

4556
main "$@"

0 commit comments

Comments
 (0)