2121 KOMPOSE_ROOT=$( readlink -f $( dirname " ${BASH_SOURCE} " ) /../../..)
2222fi
2323
24+ # for mac (GNU realpath)
25+ realpath_cmd=" realpath"
26+ if type " grealpath" > /dev/null 2>&1 ; then
27+ realpath_cmd=" grealpath"
28+ fi
29+
30+ # Check for container runtime (docker or podman)
31+ # These are needed for --build local tests
32+ CONTAINER_RUNTIME=" "
33+ BUILD_CMD_FLAGS=" "
34+ if docker info > /dev/null 2>&1 ; then
35+ CONTAINER_RUNTIME=" docker"
36+ elif podman info > /dev/null 2>&1 ; then
37+ CONTAINER_RUNTIME=" podman"
38+ BUILD_CMD_FLAGS=" --build-command 'podman build' --push-command 'podman push'"
39+ fi
40+
2441source $KOMPOSE_ROOT /script/test/cmd/lib.sh
2542
2643# Get current branch and remote url of git repository
@@ -48,8 +65,8 @@ os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/$DIR/
4865k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/$DIR /output-k8s.yaml"
4966os_output=" $KOMPOSE_ROOT /script/test/fixtures/$DIR /output-os.yaml"
5067
51- convert::expect_success " $k8s_cmd " " $k8s_output "
52- convert::expect_success " $os_cmd " " $os_output "
68+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output "
69+ convert::expect_success_and_warning " $os_cmd " " $os_output "
5370
5471
5572
@@ -88,24 +105,29 @@ convert::check_artifacts_generated "kompose --provider=openshift -f $KOMPOSE_ROO
88105
89106
90107# #####
91- # Test the path of build image
92- # Test build v2 absolute compose file
93- convert::check_artifacts_generated " kompose --build local -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose.yaml convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
94- # Test build v2 relative compose file
95- relative_path=$( realpath --relative-to=" $PWD " " $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose.yaml" )
96- convert::check_artifacts_generated " kompose --build local -f $relative_path convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
97- # Test build v3 absolute compose file with context
98- convert::check_artifacts_generated " kompose --build local -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-v3.yaml convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
99- # Test build v3 relative compose file with context
100- relative_path=$( realpath --relative-to=" $PWD " " $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-v3.yaml" )
101- convert::check_artifacts_generated " kompose --build local -f $relative_path convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
102-
103- # #####
104- # Test the build config with push image
105- # see tests_push_image.sh for local push test
106- # Should warn when push image disabled
107- cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-build-no-image.yaml -o $TEMP_DIR /output_file convert --build=local --push-image-registry=whatever"
108- convert::expect_warning " $cmd " " Push image registry 'whatever' is specified but push image is disabled, skipping pushing to repository"
108+ # Test the path of build image (requires docker or podman)
109+ if [ -n " $CONTAINER_RUNTIME " ]; then
110+ echo " Container runtime detected: $CONTAINER_RUNTIME - running build tests"
111+ # Test build v2 absolute compose file
112+ convert::check_artifacts_generated " kompose --build local $BUILD_CMD_FLAGS -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose.yaml convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
113+ # Test build v2 relative compose file
114+ relative_path=$( $realpath_cmd --relative-to=" $PWD " " $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose.yaml" )
115+ convert::check_artifacts_generated " kompose --build local $BUILD_CMD_FLAGS -f $relative_path convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
116+ # Test build v3 absolute compose file with context
117+ convert::check_artifacts_generated " kompose --build local $BUILD_CMD_FLAGS -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-v3.yaml convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
118+ # Test build v3 relative compose file with context
119+ relative_path=$( $realpath_cmd --relative-to=" $PWD " " $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-v3.yaml" )
120+ convert::check_artifacts_generated " kompose --build local $BUILD_CMD_FLAGS -f $relative_path convert -o $TEMP_DIR /output_file" " $TEMP_DIR /output_file"
121+
122+ # #####
123+ # Test the build config with push image
124+ # see tests_push_image.sh for local push test
125+ # Should warn when push image disabled
126+ cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/buildconfig/compose-build-no-image.yaml -o $TEMP_DIR /output_file convert --build=local $BUILD_CMD_FLAGS --push-image-registry=whatever"
127+ convert::expect_warning " $cmd " " Push image registry 'whatever' is specified but push image is disabled, skipping pushing to repository"
128+ else
129+ echo " SKIP: Build tests require docker or podman (neither is running)"
130+ fi
109131
110132# TEST the kompose.volume.storage-class-name label
111133convert::check_artifacts_generated " kompose -f $KOMPOSE_ROOT /script/test/fixtures/storage-class-name/compose.yaml convert -o $TEMP_DIR /output-k8s.yaml" " $TEMP_DIR /output-k8s.yaml"
@@ -159,8 +181,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/compose.
159181k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.yaml"
160182os_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/change-in-volume/compose.yaml convert --with-kompose-annotation=false --stdout --volumes emptyDir"
161183os_output=" $KOMPOSE_ROOT /script/test/fixtures/change-in-volume/output-os-empty-vols-template.yaml"
162- convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
163- convert::expect_success " $os_cmd " " $os_output " || exit 1
184+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
185+ convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
164186
165187# Test that emptyvols works
166188k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/change-in-volume/compose.yaml convert --with-kompose-annotation=false --stdout --emptyvols"
@@ -205,8 +227,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/statefulset/compose.yaml
205227ocp_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/statefulset/compose.yaml convert --stdout --with-kompose-annotation=false --controller statefulset"
206228k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/statefulset/output-k8s.yaml"
207229ocp_output=" $KOMPOSE_ROOT /script/test/fixtures/statefulset/output-os.yaml"
208- convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
209- convert::expect_success " $ocp_cmd " " $ocp_output " || exit 1
230+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
231+ convert::expect_success_and_warning " $ocp_cmd " " $ocp_output " || exit 1
210232
211233# test cronjob
212234k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/cronjob/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -222,7 +244,7 @@ os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/mul
222244k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/multiple-type-volumes/output-k8s.yaml"
223245os_output=" $KOMPOSE_ROOT /script/test/fixtures/multiple-type-volumes/output-os.yaml"
224246convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
225- convert::expect_success " $os_cmd " " $os_output " || exit 1
247+ convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
226248
227249# Test environment variables interpolation
228250k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/envvars-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -237,8 +259,8 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/env-dotenv/compose.yaml c
237259os_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/env-dotenv/compose.yaml convert --stdout --with-kompose-annotation=false"
238260k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/env-dotenv/output-k8s.yaml"
239261os_output=" $KOMPOSE_ROOT /script/test/fixtures/env-dotenv/output-os.yaml"
240- convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
241- convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
262+ convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
263+ convert::expect_success " $os_cmd " " $os_output " || exit 1
242264
243265# Test single file output feature
244266k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/single-file-output/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -275,7 +297,7 @@ k8s_output="$KOMPOSE_ROOT/script/test/fixtures/fsgroup/output-k8s.yaml"
275297os_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/fsgroup/compose.yaml convert --stdout --with-kompose-annotation=false"
276298os_output=" $KOMPOSE_ROOT /script/test/fixtures/fsgroup/output-os.yaml"
277299convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
278- convert::expect_success " $os_cmd " " $os_output " || exit 1
300+ convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
279301
280302# Test support for compose.yaml file
281303k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/compose-file-support/compose.yaml convert --stdout --with-kompose-annotation=false"
@@ -286,29 +308,27 @@ convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
286308k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/compose-env-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
287309k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/compose-env-interpolation/output-k8s.yaml"
288310convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
289- convert::expect_success " $os_cmd " " $os_output " || exit 1
290311
291312# Test support for compose env without interpolation
292313k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/compose-env-no-interpolation/compose.yaml convert --stdout --no-interpolate --with-kompose-annotation=false"
293314k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/compose-env-no-interpolation/output-k8s.yaml"
294315convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
295- convert::expect_success " $os_cmd " " $os_output " || exit 1
296316
297- # Test configmap generated by env_file with variable interpolation
317+ # Test configmap generated by env_file with variable interpolation
298318k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/envfile-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
299319os_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/envfile-interpolation/compose.yaml convert --stdout --with-kompose-annotation=false"
300320k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/envfile-interpolation/output-k8s.yaml"
301321os_output=" $KOMPOSE_ROOT /script/test/fixtures/envfile-interpolation/output-os.yaml"
302- convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
303- convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
322+ convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
323+ convert::expect_success " $os_cmd " " $os_output " || exit 1
304324
305325# Test support for subpath volume
306326k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
307327k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/vols-subpath/output-k8s.yaml"
308328os_cmd=" kompose --provider=openshift -f $KOMPOSE_ROOT /script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
309329os_output=" $KOMPOSE_ROOT /script/test/fixtures/vols-subpath/output-os.yaml"
310330convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
311- convert::expect_success " $os_cmd " " $os_output " || exit 1
331+ convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
312332
313333# Test support for network policies generation
314334k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/network-policies/compose.yaml convert --generate-network-policies --stdout --with-kompose-annotation=false"
@@ -371,10 +391,10 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/initcontainer/compose.yam
371391k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/initcontainer/output-k8s.yaml"
372392convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
373393
374- # Test HPA
394+ # Test HPA
375395k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/hpa/compose.yaml convert --stdout --with-kompose-annotation=false"
376396k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/hpa/output-k8s.yaml"
377- convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
397+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
378398
379399# Test auto configmaps from files/dir
380400k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/configmap-file-configs/compose-1.yaml convert --stdout --with-kompose-annotation=false"
@@ -397,13 +417,13 @@ k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-file-configs/co
397417k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/configmap-file-configs/output-k8s-3.yaml"
398418os_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/configmap-file-configs/compose-3.yaml convert --provider openshift --stdout --with-kompose-annotation=false"
399419os_output=" $KOMPOSE_ROOT /script/test/fixtures/configmap-file-configs/output-os-3.yaml"
400- convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
401- convert::expect_success " $os_cmd " " $os_output " || exit 1
420+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
421+ convert::expect_success_and_warning " $os_cmd " " $os_output " || exit 1
402422
403423# Test network_mode: service:
404424k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/network-mode-service/compose.yaml convert --stdout --with-kompose-annotation=false"
405425k8s_output=" $KOMPOSE_ROOT /script/test/fixtures/network-mode-service/output-k8s.yaml"
406- convert::expect_success " $k8s_cmd " " $k8s_output " || exit 1
426+ convert::expect_success_and_warning " $k8s_cmd " " $k8s_output " || exit 1
407427
408428# Test env var with status
409429k8s_cmd=" kompose -f $KOMPOSE_ROOT /script/test/fixtures/envvars-with-status/compose.yaml convert --stdout --with-kompose-annotation=false"
0 commit comments