ansible-community / ansible-bender

ansible-playbook + buildah = a sweet container image
https://ansible-community.github.io/ansible-bender/build/html/
MIT License
678 stars 74 forks source link

podman entrypoint for working container #258

Open neldridge opened 3 years ago

neldridge commented 3 years ago

Hi, I've been doing some testing with bender to replace our AMIs with Docker containers.

One of the things I'm trying to accomplish is setting up our Ubuntu-based Jenkins agents in Docker through ECS+Fargate.

My pipeline is: base -> jenkins-base jenkins-base -> infrastructure jenkins-base -> java jenkins-base -> etc.

During my jenkins-base creation, I set the target_image entrypoint to /usr/local/bin/jenkins-agent - which is required behavior for ECS as it passes a command expecting it to be an argument to that shell script.

Unfortunately, this means in my infrastructure/java/etc. images- the ansible-bender build fails, "can't find python".

The only way I can figure out how to get around this is to not set the entrypoint in my jenkins-base and set it in the downstream containers- which isn't ideal.

Am I missing another way?

Logs here:

root@ip:/home/ubuntu/ansible# time ansible-bender -vvv build test-infrastructure-linux.yml
19:58:00.085 utils.py          INFO   running command: "['ansible-playbook', '--version']"
19:58:00.431 utils.py          INFO   running command: "['ansible-playbook', '-c', 'local', '-i', '/tmp/abauyyxs3i/i', '-e', 'ansible_python_interpreter=/usr/bin/python3', '.test-infrastructure-linux-20210720195800085112-odiwaowrjg.yaml']"
19:58:01.490 utils.py          INFO   running command: "['podman', 'version']"
19:58:01.615 utils.py          INFO   running command: "['buildah', 'version']"
19:58:01.677 utils.py          INFO   running command: "['buildah', 'from', '--name', ' artifactory-devops-infrastructure-linux-0-0-1-20210720-195801462893-cont-20210720195801677290', 'artifactory.internal/company/jenkins-base:18.04']"
19:58:01.871 utils.py          INFO   running command: "['buildah', 'run', ' artifactory-devops-infrastructure-linux-0-0-1-20210720-195801462893-cont-20210720195801677290', 'true']"
19:58:02.425 utils.py          INFO   running command: "['buildah', 'rm', ' artifactory-devops-infrastructure-linux-0-0-1-20210720-195801462893-cont-20210720195801677290']"
19:58:02.522 utils.py          INFO   running command: "['buildah', 'inspect', '-t', 'image', 'artifactory.internal/company/jenkins-base:18.04']"
19:58:02.607 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'true']"
19:58:03.179 utils.py          INFO   running command: "['buildah', 'inspect', '-t', 'image', 'artifactory.internal/company/jenkins-base:18.04']"
19:58:03.307 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python3']"
19:58:03.891 buildah_builder.py INFO   python interpreter /usr/bin/python3 does not exist
19:58:03.892 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/local/bin/python3']"
19:58:04.543 buildah_builder.py INFO   python interpreter /usr/local/bin/python3 does not exist
19:58:04.544 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python3.7']"
19:58:05.131 buildah_builder.py INFO   python interpreter /usr/bin/python3.7 does not exist
19:58:05.132 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python37']"
19:58:05.767 buildah_builder.py INFO   python interpreter /usr/bin/python37 does not exist
19:58:05.768 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python3.6']"
19:58:06.383 buildah_builder.py INFO   python interpreter /usr/bin/python3.6 does not exist
19:58:06.383 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python36']"
19:58:06.967 buildah_builder.py INFO   python interpreter /usr/bin/python36 does not exist
19:58:06.968 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python2']"
19:58:07.555 buildah_builder.py INFO   python interpreter /usr/bin/python2 does not exist
19:58:07.556 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/local/bin/python2']"
19:58:08.139 buildah_builder.py INFO   python interpreter /usr/local/bin/python2 does not exist
19:58:08.140 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/bin/python']"
19:58:08.767 buildah_builder.py INFO   python interpreter /usr/bin/python does not exist
19:58:08.768 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/local/bin/python']"
19:58:09.335 buildah_builder.py INFO   python interpreter /usr/local/bin/python does not exist
19:58:09.335 utils.py          INFO   running command: "['podman', 'run', '--rm', 'artifactory.internal/company/jenkins-base:18.04', 'ls', '/usr/libexec/platform-python']"
19:58:09.939 buildah_builder.py INFO   python interpreter /usr/libexec/platform-python does not exist
19:58:09.940 buildah_builder.py ERROR  couldn't locate python interpreter, tried these paths: ('/usr/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3.7', '/usr/bin/python37', '/usr/bin/python3.6', '/usr/bin/python36', '/usr/bin/python2', '/usr/local/bin/python2', '/usr/bin/python', '/usr/local/bin/python', '/usr/libexec/platform-python')
There was an error during execution: no python interpreter was found in the base image "artifactory.internal/company/jenkins-base:18.04", you can specify the path via CLI option --python-interpreter

real    0m10.093s
user    0m5.945s
sys     0m1.736s
root@ip:/home/ubuntu/ansible# podman run -it --rm --entrypoint python3 artifactory.internal/company/jenkins-base:18.04 --version
Python 3.6.9
TomasTomecek commented 3 years ago

Hello! I can see three options here:

  1. Do what you suggest and change the entrypoint later (easy)

  2. Invoke bender build with --entrypoint and override the value from the playbook vars (easy-ish, should work)

  3. Change bender so it's able to work with images which don't use shell-like entrypoint (no changes on your side, though we'd need to fix bender)

Not sure if this is a change podman did recently because I don't recall this behaviour wrt entrypoint.

I could have some bandwidth this week to implement 3) though can't promise it.

neldridge commented 3 years ago

Yea I'll go through with 1 for now; I dug through the code for running commands but I'm not confident in creating a useful PR with my schedule at the moment. I may try to jump in next week when I have more time if you haven't gotten to it by then.

No worries on timing man, appreciate the work you've done so far. I was mostly checking to see if I was missing something that I didn't understand.

TomasTomecek commented 3 years ago

Sadly my extra time got absorbed by the sickness from the second covid dose :/ it would take me weeks to get to this because of my current plans.

Let me know if you need any further help and I'll try to assist as soon as I find time.

Obviously, long term, we should do 3) and actually fix this in bender, so I'm glad we have a solid workaround in the meantime.