Develop on containers#
本指南描述如何使用 remote container(远程容器) 或 Codespaces 开发 PyMAPDL 功能或修复 bug。 用于设置容器的文件可在 .devcontainer directory 中找到。
About the MAPDL container#
由于 MAPDL 软件不是开源的,因此 GPL 许可证不允许向用户分发 docker 容器。 要使用本节提到的任何一种开发方法,都必须有一个安装了 MAPDL 的 docker 容器。 如果你想构建自己的 docker 镜像,请访问以下链接 创建自己的 MAPDL docker 容器。
License#
As mentioned before, you must have a valid license to run MAPDL.
When you launch the container, the file script.sh
automatically
checks if the environment variable 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.
You can set the ANSYSLMD_LICENSE_FILE
environment variable
from the terminal before launching VS Code.
For example, if you have a license server at the address 123.45.67.89
,
you can set the license on Windows using:
$env:ANSYSLMD_LICENSE_FILE = '1055@123.45.65.89'
code . # launch VS Code
On Linux
$ 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.
Develop on a remote container#
Note
This approach requires you have a Docker image with MAPDL installed. The Docker image listed in the repository development container configuration files is not for public use due to licensing issues. However, you can create your own Docker image <ref_make_container_> and use this file as a template for setting your own local development container.
To use a remote container, you must install this software:
Docker software or equivalent. To run Linux Docker containers, you should use the Windows Subsystem Linux (WSL) backend. For more information, see Developing inside a Container - Getting started.
As mentioned before, you must have your own Docker image with MAPDL installed
locally available or hosted in an online registry, such as GitHub ghcr.io.
For the purpose of this document, assume your image is hosted at
ghcr.io/myaccount/mapdlimage:mytag
.
You must then modify the docker-compose.yml file with your custom image:
ports:
- '50052:50052'
- '50055:50055'
image: 'ghcr.io/myaccount/mapdlimage:mytag'
user: "0:0"
Warning
You might also need to change some environment variables or Docker
options to adjust to your image configuration.
For example, you might need to change the AWP_ROOT222
environment
variable if your MAPDL container does not have the installation in the default directory.
Be careful that you do not commit those changes in your PRs.
You can now open the current folder (or PyMAPDL repository) using
ctr/cmd + shift + p to open the Visual Studio Code Command palette.
Then select Dev Containers: Open Folder in Container.
When you are prompted to select one of the multiple devcontainer configurations,
select PyMAPDL-DevContainer (Local).
Because the configuration is available in the .devcontainer/devcontainer-local
directory,
Visual Studio Code automatically launches the MAPDL container with the desired configuration.
Note
The first time that you launch the devcontainer, it might take a long time before it is ready, This is because the container image must be pulled from the registry.
You can now work normally, but you would be, in fact, working from inside the container. Because Visual Studio Code mount the local directory into the Docker container, you don’t lose your changes if you accidentally delete your container. However, this mounting process might have a significant impact on the container performance, especially noticeable if you are using MacOS. You can avoid this by cloning the repository inside the container. For more information, see Quick start: Open a Git repository or GitHub PR in an isolated container volume.