3.9. 추가적인 사용자 지정 빌드 단계
정의 파일의 additional_build_steps
섹션에서 모든 빌드 단계에 대한 사용자 정의 빌드 명령을 지정할 수 있습니다. 이를 통해 빌드 단계를 세부적으로 제어할 수 있습니다.
prepend_
및 append_
명령을 사용하여 기본 빌드 단계가 실행되기 전이나 후에 실행되는 Containerfile
에 지시문을 추가합니다. 명령은 런타임 시스템에 필요한 모든 규칙을 준수해야 합니다.
additional_build_steps
에서 사용할 수 있는 값 목록은 다음 표를 참조하십시오.
현재의 | 설명 |
---|---|
| 기본 이미지를 빌드하기 전에 명령을 삽입할 수 있습니다. |
| 기본 이미지를 빌드한 후 명령을 삽입할 수 있습니다. |
| Galaxy 이미지를 빌드하기 전에 삽입할 수 있습니다. |
| Galaxy 이미지를 빌드한 후 삽입할 수 있습니다. |
| Python 빌더 이미지를 빌드하기 전에 명령을 삽입할 수 있습니다. |
| Python 빌더 이미지를 빌드한 후 명령을 삽입할 수 있습니다. |
| 최종 이미지를 빌드하기 전에 삽입할 수 있습니다. |
| 최종 이미지를 빌드한 후 삽입할 수 있습니다. |
additional_build_steps
구문은 여러 줄 문자열과 목록을 모두 지원합니다. 다음 예제를 참조하십시오.
예 3.1. 여러 줄 문자열 항목
prepend_final: | RUN whoami RUN cat /etc/os-release
prepend_final: |
RUN whoami
RUN cat /etc/os-release
예 3.2. 목록 항목
append_final: - RUN echo This is a post-install command! - RUN ls -la /etc
append_final:
- RUN echo This is a post-install command!
- RUN ls -la /etc
예 3.3. 임의의 파일을 실행 환경에 복사
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:
# 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.9.1. 환경 변수를 사용하여 실행 환경 빌드
다음 예제 파일은 빌드 프로세스에 필요할 수 있는 환경 변수를 지정합니다.
이 기능을 수행하기 위해 additional_build_steps 섹션의 prepend_base
단계에서 ENV
변수 정의를 사용합니다.
— additional_build_steps: prepend_base: - ENV FOO=bar - RUN echo $FOO > /tmp/file1.txt
—
additional_build_steps:
prepend_base:
- ENV FOO=bar
- RUN echo $FOO > /tmp/file1.txt
동일한 환경 변수는 빌드 프로세스의 이후 단계에서 사용할 수 있습니다.
3.9.2. Galaxy 구성에 대한 환경 변수를 사용하여 실행 환경 빌드
Ansible Builder 스키마 3을 사용하면 사용자 지정 Galaxy 구성 지정과 같은 복잡한 시나리오를 수행할 수 있습니다. 이 방법을 사용하여 인증 토큰과 같은 중요한 정보를 최종 실행 환경 이미지로 유출하지 않고 실행 환경 빌드에 전달할 수 있습니다.
다음 예제에서는 Ansible Galaxy Server 환경 변수를 사용합니다.
additional_build_steps: prepend_galaxy: # Environment variables used for Galaxy client configurations - ENV ANSIBLE_GALAXY_SERVER_LIST=automation_hub - ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL=https://console.redhat.com/api/automation-hub/content/xxxxxxx-synclist/ - ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token # define a custom build arg env passthru - we still also have to pass # `--build-arg ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN` to get it to pick it up from the env - ARG ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN options: package_manager_path: /usr/bin/microdnf # downstream images use non-standard package manager
additional_build_steps:
prepend_galaxy:
# Environment variables used for Galaxy client configurations
- ENV ANSIBLE_GALAXY_SERVER_LIST=automation_hub
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL=https://console.redhat.com/api/automation-hub/content/xxxxxxx-synclist/
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
# define a custom build arg env passthru - we still also have to pass
# `--build-arg ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN` to get it to pick it up from the env
- ARG ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN
options:
package_manager_path: /usr/bin/microdnf # downstream images use non-standard package manager
ENV
지시문을 사용하여 ANSIBLE_GALAXY_SERVER_LIST
,ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL
및 ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL
과 같은 환경 변수를 제공할 수 있습니다. 자세한 내용은 Ansible 문서의 Galaxy 사용자 가이드를 참조하십시오.
보안상의 이유로 중요한 정보를 ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN
에 저장해서는 안 됩니다. ARG 지시문을 사용하여 사용자의 민감한 정보를 입력으로 수신할 수 있습니다.
-build-args
는 ansible-builder 명령을 호출하는 동안 이 정보를 제공하는 데 사용할 수 있습니다.