Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
change docker image build path (#51)
Browse files Browse the repository at this point in the history
* change docker image build path

* document image build path param

* align the Dockerfile creation task

* prefer ephemeral directory to build unless specified otherwise

* add a cleanup playbook for custom build context

* fix tests issues
  • Loading branch information
alxgomz authored May 16, 2021
1 parent 8690b73 commit abe5e0f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions molecule_docker/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Docker(Driver):
image: image_name:tag
dockerfile: Dockerfile.j2
pull: True|False
path: /path/to_docker/build/context
pre_build_image: True|False
registry:
url: registry.example.com
Expand Down
16 changes: 16 additions & 0 deletions molecule_docker/playbooks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Cleanup
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
vars:
molecule_labels:
owner: molecule
tasks:
- name: Cleanup Dockerfiles
file:
state: absent
path: "{{ item.path }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
when: item.path is defined
loop: "{{ molecule_yml.platforms }}"
12 changes: 10 additions & 2 deletions molecule_docker/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@
{%- else -%}
{{ playbook_dir + '/Dockerfile.j2' }}
{%- endif -%}
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
dest: "{{ item.path | default(molecule_ephemeral_directory) }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
mode: "0600"
loop: "{{ molecule_yml.platforms }}"
loop_control:
index_var: i
when: not item.pre_build_image | default(false)
register: platforms

- name: Copy files for image building
copy:
src: "{{ molecule_scenario_directory }}/"
dest: "{{ molecule_ephemeral_directory }}"
mode: "0600"
when: not item.pre_build_image | default(false) and not item.path
loop: "{{ molecule_yml.platforms }}"

- name: Discover local Docker images
docker_image_info:
name: "molecule_local/{{ item.item.name }}"
Expand All @@ -67,7 +75,7 @@
- not item.item.pre_build_image | default(false)
docker_image:
build:
path: "{{ molecule_ephemeral_directory }}"
path: "{{ item.item.path | default(molecule_ephemeral_directory) }}"
dockerfile: "{{ item.invocation.module_args.dest }}"
pull: "{{ item.item.pull | default(true) }}"
network: "{{ item.item.network_mode | default(omit) }}"
Expand Down

0 comments on commit abe5e0f

Please sign in to comment.