From ad9eed99c81eef44aa9d40ed9e2cf34bad253701 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 25 Jul 2023 15:23:09 +0200 Subject: [PATCH] Small improvements on the dev containers (#2208) * Documenting better the scrip and docs. Updating always the bashrc file * Reworking a bit the docs --- .devcontainer/README.rst | 26 +++++++++----- .devcontainer/devcontainer.json | 15 +++----- .devcontainer/docker-compose.yml | 61 +++++++++++++------------------- .devcontainer/script.sh | 7 ++++ 4 files changed, 52 insertions(+), 57 deletions(-) diff --git a/.devcontainer/README.rst b/.devcontainer/README.rst index 9f2e679874..882cee51c2 100644 --- a/.devcontainer/README.rst +++ b/.devcontainer/README.rst @@ -50,10 +50,10 @@ with your custom image: - '50055:50055' image: 'ghcr.io/myaccount/mapdlimage:mytag' user: "0:0" - volumes: .. warning:: Also you might need to change some environment variables or Docker options to adjust to your image configuration. + For example you might need to change the :envvar:`AWP_ROOT222` if you MAPDL container does not have the installation in the default directory. Be careful to not commit those changes in your PRs. You can now open the current folder (or PyMAPDL repository) using @@ -76,22 +76,30 @@ License ------- As mentioned before, you must have a valid license to run MAPDL. -When you launch the container, the file :file:`script.sh` automatically checks if the environment -variable :envvar:`ANSYSLMD_LICENSE_FILE` exists. +When you launch the container, the file :file:`script.sh` automatically +checks if the environment variable :envvar:`ANSYSLMD_LICENSE_FILE` exists. This environment variable sets the port and IP address of the license server. +If you do not have set this environment variable before launching the +container, you are prompt to enter your license server port and address. -If you do not have set this environment variable before launching the container, you are prompt to enter -your license server port and address. - -You can set your license using the environment variable :envvar:`ANSYSLMD_LICENSE_FILE` from the terminal before launching -VS Code. This is recommended if you are using Windows OS. -For example, if you have a license server at the address ``123.45.67.89``, you can set the license using: +You can set the environment variable :envvar:`ANSYSLMD_LICENSE_FILE` +from the terminal before launching VS Code. +This is recommended if you are using Windows OS. +For example, if you have a license server at the address ``123.45.67.89``, +you can set the license using: .. code:: pwsh-session $env:ANSYSLMD_LICENSE_FILE = '1055@123.45.65.89' code . # launch VS Code +On Linux + +.. code:: bash + + $ export ANSYSLMD_LICENSE_FILE =1055@123.45.65.89 + code . # launch VS Code + And then open the folder in the container using the *Command palette*. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 52c01e0687..0d792414d0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,7 +22,7 @@ // Uncomment the next line if you want to keep your containers running after VS Code shuts down. // "shutdownAction": "none", // Uncomment the next line to run commands after the container is created - for example installing curl. - "postCreateCommand": "/bin/bash ./.devcontainer/script.sh", //"'pkill -9 -f ansys_inc/v222/ansys'", + "postCreateCommand": "/bin/bash ./.devcontainer/script.sh", // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "root", @@ -35,20 +35,13 @@ ] }, "vscode": { + "openFiles": [ + ".devcontainer/README.rst" + ], "extensions": [ - "hbenl.vscode-test-explorer", - "LittleFoxTeam.vscode-python-test-adapter", "ms-azuretools.vscode-docker", "ms-python.python", - "ms-vscode-remote.remote-containers", - "ms-vscode-remote.remote-ssh-edit", - "ms-vscode-remote.remote-ssh", - "ms-vscode-remote.remote-wsl", "ms-vscode-remote.vscode-remote-extensionpack", - "ms-vscode.remote-explorer", - "njpwerner.autodocstring", - "VisualStudioExptTeam.vscodeintellicode", - "yzhang.markdown-all-in-one", ] } } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 0d3b31fe53..bac3a5e98c 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,51 +1,38 @@ +# Requirements +# ------------ +# +# You should have a valid `ANSYSLMD_LICENSE_FILE` env var. For example: +# +# $ ANSYSLMD_LICENSE_FILE=1055@myserver +# +# This env var will be copied to the container `.bashrc` file so it will +# be available in the future runs. +# If you do not have a valid env var when starting the container, you will +# be prompted through the terminal to input a valid port and IP for the +# license server. + version: '3.3' services: - # Update this to the name of the service you want to work with in your docker-compose.yml file mapdldev: - # If you want add a non-root user to your Dockerfile, you can use the "remoteUser" - # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks, - # debugging) to execute as the user. Uncomment the next line if you want the entire - # container to run as this user instead. Note that, on Linux, you may need to - # ensure the UID and GID of the container user you create matches your local user. - # See https://aka.ms/vscode-remote/containers/non-root for details. - # - # user: vscode - - # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer - # folder. Note that the path of the Dockerfile and context is relative to the *primary* - # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" - # array). The sample below assumes your primary file is in the root of your project. - # - # build: - # context: . - # dockerfile: .devcontainer/Dockerfile restart: always - shm_size: '8gb' + shm_size: '8gb' # Increase the shared memory directory + # to avoid running issues. By Default this is very small (64MB) container_name: mapdldev mem_reservation: 8g environment: - - ANSYS_LOCK=OFF - - AWP_ROOT222=/ansys_inc - - ANSYSLMD_LICENSE_FILE=${ANSYSLMD_LICENSE_FILE} - - PYANSYS_OFF_SCREEN=true + - ANSYS_LOCK=OFF # Avoid lock file creation. + - AWP_ROOT222=/ansys_inc # Specifying the installation directory + - ANSYSLMD_LICENSE_FILE=${ANSYSLMD_LICENSE_FILE} # License server env var + - PYANSYS_OFF_SCREEN=true # To avoid plotting. ports: - - '50052:50052' - - '50055:50055' - image: 'ghcr.io/pyansys/mapdl:v22.2-ubuntu' + - '50052:50052' # For the gRPC server + - '50055:50055' # For the DB server + image: 'ghcr.io/ansys/mapdl:v22.2-ubuntu' user: "0:0" volumes: - # Update this to wherever you want VS Code to mount the folder of your project + # Update this to wherever you want VS Code to mount the folder of your project inside the container. - ../:/local:cached - # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. - # - /var/run/docker.sock:/var/run/docker.sock - - # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. - # cap_add: - # - SYS_PTRACE - # security_opt: - # - seccomp:unconfined - # Overrides default command so things don't shut down after the process ends. - entrypoint: /bin/bash -c "echo 'Container is ready. You can now attach to it.'; while sleep 10000; do :; done" + entrypoint: /bin/bash -c "echo 'Container is ready. You can now attach to it at the port 50052'; while sleep 10000; do :; done" diff --git a/.devcontainer/script.sh b/.devcontainer/script.sh index 93bb06d58c..9af0039001 100644 --- a/.devcontainer/script.sh +++ b/.devcontainer/script.sh @@ -24,4 +24,11 @@ if [[ -z "${ANSYSLMD_LICENSE_FILE}" ]]; then else echo "ANSYSLMD_LICENSE_FILE was found." echo "It is defined as ${ANSYSLMD_LICENSE_FILE}" + + # Storing env var in .bashrc file so it is automatically loaded. + printf "\n%s\n" "ANSYSLMD_LICENSE_FILE=${ANSYSLMD_LICENSE_FILE}" >> ~/.bashrc + + # Activating the new configuration + source ~/.bashrc + fi