ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 392 forks source link

import from Dockerfile does not handle multiline ADD correctly #836

Open dchsueh opened 6 years ago

dchsueh commented 6 years ago
ISSUE TYPE
container.yml

not applicable

OS / ENVIRONMENT
$ ansible-container --debug version
Ansible Container, version 0.9.3rc0
Linux, ubuntu, 4.4.0-101-generic, #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017, x86_64
2.7.12 (default, Nov 20 2017, 18:23:56) 
[GCC 5.4.0 20160609] /home/ubuntu/ansible-container/bin/python2

using virtualenv, ansible-container installed from github repo checkout from 2017-12-13 also confirmed with current pip-installed ansible-container version (0.9.2?)

SUMMARY

importing a docker context dir with Dockerfile containing multiline ADD command, e.g.

FROM centos:7

RUN yum update -y \
  && yum install -y wget unzip \
  && yum clean all

results in a \<currentdir>/roles/\<docker-context-dir>/tasks/main.yml containing:

- shell: yum update -y
- shell: '&& yum install -y wget unzip'
- shell: '&& yum clean all'
STEPS TO REPRODUCE

as per summary above

EXPECTED RESULTS

a correct shell task, either concatenated into one line, or a single multiline shell task

ACTUAL RESULTS

resulting .../roles/.../tasks/main.yml shown in summary above the import will succeed but the yml needs editing in order to run

j00bar commented 6 years ago

Interesting - never seen:

/bin/foo \
&& /bin/bar

Is this, in your experience, a common pattern? We've always seen:

/bin/foo && \
/bin/bar
dchsueh commented 6 years ago

I don't think there is any pattern or requirement that individual run commands be on a line, or the && token be at the beginning or at the end. For example, see https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#run "Below is a well-formed RUN instruction..." where the first cmd is part of the first line, the second command starts on the first line and runs for another n-2, and the last command is on its own line with && in front.

The backslashed-newline just means "not done yet". For ansible-container import, maybe everything can just be dumped into one shell call with backslash-newline removed and everything concatenated.