45 lines
1.4 KiB
YAML
45 lines
1.4 KiB
YAML
- import_tasks: precheck.yml
|
|
tags:
|
|
- always
|
|
|
|
- name: Ensure that modify_dir_path is defined
|
|
assert:
|
|
that:
|
|
- modify_dir_path is defined
|
|
- modify_dir_path | length > 0
|
|
|
|
- name: Set default modified_append_tag
|
|
set_fact:
|
|
modified_append_tag: "{{ lookup('pipe','date +-modified-%Y%m%d%H%M%S') }}"
|
|
when: modified_append_tag is undefined
|
|
|
|
- name: Create Dockerfile tempfile name
|
|
tempfile:
|
|
path: "{{ modify_dir_path }}"
|
|
prefix: Dockerfile.
|
|
register: dockerfile
|
|
|
|
- name: Copy Dockerfile to {{ dockerfile.path }}
|
|
copy:
|
|
src: "{{ modify_dir_path }}/Dockerfile"
|
|
dest: "{{ dockerfile.path }}"
|
|
|
|
- name: Replace FROM directive
|
|
lineinfile:
|
|
path: "{{ dockerfile.path }}"
|
|
regexp: "^FROM "
|
|
line: "FROM {{ source_image }}"
|
|
|
|
- name: Add LABEL modified_append_tag={{ modified_append_tag }}
|
|
lineinfile:
|
|
path: "{{ dockerfile.path }}"
|
|
insertafter: "^FROM "
|
|
line: "LABEL modified_append_tag={{ modified_append_tag }}"
|
|
|
|
- name: Modify image from {{ modify_dir_path }}
|
|
command: "{{ build_commands[container_build_tool] }} --tag {{ target_image | default(source_image) }}{{ modified_append_tag }} --file {{ dockerfile.path }} --network host ./"
|
|
#FIXME: buildah should not required root commands to build an image
|
|
become: "{{ true if build_commands[container_build_tool] == 'buildah' else false }}"
|
|
args:
|
|
chdir: "{{ modify_dir_path }}"
|