0

我有一个molecule.yml看起来有点像这样的:

dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: testohpc-compute-0
    image: docker.io/pycontribs/centos:7
    pre_build_image: true
    groups:
      - testohpc_compute
    command: /sbin/init
    tmpfs:
      - /run
      - /tmp
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - name: net1

我如何定义另一个实例,说testohpc-compute-2除了名称之外它完全相同?我真的需要再次复制所有定义-1吗?

此外,如果有重用实例定义的方法,我可以在场景之间共享它吗?

4

2 回答 2

1

您可以利用 yaml 锚点和合并关键功能。您可以在 Y 分钟内找到有关 Learn yaml 的基本解释。

在您的具体情况下,这是一个可能的解决方案。

platforms:
  - &default_platform
    name: testohpc-compute-0
    image: docker.io/pycontribs/centos:7
    pre_build_image: true
    groups:
      - testohpc_compute
    command: /sbin/init
    tmpfs:
      - /run
      - /tmp
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - name: net1
  - <<: *default_platform
    name: testohpc-compute-2

注意:锚点和合并键只能在同一个 yaml 文件中使用。所以这在不同的场景之间不起作用。

于 2020-07-08T12:51:48.427 回答
0

如果你真的想要完全相同的配置testohpc-compute-2,你可以使用环境变量:

dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: testohpc-compute-${NUMBER:-0}
    image: docker.io/pycontribs/centos:7
    pre_build_image: true
    groups:
      - testohpc_compute
    command: /sbin/init
    tmpfs:
      - /run
      - /tmp
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - name: net1

然后执行两个实例:

~|⇒  mol test
# Executes instance testohpc-compute-0
~|⇒  NUMBER=2 mol test
# Executes instance testohpc-compute-2
于 2020-11-16T09:15:21.267 回答