From ec029153bd31e3d3bcae3f60bf2ed9eb43bee7bb Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Keck <jean-baptiste.keck@univ-grenoble-alpes.fr>
Date: Sat, 24 Sep 2022 11:24:57 +0200
Subject: [PATCH] update bat scripts [ci skip]

---
 ci/utils/pull_docker_image.bat | 36 +++++++++++-----------------------
 ci/utils/push_docker_image.bat | 31 ++++++-----------------------
 ci/utils/run_ci.bat            | 21 ++++++++++++++++++++
 ci/utils/run_docker_image.bat  | 16 +++++++--------
 4 files changed, 46 insertions(+), 58 deletions(-)
 create mode 100644 ci/utils/run_ci.bat

diff --git a/ci/utils/pull_docker_image.bat b/ci/utils/pull_docker_image.bat
index 46d12f5a6..e95513ede 100755
--- a/ci/utils/pull_docker_image.bat
+++ b/ci/utils/pull_docker_image.bat
@@ -1,27 +1,13 @@
-#!/usr/bin/env bash
-##
-## Copyright (C) HySoP 2011-2022
-##
-## Licensed under the Apache License, Version 2.0 (the "License");
-## you may not use this file except in compliance with the License.
-## You may obtain a copy of the License at
-##
-##         http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-##
-set -euf -o pipefail
-DOCKER_IMAGE_TAG=${1:-jammy}
-HYSOP_REGISTRY_URL='gricad-registry.univ-grenoble-alpes.fr'
+pushd %~dp0
+set SCRIPT_DIR=%CD%
+popd
+
+set NTHREADS=%NUMBER_OF_PROCESSORS%
+set HYSOP_REGISTRY_URL=gricad-registry.univ-grenoble-alpes.fr
+
+if "%~1" NEQ "" (set DOCKER_IMAGE_TAG=%~1) else (set DOCKER_IMAGE_TAG=jammy)
+
 docker logout
-if [[ -z "${HYSOP_REGISTRY_USERNAME}" ]] || [[ -z "${HYSOP_REGISTRY_TOKEN}" ]]; then
-    docker login "${HYSOP_REGISTRY_URL}"
-else
-    echo "${HYSOP_REGISTRY_TOKEN}" | docker login "${HYSOP_REGISTRY_URL}" --username "${HYSOP_REGISTRY_USERNAME}" --password-stdin
-fi
-docker pull "${HYSOP_REGISTRY_URL}/particle_methods/hysop:${DOCKER_IMAGE_TAG}"
+docker login "%HYSOP_REGISTRY_URL%"
+docker pull "%HYSOP_REGISTRY_URL%/particle_methods/hysop:%DOCKER_IMAGE_TAG%"
 docker logout
diff --git a/ci/utils/push_docker_image.bat b/ci/utils/push_docker_image.bat
index c4e9a855e..69ad225b5 100755
--- a/ci/utils/push_docker_image.bat
+++ b/ci/utils/push_docker_image.bat
@@ -1,27 +1,8 @@
-#!/usr/bin/env bash
-##
-## Copyright (C) HySoP 2011-2022
-##
-## Licensed under the Apache License, Version 2.0 (the "License");
-## you may not use this file except in compliance with the License.
-## You may obtain a copy of the License at
-##
-##         http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-##
-set -euf -o pipefail
-DOCKER_IMAGE_TAG=${1:-jammy}
-HYSOP_REGISTRY_URL='gricad-registry.univ-grenoble-alpes.fr'
+set HYSOP_REGISTRY_URL=gricad-registry.univ-grenoble-alpes.fr
+
+if "%~1" NEQ "" (set DOCKER_IMAGE_TAG=%~1) else (set DOCKER_IMAGE_TAG=jammy)
+
 docker logout
