From 3300433f40906e7bc8bf5c330aefa9471eae47ab Mon Sep 17 00:00:00 2001 From: Aquiles Viza Date: Fri, 22 Sep 2023 03:26:08 -0300 Subject: [PATCH] Updated dependencies and added gitattributes --- .gitattributes | 10 +++ base/desktop.Dockerfile | 2 +- compile.bat | 52 +++++++++++++++ run.bat | 139 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 compile.bat create mode 100644 run.bat diff --git a/.gitattributes b/.gitattributes index 2d83761..62e06ab 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,11 @@ +# Auto detect text files and perform LF normalization +* text=auto .png filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.sh text eol=lf +*.bat text eol=crlf +desktopinit text eol=lf +klayout text eol=lf +setwallpaper text eol=lf +startserver text eol=lf +*.desktop text eol=lf diff --git a/base/desktop.Dockerfile b/base/desktop.Dockerfile index 08f7ce1..7bb9ac6 100644 --- a/base/desktop.Dockerfile +++ b/base/desktop.Dockerfile @@ -6,7 +6,7 @@ FROM greyltc/archlinux-aur:paru RUN pacman -Syuq --noconfirm # Install packages -RUN aur-install sudo git git-lfs python python-pip python-pipx xz gnu-free-fonts vim ngspice gedit jupyter-notebook +RUN aur-install sudo git git-lfs python python-pip python-pipx xz gnu-free-fonts vim ngspice gedit jupyter-lab xterm # Clean cache RUN pacman -Scc diff --git a/compile.bat b/compile.bat new file mode 100644 index 0000000..c28922b --- /dev/null +++ b/compile.bat @@ -0,0 +1,52 @@ +@echo off +setlocal + +SET STACK=analog-xk + +SET DOCKER_USER=akilesalreadytaken +SET DOCKER_IMAGE=analog-tools +SET DOCKER_TAG=latest + + +SET CALL=call +:parse + IF /I ""%1""=="""" GOTO run + IF /I ""%1""==""--help"" GOTO documentation + IF /I ""%1""==""-h"" GOTO documentation + IF /I ""%1""==""--dry"" ( SET "CALL=echo" ) + IF /I ""%1""==""-s"" ( SET "CALL=echo" ) + IF /I ""%1""==""--path"" ( SET "DESIGNS=%~2" && SHIFT ) + IF /I ""%1""==""-p"" ( SET "DESIGNS=%~2" && SHIFT ) + SHIFT + GOTO parse + + +:documentation + echo Usage: run.bat %~nx0 [-h^|--help] [-s^|--dry-run] + GOTO end + + +:run + SET TAG=%DOCKER_USER%/%DOCKER_IMAGE% + IF DEFINED DOCKER_TAG SET TAG=%TAG%:%DOCKER_TAG% + + %CALL% docker build --rm -t osicstacks-base-desktop -f base/desktop.Dockerfile . + %CALL% docker build --rm -t osicstacks-base-web -f base/web.Dockerfile . + %CALL% docker build --rm --build-arg BASE_IMG=osicstacks-base-web --target %STACK%-desktop -t %DOCKER_USER%/%STACK%:latest -f stacks/%STACK%.Dockerfile . + ::%CALL% docker build --rm --build-arg BASE_IMG=%DOCKER_USER%/%STACK%:latest -t %TAG% -f stacks/analog/Dockerfile + GOTO end + +:end + endlocal + + +:normalizepath + SET DESIGNS=%~f1 + EXIT /B + + +:: Get DISPLAY from WSL +::wsl --exec bash --norc -c 'echo $DISPLAY' + +:: Get current path of batsh script +::SET BATCH_PATH=%~dpnx0 \ No newline at end of file diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..1b5eccb --- /dev/null +++ b/run.bat @@ -0,0 +1,139 @@ +@echo off +setlocal + +SET IMAGE=akilesalreadytaken/analog-xk:latest + +SET CALL=call +:parse + IF /I ""%1""=="""" GOTO run + IF /I ""%1""==""--help"" GOTO documentation + IF /I ""%1""==""-h"" GOTO documentation + IF /I ""%1""==""--dry"" ( SET "CALL=echo" ) + IF /I ""%1""==""-s"" ( SET "CALL=echo" ) + IF /I ""%1""==""--path"" ( SET "DESIGNS=%~2" && SHIFT ) + IF /I ""%1""==""-p"" ( SET "DESIGNS=%~2" && SHIFT ) + SHIFT + GOTO parse + + +:documentation + echo Usage: run.bat %~nx0 [-h^|--help] [-s^|--dry-run] [-p^|--path PATH] + GOTO end + + +:run + :: Set fixed parameters + ::::::::::::::::::::::::::: + IF NOT DEFINED DESIGNS SET DESIGNS=%CD% + CALL :NORMALIZEPATH %DESIGNS% + + IF NOT DEFINED PDK SET PDK=gf180mcuC + + IF NOT DEFINED DOCKER_USER SET DOCKER_USER=git.1159.cl/mario1159 + IF NOT DEFINED DOCKER_IMAGE SET DOCKER_IMAGE=analog-xk + IF NOT DEFINED DOCKER_TAG SET DOCKER_TAG=latest + + IF NOT DEFINED CONTAINER_USER SET CONTAINER_USER=1000 + IF NOT DEFINED CONTAINER_GROUP SET CONTAINER_GROUP=1000 + + IF NOT DEFINED CONTAINER_NAME SET CONTAINER_NAME=analog-tools + + IF NOT DEFINED JUPYTER_PORT SET JUPYTER_PORT=8888 + IF NOT DEFINED VNC_PORT SET VNC_PORT=8444 + + :: Get parameters from wsl + :::::::::::::::::::::::::: + SET WSL_GET_DISPLAY=wsl --exec bash --norc -c "echo $DISPLAY" + FOR /F "USEBACKQ" %%i IN (`%WSL_GET_DISPLAY%`) DO ( SET "DISPLAY=%%i" ) + + SET WSL_GET_WAYLAND_DISPLAY=wsl --exec bash --norc -c "echo $WAYLAND_DISPLAY" + FOR /F "USEBACKQ" %%i IN (`%WSL_GET_WAYLAND_DISPLAY%`) DO ( SET "WAYLAND_DISPLAY=%%i" ) + + :: Validate parameters + :::::::::::::::::::::: + IF %CONTAINER_USER% NEQ 0 IF %CONTAINER_USER% LSS 1000 ( + echo WARNING: Selected User ID %CONTAINER_USER% is below 1000. This ID might interfere with User-IDs inside the container and cause undefined behaviour! + ) + IF %CONTAINER_GROUP% NEQ 0 IF %CONTAINER_GROUP% LSS 1000 ( + echo WARNING: Selected Group ID %CONTAINER_GROUP% is below 1000. This ID might interfere with Group-IDs inside the container and cause undefined behaviour! + ) + + :: Attach to existing container + ::::::::::::::::::::::::::::::: + docker container inspect %CONTAINER_NAME% 2>&1 | find "Status" | find /i "running" + IF NOT ERRORLEVEL 1 ( + ECHO Container %CONTAINER_NAME% is running! + ECHO Stop with "docker stop %CONTAINER_NAME%" + ECHO Remove with "docker rm %CONTAINER_NAME%" if required. + GOTO attach_shell + ) + docker container inspect %CONTAINER_NAME% 2>&1 | find "Status" | find /i "exited" + IF NOT ERRORLEVEL 1 ( + ECHO Container %CONTAINER_NAME% exists. + ECHO Restart with "docker start %CONTAINER_NAME%" + ECHO Or remove with "docker rm %CONTAINER_NAME%" if required. + GOTO restart_shell + ) + + :: Set environment, variables and run the container + :::::::::::::::::::::::::::::::::::::::::::::::::::: + echo Check requirements + %CALL% wsl --install Ubuntu --no-launch + %CALL% wsl --update + + echo Container does not exist, creating %CONTAINER_NAME% ... + + SET PARAMS=-d + @REM SET PARAMS=%PARAMS% --user %CONTAINER_USER%:%CONTAINER_GROUP% + SET PARAMS=%PARAMS% --name %CONTAINER_NAME% + @REM SET PARAMS=%PARAMS% --security-opt seccomp=unconfined + SET PARAMS=%PARAMS% -p %JUPYTER_PORT%:8888 + SET PARAMS=%PARAMS% -p %VNC_PORT%:8444 + SET PARAMS=%PARAMS% -v "%DESIGNS%":/home/designer/shared + SET PARAMS=%PARAMS% -v \\wsl.localhost\Ubuntu\mnt\wslg:/tmp + SET PARAMS=%PARAMS% -e DISPLAY=%DISPLAY% + SET PARAMS=%PARAMS% -e WAYLAND_DISPLAY=%WAYLAND_DISPLAY% + SET PARAMS=%PARAMS% -e XDG_RUNTIME_DIR=/mnt/wslg + SET PARAMS=%PARAMS% -e PDK=%PDK% + + IF NOT DEFINED IMAGE ( + SET IMAGE=%DOCKER_USER%/%DOCKER_IMAGE% + IF DEFINED DOCKER_TAG SET IMAGE=%IMAGE%:%DOCKER_TAG% + ) + + @REM SET COMMAND=jupyter-lab --no-browser + @REM SET COMMAND=sudo vncserver -select-de xfce + @REM SET COMMAND=sleep infinity + @REM SET COMMAND=bash + + @echo on + %CALL% docker run %PARAMS% %IMAGE% %COMMAND% + @echo off + + GOTO attach_shell + + +:attach_shell + %CALL% docker exec -it %CONTAINER_NAME% bash + GOTO end + + +:restart_shell + %CALL% docker start %CONTAINER_NAME% + GOTO attach_shell + + +:end + endlocal + + +:normalizepath + SET DESIGNS=%~f1 + EXIT /B + + +:: Get DISPLAY from WSL +::wsl --exec bash --norc -c 'echo $DISPLAY' + +:: Get current path of batsh script +::SET BATCH_PATH=%~dpnx0 \ No newline at end of file