Skip to content

Commit 866038c

Browse files
author
Maurice Faber
committed
fix: console docker compose [ci skip]
1 parent 98f3048 commit 866038c

File tree

9 files changed

+70
-62
lines changed

9 files changed

+70
-62
lines changed

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
FROM node:14-slim as ci
22

3+
ARG SKIP_TESTS='false'
4+
ENV EXIT_FAST='true'
5+
36
ENV APP_HOME=/home/app/stack
47
RUN mkdir -p $APP_HOME
58
WORKDIR $APP_HOME
69

710
COPY package*.json ./
811
COPY . .
9-
RUN npm install
12+
RUN [ "$SKIP_TESTS" = 'false' ] && npm install || true
1013
COPY ./.cspell.json .
11-
RUN npm run spellcheck
14+
RUN [ "$SKIP_TESTS" = 'false' ] && npm run spellcheck || true
1215

1316
FROM otomi/tools:1.4.7 as test
1417
ENV APP_HOME=/home/app/stack
@@ -18,8 +21,8 @@ WORKDIR $APP_HOME
1821
COPY . .
1922
RUN cp -r .demo/ env/
2023

21-
RUN bin/validate-values.sh
22-
RUN EXIT_FAST=1 bin/validate-templates.sh
24+
RUN [ "$SKIP_TESTS" = 'false' ] && bin/validate-values.sh || true
25+
RUN [ "$SKIP_TESTS" = 'false' ] && bin/validate-templates.sh || true
2326

2427
#-----------------------------
2528
FROM otomi/tools:1.4.8 as prod

bin/bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mkdir -p $bin_path &>/dev/null
2929

3030
# The very first time we use latest image
3131
img='otomi/core:latest'
32-
[[ "$has_otomi" == "true" ]] && img="otomi/core:$(otomi_image_tag)"
32+
[ "$has_otomi" = 'true' ] && img="otomi/core:$(otomi_image_tag)"
3333
echo "Installing artifacts from $img"
3434
for f in 'aliases' 'common.sh' 'otomi'; do
3535
cp $PWD/bin/$f $bin_path/

bin/check-console.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ api_settings="$ENV_DIR/env/charts/otomi-api.yaml"
1212
api_secrets="$ENV_DIR/env/charts/secrets.otomi-api.yaml"
1313

1414
# decrypt secrets if needed
15-
[ -f "$ENV_DIR/.sops.yaml" ] && set +e && helm secrets dec $api_secrets $settings_secrets >/dev/null && set -e
15+
if [ -f "$ENV_DIR/.sops.yaml" ]; then
16+
set +e
17+
helm secrets dec $api_secrets >/dev/null
18+
helm secrets dec $settings_secrets >/dev/null
19+
set -e
20+
fi
1621
[ -f "$api_secrets.dec" ] && api_secrets="$api_secrets.dec"
1722
[ -f "$settings_secrets.dec" ] && settings_secrets="$settings_secrets.dec"
1823
pull_secret="$(yq m $settings $settings_secrets | yq r - 'otomi.pullSecret')"
@@ -23,11 +28,11 @@ user=$(yq m $api_secrets $api_settings | yq r - 'charts[otomi-api].git.user')
2328
password=$(yq m $api_secrets $api_settings | yq r - 'charts[otomi-api].git.password')
2429

2530
# all present?
26-
[ "$pull_secret" == "" ] && echo "Error: otomi.pullSecret not set in $ENV_DIR/env/secrets.settings.yaml!" >&2 && err=1
27-
[ "$repo_url" == "" ] || [ "$repo_url" == "github.com/redkubes/otomi-values-demo.git" ] && error="\nrepoUrl: $repo_url "
28-
[ "$email" == "" ] || [ "$email" == "some@secret.value" ] && error="$error\nemail: $email"
29-
[ "$user" == "" ] || [ "$user" == "somesecretvalue" ] && error="$error\nuser: $user"
30-
[ "$password" == "" ] || [ "$password" == "somesecretvalue" ] && error="$error\npassword: $password"
31+
[ "$pull_secret" = "" ] && echo "Error: otomi.pullSecret not set in $ENV_DIR/env/secrets.settings.yaml!" >&2 && err=1
32+
[ "$repo_url" = "" ] || [ "$repo_url" = "github.com/redkubes/otomi-values-demo.git" ] && error="\nrepoUrl: $repo_url "
33+
[ "$email" = "" ] || [ "$email" = "some@secret.value" ] && error="$error\nemail: $email"
34+
[ "$user" = "" ] || [ "$user" = "somesecretvalue" ] && error="$error\nuser: $user"
35+
[ "$password" = "" ] || [ "$password" = "somesecretvalue" ] && error="$error\npassword: $password"
3136
[ "$error" != "" ] && printf "Error: Make sure the git details are correctly added to 'charts/*otomi-api.yaml'. Incorrect values found for git: $error\n" >&2
3237
[ "$err" != "" ] || [ "$error" != "" ] && exit 1
3338