-if [[ -z "${HYSOP_REGISTRY_USERNAME}" ]] || [[ -z "${HYSOP_REGISTRY_TOKEN}" ]]; then
-    docker login "${HYSOP_REGISTRY_URL}"
-else
-    echo "${HYSOP_REGISTRY_TOKEN}" | docker login "${HYSOP_REGISTRY_URL}" --username "${HYSOP_REGISTRY_USERNAME}" --password-stdin
-fi
-docker push "${HYSOP_REGISTRY_URL}/particle_methods/hysop:${DOCKER_IMAGE_TAG}"
+docker login "%HYSOP_REGISTRY_URL%"
+docker push "%HYSOP_REGISTRY_URL%/particle_methods/hysop:%DOCKER_IMAGE_TAG%"
 docker logout
diff --git a/ci/utils/run_ci.bat b/ci/utils/run_ci.bat
new file mode 100644
index 000000000..34118d2c6
--- /dev/null
+++ b/ci/utils/run_ci.bat
@@ -0,0 +1,21 @@
+pushd %~dp0
+set SCRIPT_DIR=%CD%
+popd
+
+set "HYSOP_REGISTRY_URL=gricad-registry.univ-grenoble-alpes.fr"
+if "%~1" NEQ "" (set DOCKER_IMAGE_TAG=%~1) else (set DOCKER_IMAGE_TAG=jammy)
+set "DOCKER_IMAGE_TAG_POSTFIX=%DOCKER_IMAGE_TAG:~-4%"
+IF "%DOCKER_IMAGE_TAG_POSTFIX%" == "cuda" (set "EXTRA_ARGS=--gpus all") else (set "EXTRA_ARGS=")
+set "DOCKER_IMG=%HYSOP_REGISTRY_URL%/particle_methods/hysop:%DOCKER_IMAGE_TAG%"
+set "CONTAINER_ID=hysop_build_and_test"
+
+docker stop %CONTAINER_ID%
+docker rm %CONTAINER_ID%
+
+docker create %EXTRA_ARGS% -v "%SCRIPT_DIR%\..\..:/hysop:ro" --name=%CONTAINER_ID% -it %DOCKER_IMG%
+
+docker start %CONTAINER_ID%
+
+docker exec %CONTAINER_ID% /hysop/ci/scripts/build_and_test.sh
+
+docker commit %CONTAINER_ID% %DOCKER_IMG%
diff --git a/ci/utils/run_docker_image.bat b/ci/utils/run_docker_image.bat
index c0d6255ea..24200c767 100755
--- a/ci/utils/run_docker_image.bat
+++ b/ci/utils/run_docker_image.bat
@@ -1,8 +1,8 @@
-SET DOCKER_IMAGE_TAG=%1:-jammy%
-SET HYSOP_REGISTRY_URL='gricad-registry.univ-grenoble-alpes.fr'
-IF [[ "%DOCKER_IMAGE_TAG%" == "*_cuda" "]]" (
-  SET EXTRA_ARGS=--gpus all
-) ELSE (
-  SET EXTRA_ARGS=
-)
-docker "run" "--cap-add=SYS_PTRACE" "%EXTRA_ARGS%" "-it" "-v" "%SCRIPT_DIR%\..\%CD%.:\hysop:ro" "%HYSOP_REGISTRY_URL%\particle_methods\hysop:%DOCKER_IMAGE_TAG%"
+pushd %~dp0
+set SCRIPT_DIR=%CD%
+popd
+set HYSOP_REGISTRY_URL=gricad-registry.univ-grenoble-alpes.fr
+if "%~1" NEQ "" (set DOCKER_IMAGE_TAG=%~1) else (set DOCKER_IMAGE_TAG=jammy)
+set "DOCKER_IMAGE_TAG_POSTFIX=%DOCKER_IMAGE_TAG:~-4%"
+if "%DOCKER_IMAGE_TAG_POSTFIX%" == "cuda" (set "EXTRA_ARGS=--gpus all") else (set "EXTRA_ARGS=")
+docker run %EXTRA_ARGS% -it -v "%SCRIPT_DIR%\..\..:/hysop:ro" "%HYSOP_REGISTRY_URL%/particle_methods/hysop:%DOCKER_IMAGE_TAG%"
-- 
GitLab