将任意文件复制到 EE

Ansible Builder 版本 3 模式提供了将文件复制到 EE 镜像的选项。有关更多详细信息,请参阅版本 3 模式

在下面的示例中,我们将了解如何将任意文件复制到执行环境。

---
version: 3

images:
  base_image:
    name: quay.io/centos/centos:stream9  # vanilla image

dependencies:
  # Use Python 3.9
  python_interpreter:
    package_system: python39
    python_path: /usr/bin/python3.9
  # Collections to be installed
  galaxy:
    collections:
      - ansible.utils

additional_build_files:
  # copy arbitrary files next to this EE def into the build context - we can refer to them later...
  - src: files/rootCA.crt
    dest: configs

additional_build_steps:
  prepend_base:
    # copy a custom CA cert into the base image and recompute the trust database
    # because this is in "base", all stages will inherit (including the final EE)
    - COPY _build/configs/rootCA.crt /usr/share/pki/ca-trust-source/anchors
    - RUN update-ca-trust

在此示例中,additional_build_files 部分允许您将 rootCA.crt 添加到构建上下文目录。将此文件复制到构建上下文目录后,即可在构建过程中使用它。为了使用该文件,我们需要使用 additional_build_steps 部分的 prepend_base 步骤中指定的 COPY 指令将其从构建上下文目录复制。

最后,您可以根据复制的文件执行任何操作,例如在此示例中通过运行 RUN update-ca-trust 更新 CA 证书的动态配置。

另请参阅

执行环境定义版本 3

有关 EE 定义版本 3 的详细文档