Skip to content

Commit a94b854

Browse files
CasLubbersCas Lubbersj-zimnowoda
authored
feat: run test not in docker by default (#1606) [TOOLS][MAJOR]
Co-authored-by: Cas Lubbers <[email protected]> Co-authored-by: Jehoszafat Zimnowoda <[email protected]>
1 parent 5675458 commit a94b854

22 files changed

+166
-133
lines changed

.env.sample

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# will bypass docker but expects all binaries present on host
2-
IN_DOCKER=1
32
VERBOSITY=2
43
# will disable contacting the cluster as found in kube context:
54
DISABLE_SYNC=1

.github/workflows/otomi-tools-build-push.yaml

+17-20
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: 'Version to build and push'
7+
description: 'Placeholder, this value is not yet used.'
88
required: false
9-
default: 'latest'
9+
default: 'run'
1010
type: string
1111
push:
1212
branches:
@@ -26,6 +26,13 @@ jobs:
2626
with:
2727
fetch-depth: '2'
2828

29+
- name: Docker meta
30+
id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ${{ env.REGISTRY_IMAGE }}
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
2936
- name: Set up Docker Buildx
3037
uses: docker/setup-buildx-action@v3
3138

@@ -63,29 +70,19 @@ jobs:
6370
echo OLD_VERSION = ${OLD_VERSION}
6471
echo NEW_VERSION = ${NEW_VERSION}
6572
fi
66-
6773
echo "No need to bump the version. Will skip next steps."
6874
69-
- name: Build and tag Docker image
70-
if: ${{ env.NEW_VERSION != null }}
71-
run: |
72-
docker buildx build --load -t ${{ env.NAMESPACE }}/${{ env.REPO }} -f tools/Dockerfile .
73-
docker tag ${{ env.NAMESPACE }}/${{ env.REPO }} ${{ env.NAMESPACE }}/${{ env.REPO }}:${{ env.NEW_VERSION }}
74-
75-
- name: Squash image
76-
if: ${{ env.NEW_VERSION != null }}
77-
run: |
78-
pip3 install docker-squash
79-
docker-squash otomi/tools -t ${{ env.NAMESPACE }}/${{ env.REPO }}:${{ env.NEW_VERSION }}
80-
8175
- name: Login to GitHub Container Registry
8276
if: ${{ env.NEW_VERSION != null }}
8377
uses: docker/login-action@v3
8478
with:
8579
username: 'otomi'
8680
password: '${{ secrets.DOCKERHUB_OTOMI_TOKEN }}'
87-
88-
- name: Push Docker image
89-
if: ${{ env.NEW_VERSION != null }}
90-
run: |
91-
docker push ${{ env.NAMESPACE }}/${{ env.REPO }}:${{ env.NEW_VERSION }}
81+
- name: image build and push tag for branch
82+
uses: docker/build-push-action@v5
83+
with:
84+
push: true
85+
platforms: linux/amd64
86+
file: tools/Dockerfile
87+
tags: |
88+
${{ env.NAMESPACE }}/${{ env.REPO }}:${{ env.NEW_VERSION }}

.husky/pre-push

-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,3 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
npm run lint
5-
6-
# Not in main
7-
if ! git diff HEAD main --quiet; then
8-
# if values files have BOTH been modified, then we know migrate is safe
9-
if test $(git diff origin/main --name-only | awk 'xor(/values-schema.yaml/,/values-changes.yaml/)' | wc -l) = 2; then
10-
npm run migrate-values
11-
fi
12-
fi

Dockerfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM otomi/tools:v1.6.0 as ci
1+
FROM otomi/tools:multi-arch as ci
22

33
ENV APP_HOME=/home/app/stack
44

@@ -9,7 +9,6 @@ ARG SKIP_TESTS='false'
99
ENV NODE_ENV='test'
1010
ENV CI=true
1111
ENV ENV_DIR=$APP_HOME/env
12-
ENV IN_DOCKER='1'
1312
ENV VERBOSITY='2'
1413
ENV DISABLE_SYNC='1'
1514
ENV NODE_PATH='dist'
@@ -28,11 +27,10 @@ FROM ci as clean
2827
RUN npm prune --production
2928

3029
#-----------------------------
31-
FROM otomi/tools:v1.6.0 as prod
30+
FROM otomi/tools:multi-arch as prod
3231

3332
ENV APP_HOME=/home/app/stack
3433
ENV ENV_DIR=/home/app/stack/env
35-
ENV IN_DOCKER='1'
3634
ENV VERBOSITY='0'
3735
ENV NODE_NO_WARNINGS='1'
3836
ENV NODE_PATH='dist'

bin/build-gatekeeper-artifacts.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function build() {
4949
function decorate() {
5050
echo "Decorating template/constraints files with properties."
5151
local map_constraints_expr='.policies as $constraints | $constraints | keys[] | {(.): $constraints[.]}'
52-
for constraint in $(yq r $policies_file -j | jq --raw-output -S -c "$map_constraints_expr"); do
52+
for constraint in $(yq -o=json $policies_file | jq --raw-output -S -c "$map_constraints_expr"); do
5353
local key=$(echo $constraint | jq --raw-output '. | keys[0]')
5454
# NOTE:
5555
# Konstraint library is generating filenames from folder names using the dash symbol "-" as uppercase markup. Example: file-name => FileName
@@ -58,16 +58,16 @@ function decorate() {
5858
# decorate constraints with parameters
5959
local constraints_file=$(ls $tmp_path/constraint_* | grep -i "$filename.yaml")
6060
local parameters=$(echo $constraint | jq --raw-output -c "{\"spec\":{\"parameters\": {\"$key\"} }}")
61-
local constraints=$(yq r -P -j $constraints_file | jq --raw-output -c '.')
62-
jq -n --argjson constraints $constraints --argjson parameters $parameters '$constraints * $parameters | .' | yq r -P - >"$constraints_file"
61+
local constraints=$(yq -o=json $constraints_file | jq --raw-output -c '.')
62+
jq -n --argjson constraints $constraints --argjson parameters $parameters '$constraints * $parameters | .' | yq -o=yaml - >"$constraints_file"
6363
# decorate constraint templates with openAPI schema properties
6464
local map_properties_expr='. as $properties | {"spec":{"crd":{"spec":{"validation": {"openAPIV3Schema": $properties }}}}} | .'
6565
local policy_json_path="properties.policies.properties[${key}]"
66-
local properties=$(yq -j r $compiled_schema_path $policy_json_path | yq d - '**.required.' | yq d - '**.default.' | yq d - '**.additionalProperties.' | jq -c --raw-output "$map_properties_expr")
66+
local properties=$(yq e 'del(..|.required?, .default?, .additionalProperties?)' -o=json -I=0 $compiled_schema_path | jq -c --raw-output "$map_properties_expr")
6767
local ctemplates_file=$(ls $tmp_path/template_* | grep -i "$filename.yaml")
6868
local template_file=${ctemplates_file/$tmp_path/$templates_path}
69-
local template=$(yq r -P -j $ctemplates_file | jq --raw-output -c '.')
70-
jq -n --argjson template "$template" --argjson properties "$properties" '$template * $properties | .' | yq r -P - >"$template_file"
69+
local template=$(yq e -o=json -I=0 $ctemplates_file | jq --raw-output -c '.')
70+
jq -n --argjson template "$template" --argjson properties "$properties" '$template * $properties | .' | yq e -o=yaml - >"$template_file"
7171
done
7272
}
7373

bin/common.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ fi
106106
function _rind() {
107107
local cmd="$1"
108108
shift
109-
if [ $has_docker = 'true' ] && [ -z "$IN_DOCKER" ]; then
109+
if [ $has_docker = 'true' ] && [ "${IN_DOCKER,,}" == "true" ]; then
110110
docker run --rm \
111111
$LINUX_WORKAROUND \
112112
-v $ENV_DIR:$ENV_DIR \
113-
-e IN_DOCKER='1' \
114113
-e ENV_DIR=$ENV_DIR \
115114
$otomi_tools_image $cmd "$@"
116115
return $?
@@ -133,7 +132,7 @@ function yq() {
133132

134133
function yqr() {
135134
local all_values=$(hf_values)
136-
local ret=$(echo "$all_values" | yq r - "$@")
135+
local ret=$(echo "$all_values" | yq "$@" -)
137136
[ -z "$ret" ] && return 1
138137
echo $ret
139138
}
@@ -149,14 +148,14 @@ function get_k8s_version() {
149148

150149
function otomi_image_tag() {
151150
local otomi_version=$OTOMI_VERSION
152-
[ -z "$otomi_version" ] && [ -f $otomi_settings ] && otomi_version=$(yq r $otomi_settings otomi.version)
151+
[ -z "$otomi_version" ] && [ -f $otomi_settings ] && otomi_version=$(yq '.otomi.version' $otomi_settings)
153152
[ -z "$otomi_version" ] && otomi_version=$(cat $PWD/package.json | jq -r .version)
154153
[ -z "$otomi_version" ] && otomi_version='main'
155154
echo $otomi_version
156155
}
157156

158157
function customer_name() {
159-
[ -f $otomi_settings ] && yq r $otomi_settings "customer.name" && return 0
158+
[ -f $otomi_settings ] && yq 'customer.name' $otomi_settings && return 0
160159
[ -n "$CI" ] && return 0
161160
return 1
162161
}
@@ -236,7 +235,7 @@ function hf_values() {
236235
hf -f helmfile.tpl/helmfile-dump.yaml build |
237236
grep -Ev $helmfile_output_hide |
238237
sed -e $replace_paths_pattern |
239-
yq read -P - 'renderedvalues'
238+
yq '.renderedvalues' -
240239
}
241240

242241
function hf_template() {

binzx/installer

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22

33
readonly script=otomi
4-
readonly branch=${OTOMI_TAG:-main}
4+
readonly current_branch=$(git rev-parse --abbrev-ref HEAD)
5+
readonly branch=${OTOMI_TAG:-$current_branch}
56
readonly remote=https://raw.githubusercontent.com/redkubes/otomi-core/$branch/binzx/$script
67
readonly path=/usr/local/bin
78

@@ -38,6 +39,9 @@ if [[ $SHELL == *zsh* ]] || [[ $SHELL == *bash* ]]; then
3839
acPath='/usr/local/share/zsh/site-functions/_otomi'
3940
if [[ $SHELL == *bash* ]]; then
4041
acPath='/usr/local/etc/bash_completion.d/otomi.bash'
42+
mkdir -p /usr/local/etc/bash_completion.d
43+
else
44+
mkdir -p /usr/local/share/zsh/site-functions
4145
fi
4246
otomi completion | tr -d '\r' >$acPath
4347
chmod +x $acPath
@@ -51,5 +55,8 @@ if [[ $SHELL == *zsh* ]] || [[ $SHELL == *bash* ]]; then
5155
esac
5256
fi
5357

58+
# The /tmp/otomi is created by regular user. Installer creates it with root permisions only
59+
rm -rf /tmp/otomi
60+
5461
echo "Otomi has been installed in $file"
5562
echo 'You can now run it by calling `otomi`'

binzx/otomi

+13-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
# shellcheck disable=SC2128
1515
[ "${BASH_VERSINFO:-0}" -lt 4 ] && echo "You are using $BASH_VERSINFO, while we only support Bash -ge than version 4. Please upgrade." && exit 1
1616
calling_args="$*"
17+
if [ -z "$IN_DOCKER" ]; then
18+
IN_DOCKER=false
19+
fi
1720
if [ "$NODE_ENV" == "test" ]; then
1821
CI=1
1922
ENV_DIR="$PWD/tests/fixtures"
2023
NOPULL=1
2124
OTOMI_TAG="main"
22-
elif [ -z "$ENV_DIR" ] && [ -n "$IN_DOCKER" ]; then
25+
elif [ -z "$ENV_DIR" ] && [ "${IN_DOCKER,,}" == "false" ]; then
2326
ENV_DIR="$PWD/env"
24-
elif [ -z "$IN_DOCKER" ] && [ -n "$ENV_DIR" ]; then
25-
mkdir -p $ENV_DIR
27+
elif [ -z "$IN_DOCKER" ]; then
28+
IN_DOCKER=false
29+
if [ -n "$ENV_DIR" ]; then
30+
mkdir -p $ENV_DIR
31+
fi
2632
fi
2733
[[ "$ENV_DIR" == *"../"* ]] && echo "Don't provide an ENV_DIR that contains '../'!" && exit 1
2834
# treat CI and chart as non interactive
@@ -176,7 +182,7 @@ check_update() {
176182
fi
177183
}
178184

179-
[ -z $DONT_CHECK_UPDATE ] && [ -z $IN_DOCKER ] && silent echo "Checking for updates" && check_update
185+
[ -z $DONT_CHECK_UPDATE ] && [ "${IN_DOCKER,,}" != "false" ] && silent echo "Checking for updates" && check_update
180186

181187
tmp_env=$(mktemp)
182188

@@ -232,7 +238,7 @@ dump_vars "${vars[@]}"
232238

233239
cat >>$tmp_env <<EOF
234240
OTOMI_CALLER_COMMAND=${BASH_SOURCE[0]##*/}
235-
IN_DOCKER=1
241+
IN_DOCKER=false
236242
EOF
237243

238244
helm_config="$HOME/.config/helm"
@@ -279,7 +285,7 @@ if [ "$1" = "bash" ] && [ "$#" = "1" ]; then
279285
cmd="bash"
280286
fi
281287

282-
if { { [ "$otomi_version_used" = 'latest' ] || [ "$otomi_version_used" = 'main' ]; } || [ -n "$FORCE_PULL" ]; } && [ -z $NOPULL ] && [ -z $IN_DOCKER ]; then
288+
if { { [ "$otomi_version_used" = 'latest' ] || [ "$otomi_version_used" = 'main' ]; } || [ -n "$FORCE_PULL" ]; } && [ -z $NOPULL ] && [ "${IN_DOCKER,,}" != "false" ]; then
283289
silent echo "Pulling latest version of the docker image, please wait"
284290
silent docker pull $otomi_tools_image
285291
status=$?
@@ -304,7 +310,7 @@ mkdir -p /tmp/otomi
304310
# Issue arises due to OSX not assuming UTF-8 format: https://unix.stackexchange.com/a/64905 need to set LC_ALL=C
305311
container_name="otomi-core-$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)"
306312

307-
if [ -n "$IN_DOCKER" ]; then
313+
if [ "${IN_DOCKER,,}" == "false" ]; then
308314
silent echo $cmd
309315
$cmd
310316
status=$?

chart/otomi/localtest.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -eu
88
# Set port forwarding so otomi the 'otomi apply' can push values to gitea
99
# k port-forward -n gitea svc/gitea-http 3000:3000
1010

11-
export IN_DOCKER=1
11+
export IN_DOCKER=false
1212
# OTOMI_DEV_APPLY_LABEL - In local test you can narrow down the helm releases that are going to be installed while perogotim otomi apply
1313
# export OTOMI_DEV_APPLY_LABEL=pkg=gitea
1414
export VALUES_INPUT=${VALUES_INPUT:-'tests/bootstrap/input.yaml'}

charts/otomi-pipelines/templates/tekton-otomi-git-clone.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
stepTemplate:
2626
computeResources: {{- toYaml .Values.tektonTask.resources | nindent 6 }}
2727
workingDir: $(workspaces.source.path)
28-
image: otomi/core:v1.0.0
28+
image: otomi/core:{{ .Values.otomiVersion }}
2929
steps:
3030
- name: git-clone
3131
script: |
@@ -63,7 +63,7 @@ spec:
6363
echo -n "0" > $(results.CI.path) && export CI="0" && echo "Finished"
6464
fi
6565
66-
echo -n "$(yq r values/env/settings.yaml otomi.version)" > $(results.OTOMI_VERSION.path)
66+
echo -n "$(yq '.otomi.version' values/env/settings.yaml)" > $(results.OTOMI_VERSION.path)
6767
cd values
6868
# Check if team files has been changed
6969
if git diff --name-only HEAD~1 | grep -e "env/.*.teams" -e "env/teams"; then

charts/otomi-pipelines/templates/tekton-otomi-task-teams.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
- name: CI
3131
value: $(params["CI"])
3232
- name: IN_DOCKER
33-
value: '1'
33+
value: 'false'
3434
- name: ENV_DIR
3535
value: /home/app/stack/env
3636
- name: VERBOSE

charts/otomi-pipelines/templates/tekton-otomi-task.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
- name: CI
3131
value: $(params["CI"])
3232
- name: IN_DOCKER
33-
value: '1'
33+
value: 'false'
3434
- name: ENV_DIR
3535
value: /home/app/stack/env
3636
- name: VERBOSE

charts/otomi-pipelines/values.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ kms: {}
3030

3131
giteaPassword: ""
3232

33-
cloneUnsecure: false
33+
cloneUnsecure: false
34+
35+
otomiVersion: 0.1.0

docs/development.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ npm run install-deps
418418
Then instruct Otomi to not run in docker:
419419

420420
```
421-
export IN_DOCKER=1
421+
export IN_DOCKER=false
422422
```
423423

424424
Next you can execute `otomi apply` or `otomi status` against your to connect with your kubernetes cluster.

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@
117117
},
118118
"scripts": {
119119
"install-deps": "bin/install-deps.sh",
120-
"app-versions:csv": "echo 'name,appVersion,chartVersion'; for f in $(find charts -name Chart.yaml -type f -maxdepth 2| sort); do yq eval -o=json $f | jq -rc '. | [.name, .appVersion, .version] | @csv' | tr -d '\"'; done",
120+
"app-versions:csv": "echo 'name,appVersion,chartVersion'; for f in $(find charts -name Chart.yaml -type f -maxdepth 2| sort); do yq e -o=json -I=0 $f | jq -rc '. | [.name, .appVersion, .version] | @csv' | tr -d '\"'; done",
121121
"adr": "adr-log -d adr -i",
122-
"check-policies": "NODE_ENV=test binzx/otomi check-policies",
122+
"check-policies": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test binzx/otomi check-policies",
123123
"clean": "rm -rf dist >/dev/null",
124124
"compile": "npm run clean && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json -v --dir dist && chmod +x ./dist/src/otomi.js",
125125
"compile:watch": "npm run compile && tsc -w",
@@ -134,7 +134,7 @@
134134
"lint": "run-p spellcheck lint:hf lint:ts lint:types",
135135
"lint-staged": "lint-staged",
136136
"lint:fix": "prettier --write tests/**/*.yaml --write '.values/env/**/*.yaml' && npm run lint:ts:fix",
137-
"lint:hf": "NODE_ENV=test binzx/otomi lint",
137+
"lint:hf": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test binzx/otomi lint",
138138
"lint:ts": "eslint --ext ts src",
139139
"lint:ts:fix": "eslint --fix --ext ts src",
140140
"lint:types": "tsc --noEmit",
@@ -150,11 +150,11 @@
150150
"tasks:copy-certs": "binzx/otomi task -n copyCerts",
151151
"test": "run-s test:ts lint validate-values validate-templates check-policies",
152152
"test:opa": "NODE_ENV=test binzx/otomi x opa test policies -v",
153-
"test:ts": "NODE_ENV=test jest",
153+
"test:ts": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test jest",
154154
"test:ts-cov": "jest --coverage",
155-
"validate-templates": "NODE_ENV=test binzx/otomi validate-templates",
155+
"validate-templates": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test binzx/otomi validate-templates",
156156
"validate-templates:all": "set -e; i=25; while [ $i -le 28 ]; do NODE_ENV=test binzx/otomi validate-templates -k 1.$i; i=$(($i+1)); done",
157-
"validate-values": "NODE_ENV=test binzx/otomi validate-values",
157+
"validate-values": "ENV_DIR=$PWD/tests/fixtures NODE_ENV=test binzx/otomi validate-values",
158158
"bootstrap-dev": "rm -rf /tmp/otomi-bootstrap-dev; CI=1 VALUES_INPUT=$PWD/tests/bootstrap/input.yaml ENV_DIR=/tmp/otomi-bootstrap-dev binzx/otomi bootstrap",
159159
"bootstrap-dev-with-repo": "CI=1 ENV_DIR=/tmp/otomi-bootstrap-dev binzx/otomi bootstrap"
160160
},

schemas/gen-missing-crd-schemas.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rm -rf $input_folder/*
2121
for pkg in "pipeline" "pipelinerun" "task" "taskrun" ; do
2222
pkg_file="$input_folder/$pkg.yaml"
2323
echo '' >$pkg_file
24-
for crd in $(kubectl get crd | grep $pkg | awk '{print $1}'); do kubectl get crd $crd -o yaml | yq e 'del(.metadata)' | yq e 'del(.status)' >>$pkg_file && printf "\n---\n" >>$pkg_file; done
24+
for crd in $(kubectl get crd | grep $pkg | awk '{print $1}'); do kubectl get crd $crd -o yaml | yq 'del(.metadata, .status)' - >>$pkg_file && printf "\n---\n" >>$pkg_file; done
2525
pushd $gen_folder || exit
2626
../crd2jsonschema.py ../input-crds/$pkg.yaml
2727
popd || exit

src/cmd/migrate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,5 +413,5 @@ describe('Network policies migrations', () => {
413413
await applyChanges([valuesChanges], false, deps)
414414
const expectedValues = getExpectedValues()
415415
expect(deps.writeValues).toBeCalledWith(expectedValues, true)
416-
})
416+
}, 20000)
417417
})

0 commit comments

Comments
 (0)