willhallonline / docker-ansible

Ansible inside Docker containers: Alpine, Ubuntu, Rocky & Debian with Ansible 2.16, 2.15, 2.14, 2.13, 2.12, 2.11, 2.10 and 2.9 + Mitogen
https://www.willhallonline.co.uk/project/docker/docker-ansible/
MIT License
376 stars 135 forks source link

python 2.7 reaches End of Life in 2 months #13

Closed seanw2020 closed 4 years ago

seanw2020 commented 4 years ago

First, thank you for this image! Second, could you update it, or create a new tag, for a python3 variant? For example, when I build your Dockerfile here, I see this output:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop su pport for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support

I managed to get python 3 installed in Alpine 3.10 by following this Dockerfile, but adding your suggested mitogen, ansible-lint, and pywinrm packages:

    pip3 install --no-cache mitogen ansible-lint ; \
    pip3 install --no-cache --upgrade pywinrm ; \

Final working version:

FROM alpine:latest

# LABEL maintainer="Johannes Denninger"
# Details: https://github.com/joxz/alpine-ansible-py3/blob/master/Dockerfile
# This is mostly Johannes' work, but with Will Hall's 2 modifcations and bash, git, jq and delete __pycache__, .pyc
# and no entrypoint.sh or su-exec. See https://github.com/cytopia/docker-ansible/blob/master/Dockerfile-tools

RUN set -euxo pipefail ;\
    sed -i 's/http\:\/\/dl-cdn.alpinelinux.org/https\:\/\/alpine.global.ssl.fastly.net/g' /etc/apk/repositories ;\
    apk add --no-cache --update python3 ca-certificates openssh-client sshpass dumb-init bash git jq ;\
    apk add --no-cache --update --virtual .build-deps python3-dev build-base libffi-dev openssl-dev ;\

    pip3 install --no-cache --upgrade pip ;\
    pip3 install --no-cache --upgrade setuptools ansible ;\
    pip3 install --no-cache mitogen ansible-lint ; \
    pip3 install --no-cache --upgrade pywinrm ; \
    apk del --no-cache --purge .build-deps ;\
    rm -rf /var/cache/apk/* ;\
    rm -rf /root/.cache ;\
    ln -s /usr/bin/python3 /usr/bin/python ;\
    mkdir -p /etc/ansible/ ;\
    /bin/echo -e "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts ;\
    ssh-keygen -q -t ed25519 -N '' -f /root/.ssh/id_ed25519 ;\
    mkdir -p ~/.ssh && echo "Host *" > ~/.ssh/config && echo " StrictHostKeyChecking no" >> ~/.ssh/config ;\
    adduser -s /bin/ash -u 1000 -D -h /ansible ansible

COPY ./entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh

# Details: https://stackoverflow.com/a/41386937/1231693
RUN find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete

ENTRYPOINT ["/usr/bin/dumb-init","--"]

USER ansible
WORKDIR /ansible

Results:

$ docker exec -ti app_ansible_1 python --version
Python 3.7.5

And: image

willhallonline commented 4 years ago

So this all works? Do you want to submit a PR to the Alpine 3.10? Or would you like me to do it?

Secondly, what would you prefer? To run a separate Python 3 version, or to just say "Python 2 is deprecated, use Python 3". What is your preference?

willhallonline commented 4 years ago

So, I bounced this issue onto LinkedIn too (https://www.linkedin.com/posts/willhallonline_python-27-reaches-end-of-life-in-2-months-activity-6597158416609796096-9wbS) and it appears that people are in favour of deprecation of Python2 and replacing with Python3.

I will look for how best to easily do this. @seanw2020 Thanks again for bringing it to my attention. 👍 🥇

Jean-Baptiste-Lasselle commented 4 years ago

idea : integrating https://github.com/pyenv/pyenv in docker builds, to manage python installation ?