bin/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ hf() {
3333
}
3434

3535
hf_values() {
36-
[ "${VERBOSE-0}" == "0" ] && quiet='--quiet'
36+
[ "${VERBOSE-'true'}" = 'true' ] && quiet='--quiet'
3737
helmfile ${quiet-} -e "$CLOUD-$CLUSTER" -f helmfile.tpl/helmfile-dump.yaml build | grep -Ev $helmfileOutputHide | sed -e $replacePathsPattern |
3838
yq read -P - 'releases[0].values[0]'
3939
}

bin/crypt.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function rotate() {
1414

1515
function crypt() {
1616
cd $ENV_DIR/env >/dev/null
17-
if [ "$command" == "encrypt" ]; then
17+
if [ "$command" = 'encrypt' ]; then
1818
find . -type f -name 'secrets.*.yaml' -exec helm secrets enc {} \;
1919
else
2020
find . -type f -name 'secrets.*.yaml' -exec helm secrets dec {} \;
@@ -23,18 +23,18 @@ function crypt() {
2323
}
2424

2525
case $command in
26-
encrypt | decrypt)
27-
printf "${COLOR_LIGHT_PURPLE}${command}ing secrets...${COLOR_NC}\n"
28-
crypt
29-
printf "${COLOR_LIGHT_PURPLE}DONE!${COLOR_NC}\n"
30-
;;
31-
rotate)
32-
printf "${COLOR_LIGHT_PURPLE}rotating secrets...${COLOR_NC}\n"
33-
rotate
34-
printf "${COLOR_LIGHT_PURPLE}DONE!${COLOR_NC}\n"
35-
;;
36-
*)
37-
echo "Invalid command: $command. Should be one of: decrypt|encrypt|rotate"
38-
exit 1
39-
;;
26+
encrypt | decrypt)
27+
printf "${COLOR_LIGHT_PURPLE}${command}ing secrets...${COLOR_NC}\n"
28+
crypt
29+
printf "${COLOR_LIGHT_PURPLE}DONE!${COLOR_NC}\n"
30+
;;
31+
rotate)
32+
printf "${COLOR_LIGHT_PURPLE}rotating secrets...${COLOR_NC}\n"
33+
rotate
34+
printf "${COLOR_LIGHT_PURPLE}DONE!${COLOR_NC}\n"
35+
;;
36+
*)
37+
echo "Invalid command: $command. Should be one of: decrypt|encrypt|rotate"
38+
exit 1
39+
;;
4040
esac

bin/gen-drone.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readonly receiver=$(echo "$values" | yq r - alerts.receiver)
1313
readonly templatePath=$PWD/tpl/.drone.tpl.$receiver.yml
1414
readonly customer_name=$(customer_name)
1515

16-
if [ "$receiver" == "slack" ]; then
16+
if [ "$receiver" = 'slack' ]; then
1717
key="url"
1818
else
1919
key="lowPrio"
@@ -27,7 +27,7 @@ function template_drone_config() {
2727
printf "${COLOR_LIGHT_PURPLE}Creating $targetPath ${COLOR_NC}\n"
2828

2929
local target=$targetPath
30-
[ "${DRY_RUN-0}" == "1" ] && target="/dev/stdout"
30+
[ "${DRY_RUN-'false'}" = 'false' ] && target="/dev/stdout"
3131

3232
cat $templatePath | sed -e "s/__CLOUD/${CLOUD}/g" -e "s/__CLUSTER/${CLUSTER}/g" \
3333
-e "s/__IMAGE_TAG/${otomi_image_tag}/g" -e "s|__WEBHOOK|${webhook}|g" \

bin/otomi

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
set -e
1515

1616
command=$1
17-
[ "$ENV_DIR" == "" ] && env_unset=1
17+
[ "$ENV_DIR" = "" ] && env_unset=1
1818
ENV_DIR=${ENV_DIR:-$PWD}
19-
[ "$ENV_DIR" == "/home/app/stack" ] && ENV_DIR=$ENV_DIR/env
19+
[ "$ENV_DIR" = "/home/app/stack" ] && ENV_DIR=$ENV_DIR/env
2020

2121
. bin/common.sh
2222

@@ -33,9 +33,9 @@ function verbose_env() {
3333
}
3434

3535
# VERBOSE - export this varibale to run this script in verbose mode
36-
VERBOSE=${VERBOSE:-"0"}
36+
VERBOSE=${VERBOSE:-'true'}
3737
# EXIT_FAST - export this varaibale to exit the script on error
38-
EXIT_FAST=${EXIT_FAST:-"1"}
38+
EXIT_FAST=${EXIT_FAST:-'true'}
3939

4040
# check_kube_context - a flag to indicate to use kube context and to refresh kube access token before running command in docker
4141
check_kube_context=1
@@ -55,10 +55,10 @@ readme_url='https://github.com/redkubes/otomi-core'
5555

5656
function set_env_and_stack_dir() {
5757
local cwd=$(basename "$PWD")
58-
[ "$VERBOSE" == "1" ] && echo "CWD: $cwd"
59-
if [[ "$cwd" == "otomi-core" ]]; then
60-
[ "$env_unset" == "1" ] && echo "Error: The ENV_DIR environment variable is not set" && exit 1
61-
[ "$VERBOSE" == "1" ] && echo "Mounting otomi-core dir"
58+
[ "$VERBOSE" = "1" ] && echo "CWD: $cwd"
59+
if [ "$cwd" = "otomi-core" ]; then
60+
[ "$env_unset" = "1" ] && echo "Error: The ENV_DIR environment variable is not set" >&2 && exit 1
61+
[ "$VERBOSE" = "1" ] && echo "Mounting otomi-core dir"
6262
stack_dir=$PWD
6363
mount_stack_dir=1
6464
fi
@@ -106,16 +106,15 @@ function check_docker_running() {
106106
if [ "$?" = "0" ]; then
107107
has_docker=1
108108
else
109-
echo "Otomi CLI expects a running docker daemon!"
110-
exit 1
109+
echo "Otomi CLI expects a running docker daemon!" >&2 && exit 1
111110
fi
112111
}
113112

114113
function evaluate_k8s_context() {
115114
local env_path="${ENV_DIR}/env/clouds/${CLOUD}/${CLUSTER}/.env"
116-
[ ! -f $env_path ] && echo "Error: The file '${env_path}' does not exist" && exit 1
115+
[ ! -f $env_path ] && echo "Error: The file '${env_path}' does not exist" >&2 && exit 1
117116
source $env_path
118-
[[ -z "$K8S_CONTEXT" ]] && echo "Error: The K8S_CONTEXT env is not defined in $env_path" && exit 1
117+
[[ -z "$K8S_CONTEXT" ]] && echo "Error: The K8S_CONTEXT env is not defined in $env_path" >&2 && exit 1
119118
return 0
120119
}
121120

@@ -144,9 +143,9 @@ evaluate_secrets() {
144143
echo "Info: The 'secrets.*.yaml files' are not decrypted, because $ENV_DIR/.sops.yaml file is not present"
145144
return 0
146145
}
147-
if [ "$CI" == "" ]; then
146+
if [ "$CI" = "" ]; then
148147
local secrets_path="$ENV_DIR/.secrets"
149-
[[ ! -r "$secrets_path" ]] && echo "Error: Unable to find the '$secrets_path' file.\nPlease follow to documentation: $readme_url" && exit 2
148+
[[ ! -r "$secrets_path" ]] && echo "Error: Unable to find the '$secrets_path' file.\nPlease follow to documentation: $readme_url" >&2 && exit 2
150149
source $secrets_path
151150
fi
152151
prepare_crypt
@@ -155,13 +154,15 @@ evaluate_secrets() {
155154

156155
validate_cluster_env() {
157156
evaluate_secrets
158-
[[ -z "$CLOUD" ]] && echo "Error: The CLOUD environment variable is not set" && exit 2
159-
[[ -z "$CLUSTER" ]] && echo "Error: The CLUSTER environment variable is not set" && exit 2
157+
local err
158+
[[ -z "$CLOUD" ]] && echo "Error: The CLOUD environment variable is not set" >&2 && err=1
159+
[[ -z "$CLUSTER" ]] && echo "Error: The CLUSTER environment variable is not set" >&2 && err=1
160+
[[ ! -z "$err" ]] && exit 2
160161
return 0
161162
}
162163

163164
is_repo() {
164-
[[ "$(basename "$PWD")" == "otomi-core" ]] && echo "Error: Should not be ran from otomi-core" && exit 2
165+
[[ "$(basename "$PWD")" = "otomi-core" ]] && echo "Error: Should not be ran from otomi-core" >&2 && exit 2
165166
return 0
166167
}
167168

@@ -188,7 +189,7 @@ function drun() {
188189
local socket_volume=''
189190

190191
if [ "$CI" != "" ]; then
191-
echo "Running in CI: $CI"
192+
[ "$VERBOSE" = "1" ] && echo "Running in CI: $CI"
192193
check_kube_context=0
193194
else
194195
socket_volume="-v /var/run/docker.sock:/var/run/docker.sock"
@@ -205,15 +206,15 @@ function drun() {
205206
stack_volume="-v ${stack_dir}:${stack_dir}"
206207
fi
207208

208-
if [ "$VERBOSE" == "1" ]; then
209+
if [ "$VERBOSE" = "1" ]; then
209210
verbose_env
210211
fi
211212

212213
# use docker run if has_docker AND either:
213214
# - not in docker
214215
# - in docker AND force docker
215-
if [[ ("$CI" == "") && $has_docker -eq 1 && ("$IN_DOCKER" != "1" || $dind -eq 1) ]]; then
216-
[ "$VERBOSE" == "1" ] && echo "Running dockerized version of command: $command"
216+
if [[ ("$CI" = "") && $has_docker -eq 1 && ("$IN_DOCKER" != "1" || $dind -eq 1) ]]; then
217+
[ "$VERBOSE" = "1" ] && echo "Running dockerized version of command: $command"
217218
docker run $docker_terminal_params --rm \
218219
$stack_volume $socket_volume -v /tmp:/tmp \
219220
-v $GOOGLE_APPLICATION_CREDENTIALS:$GOOGLE_APPLICATION_CREDENTIALS \
@@ -237,7 +238,7 @@ function drun() {
237238
$cmd_image \
238239
$command
239240
else
240-
[ "$VERBOSE" == "1" ] && echo "Running native version of command: $command"
241+
[ "$VERBOSE" = "1" ] && echo "Running native version of command: $command"
241242
$command
242243
fi
243244
}
@@ -383,13 +384,12 @@ function execute() {
383384
;;
384385
*)
385386
show_usage
386-
[ "$1" != "" ] && echo "Error: Unknown command: $@"
387-
exit 1
387+
[ "$1" != "" ] && echo "Error: Unknown command: $@" >&2 && exit 1
388388
;;
389389
esac
390390
}
391391

392-
[[ -z "$command" ]] && echo "Error: Missing command argument" && show_usage && exit 2
392+
[[ -z "$command" ]] && echo "Error: Missing command argument" >&2 && show_usage && exit 2
393393

394394
set_env_and_stack_dir
395395
set_otomi_image

bin/validate-templates.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

33
set -uo pipefail
4-
EXIT_FAST=${EXIT_FAST:-"1"}
5-
[[ $EXIT_FAST == "1" ]] && set -e
4+
EXIT_FAST=${EXIT_FAST:-'true'}
5+
[ $EXIT_FAST = 'true' ] && set -e
66

77
schemaOutputPath="/tmp/otomi/kubernetes-json-schema/master"
88
outputPath="/tmp/otomi/generated-crd-schemas"
@@ -14,9 +14,9 @@ exitcode=1
1414
. bin/common.sh
1515

1616
cleanup() {
17-
[[ $exitcode -eq 0 ]] && echo "Validation Success" || echo "Validation Failed"
17+
[ $exitcode -eq 0 ] && echo "Validation Success" || echo "Validation Failed"
1818
rm -rf $extractCrdSchemaJQFile
19-
[[ "${MOUNT_TMP_DIR-0}" != "1" ]] && rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
19+
rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
2020
exit $exitcode
2121
}
2222
trap cleanup EXIT ERR
@@ -62,7 +62,7 @@ process_crd() {
6262
jq -S -c --raw-output -f "$extractCrdSchemaJQFile" >>"$schemasBundleFile"
6363
} || {
6464
echo "ERROR Processing: $document"
65-
[[ $EXIT_FAST == "1" ]] && exit 1
65+
[ $EXIT_FAST = 'true' ] && exit 1
6666
}
6767
}
6868

bin/validate-values.sh

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

33
set -uo pipefail
4-
EXIT_FAST=${EXIT_FAST:-"1"}
5-
[[ $EXIT_FAST == "1" ]] && set -e
4+
EXIT_FAST=${EXIT_FAST:-'true'}
5+
[ $EXIT_FAST = 'true' ] && set -e
66

77
. bin/common.sh
88

@@ -11,7 +11,7 @@ mkdir -p $tmp_path >/dev/null
1111

1212
cleanup() {
1313
local exitcode=$?
14-
[[ "${MOUNT_TMP_DIR-0}" != "1" ]] && rm -rf $tmp_path
14+
rm -rf $tmp_path
1515
return $exitcode
1616
}
1717
trap cleanup EXIT ERR

0 commit comments

Comments
 (0)