diff --git a/deploy.cmd b/deploy.cmd deleted file mode 100644 index 5c9b42b..0000000 --- a/deploy.cmd +++ /dev/null @@ -1,63 +0,0 @@ -@echo off -setlocal enabledelayedexpansion enableextensions -poetry check || exit /b - -set DOCKER_BUILDKIT=1 -set DOCKER_REGISTRY=registry.alertua.duckdns.org -echo DOCKER_REGISTRY: %DOCKER_REGISTRY% - -for %%I in ("%~dp0.") do set "IMAGE_NAME=%%~nxI" -echo IMAGE_NAME: %IMAGE_NAME% - -set IMAGE_TAG=latest -echo IMAGE_TAG: %IMAGE_TAG% - -set BUILD_TAG=%DOCKER_REGISTRY%/%IMAGE_NAME%:%IMAGE_TAG% -echo BUILD_TAG: %BUILD_TAG% - -set "BUILD_PATH=%~dp0" -echo BUILD_PATH: %BUILD_PATH% - -set DOCKER_EXE=docker -rem set DOCKER_OPTS=--insecure-registry=%DOCKER_REGISTRY% -set DOCKER_OPTS=--max-concurrent-uploads=10 --max-concurrent-downloads=10 - -"%DOCKER_EXE%" --version - -echo DOCKER_REMOTE: %DOCKER_REMOTE% -if defined DOCKER_HOST echo DOCKER_HOST: %DOCKER_HOST% - -@REM choice /C YN /m "Proceed?" -@REM if ["%errorlevel%"] NEQ ["1"] exit /b -timeout /t 5 - -if not defined DOCKER_REMOTE ( - set DOCKER_SERVICE=com.docker.service - where %DOCKER_EXE% >nul || ( - set "DOCKER_EXE=%ProgramFiles%\Docker\Docker\resources\bin\docker.exe" - ) - - pushd %~dp0 - sc query %DOCKER_SERVICE% | findstr /IC:"running" >nul || ( - echo starting Docker service %DOCKER_SERVICE% - sudo net start %DOCKER_SERVICE% || ( - echo "Error starting docker service %DOCKER_SERVICE% - exit /b - ) - ) - - tasklist | findstr /IC:"Docker Desktop.exe" >nul || ( - start "" "%ProgramFiles%\Docker\Docker\Docker Desktop.exe" - :loop - call docker info >nul 2>nul || ( - timeout /t 1 >nul - goto loop - ) - rem timeout /t 60 - ) -) - -"%DOCKER_EXE%" build -t %BUILD_TAG% %BUILD_PATH% %* || exit /b -"%DOCKER_EXE%" push %DOCKER_REGISTRY%/%IMAGE_NAME% || exit /b - -@REM net stop %DOCKER_SERVICE% || exit /b diff --git a/script/deploy.cmd b/script/deploy.cmd new file mode 100644 index 0000000..daffc66 --- /dev/null +++ b/script/deploy.cmd @@ -0,0 +1,81 @@ +@echo off +setlocal enabledelayedexpansion enableextensions + +poetry check || goto :end +if not exist poetry.lock poetry lock || goto :end + +if not defined DOCKER_BUILDKIT set DOCKER_BUILDKIT=1 +if not defined DOCKER_REGISTRY set DOCKER_REGISTRY=registry.alertua.duckdns.org +echo DOCKER_REGISTRY: %DOCKER_REGISTRY% + +set prevdir=%CD% +echo prevdir: %prevdir% + +cd /d %~dp0 + +for %%I in ("%CD%") do set "curdir=%%~nxI" +set "curdir_prefix=!curdir:~0,6!" +if /I "%curdir_prefix%"=="script" cd .. +for %%I in ("%CD%") do set "curdir=%%~nxI" +echo curdir: %curdir% + +if not defined IMAGE_NAME set IMAGE_NAME=%curdir% +echo IMAGE_NAME: %IMAGE_NAME% + +if not defined IMAGE_TAG set IMAGE_TAG=latest +echo IMAGE_TAG: %IMAGE_TAG% + +if not defined BUILD_TAG set BUILD_TAG=%DOCKER_REGISTRY%/%IMAGE_NAME%:%IMAGE_TAG% +echo BUILD_TAG: %BUILD_TAG% + +if not defined BUILD_PATH set "BUILD_PATH=%CD%" +echo BUILD_PATH: %BUILD_PATH% +pushd %BUILD_PATH% + +if not defined DOCKER_EXE set DOCKER_EXE=docker +rem set DOCKER_OPTS=--insecure-registry=%DOCKER_REGISTRY% +if not defined DOCKER_OPTS set DOCKER_OPTS=--max-concurrent-uploads=10 --max-concurrent-downloads=10 + +"%DOCKER_EXE%" --version + +echo DOCKER_REMOTE: %DOCKER_REMOTE% +if defined DOCKER_HOST echo DOCKER_HOST: %DOCKER_HOST% + +@REM choice /C YN /m "Proceed?" +@REM if ["%errorlevel%"] NEQ ["1"] goto :end +timeout /t 7 + +if not defined DOCKER_REMOTE ( + if not defined DOCKER_SERVICE set DOCKER_SERVICE=com.docker.service + where %DOCKER_EXE% >nul || set "DOCKER_EXE=%ProgramFiles%\Docker\Docker\resources\bin\docker.exe" + + sc query %DOCKER_SERVICE% | findstr /IC:"running" >nul || ( + echo starting Docker service %DOCKER_SERVICE% + sudo net start %DOCKER_SERVICE% || ( + echo "Error starting docker service %DOCKER_SERVICE% + goto :end + ) + ) + + tasklist | findstr /IC:"Docker Desktop.exe" >nul || ( + start "" "%ProgramFiles%\Docker\Docker\Docker Desktop.exe" + :loop + call docker info >nul 2>nul || ( + timeout /t 1 >nul + goto loop + ) + rem timeout /t 60 + ) +) + +"%DOCKER_EXE%" --version +"%DOCKER_EXE%" build -t %BUILD_TAG% %BUILD_PATH% %* || goto :end +"%DOCKER_EXE%" push %DOCKER_REGISTRY%/%IMAGE_NAME% || goto :end + +@REM net stop %DOCKER_SERVICE% || goto :end + +goto :end + +:end +cd /d %prevdir% +exit /b diff --git a/deploy_remote.cmd b/script/deploy_remote.cmd similarity index 55% rename from deploy_remote.cmd rename to script/deploy_remote.cmd index ea23d4a..39fc41c 100644 --- a/deploy_remote.cmd +++ b/script/deploy_remote.cmd @@ -1,7 +1,6 @@ @echo off -cd %~dp0 -set DOCKER_HOST=tcp://gitlab:2375 +set DOCKER_HOST=tcp://docker:2375 set DOCKER_REMOTE=1 -call deploy.cmd %* +call %~dp0\deploy.cmd %* where nircmd >nul 2>nul && nircmd beep 500 500