Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to run command(s) at container startup #221

Open
FFY00 opened this issue Mar 25, 2020 · 9 comments
Open

Add option to run command(s) at container startup #221

FFY00 opened this issue Mar 25, 2020 · 9 comments
Labels
documentation enhancement New feature or request

Comments

@FFY00
Copy link

FFY00 commented Mar 25, 2020

It would be great if we had a way to run a command at container startup. This could be used to for example update the system and install python, giving a workaround to #49.

@TomasTomecek
Copy link
Collaborator

Does raw module help with this?

@TomasTomecek TomasTomecek added the enhancement New feature or request label Mar 25, 2020
@FFY00
Copy link
Author

FFY00 commented Mar 25, 2020

No, because we need to run the command before checking if python is installed on the container.

@FFY00
Copy link
Author

FFY00 commented Apr 11, 2020

Friendly ping

Right now I am not able to create containers based on https://hub.docker.com/_/archlinux/ because it does not contain python. I would have to maintain a separate container for this, which is not great.

@TomasTomecek
Copy link
Collaborator

Friendly ping

Right now I am not able to create containers based on https://hub.docker.com/_/archlinux/ because it does not contain python. I would have to maintain a separate container for this, which is not great.

Hey, sadly I don't have time to work on bender lately, as you can clearly see. If you need this feature, you'd need to implement it yourself.

@FFY00
Copy link
Author

FFY00 commented Apr 20, 2020

Yes, I would be happy to look into it if you gave me some pointers.

@TomasTomecek
Copy link
Collaborator

So no code changes are really needed, I figured it out:

$ cat p.yaml
---
- hosts: all
  gather_facts: false
  tasks:
  - raw: pacman -Sy --noconfirm python3
  - command: python3 --version

gather_facts: false is important so that ansible won't try checking for python

you also need to tell bender where the python interpreter will be:

$ ansible-bender build --python-interpreter /usr/bin/python3.8 ./p.yaml archlinux asd

PLAY [asd-20200420-093410492979-cont] ********************************************************************************

TASK [raw] ***********************************************************************************************************
changed: [asd-20200420-093410492979-cont]

TASK [command] *******************************************************************************************************
changed: [asd-20200420-093410492979-cont]

PLAY RECAP ***********************************************************************************************************
asd-20200420-093410492979-cont : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Getting image source signatures
Copying blob sha256:97747b30defb13b27bf3be7e760d2aaa23b9c7443e6fe5de6e8ba07849a3cbcb
Copying blob sha256:fcbcfd1672a64f1f91bbfba6aaa1963fcdbcd7ec43ec21de0d6fcdf316d3a6cb
Copying blob sha256:318afdf782ebe7a6c85a922c924184e938e9fee1f64c0f5b6a8d22508de05699
Copying blob sha256:9e47f42d84b81c7b0c0815fa596b1f12f5075e713496796e1258aee2b737f58e
Copying blob sha256:c41b760cac32219ca8eb2617a8b28192413c50eaf73fc4591333a919a7989521
Copying blob sha256:2bd7c539eb799cc13d2700e6a8581e64dd46a3f25c27d5150ef9b89a7ecee5c7
Copying config sha256:d5eb846a7f8de68107acdcf0e9b0ea497911ecffbae4e5a8341c2f2cbbc58f59
Writing manifest to image destination
Storing signatures
d5eb846a7f8de68107acdcf0e9b0ea497911ecffbae4e5a8341c2f2cbbc58f59
Image 'asd' was built successfully \o/

@FFY00
Copy link
Author

FFY00 commented Apr 20, 2020

Oh, great! Thanks.

By the way, partial upgrades in Arch Linux are not supported, so you should do pacman -Sy --noconfirm python3 😄.

@TomasTomecek
Copy link
Collaborator

By the way, partial upgrades in Arch Linux are not supported, so you should do pacman -Sy --noconfirm python3 smile.

This was the first time I was using arch. Also can't see any difference between the command in my example.

@FFY00
Copy link
Author

FFY00 commented Apr 20, 2020

Sorry, typo.

pacman -Syu --noconfirm python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants