Skip to content

Instantly share code, notes, and snippets.

@thinkingerrol
Forked from BrutalSimplicity/Dockerfile
Last active June 18, 2023 08:46
Show Gist options
  • Save thinkingerrol/ba1c1e16c8fd487508ca2b9d0297a224 to your computer and use it in GitHub Desktop.
Save thinkingerrol/ba1c1e16c8fd487508ca2b9d0297a224 to your computer and use it in GitHub Desktop.
Dockerfile from ubuntu:22.04 with asdf + python 3.6.9 thanks to PYTHON_CFLAGS='-O2'
# inspired by:
# https://gist.github.com/BrutalSimplicity/882af1d343b7530fc7e005284523d38d
# and minimized thanks to:
# https://stackoverflow.com/questions/72102435/how-to-install-python3-6-on-ubuntu-22-04
FROM ubuntu:22.04
# ensure we use bash for all RUN commands
# use -l to use interactive login shell
# and ensure modifications to bashrc are properly sourced
SHELL ["/bin/bash", "-lc"]
# Install basic dev packages
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \
libgdbm-dev libnss3-dev libedit-dev libc6-dev \
git \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# installing openssl because saw this in /tmp/python-build*.log:
# warning: openssl 0x00000000 is too old for _hashlib
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
openssl \
&& rm -rf /var/lib/apt/lists/*
RUN git config --global advice.detachedHead false
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
# prepending asdf because bash knows we are not interactive and returns early from .bashrc
RUN sed -i '1s;^;source $HOME/.asdf/asdf.sh\nsource $HOME/.asdf/completions/asdf.bash\n;' ~/.bashrc
RUN asdf plugin add python
# prefixing "asdf install" due to https://stackoverflow.com/questions/70064631/python3-5-m-ensurepip-segmentation-fault
# CC=clang would be the other solution, but "apt install clang" says "557 MB of additional disk space will be used"
RUN PYTHON_CFLAGS='-O2' asdf install python 3.6.9
RUN echo XXXXX
RUN cat /tmp/python-build*.log
RUN echo YYYYY
RUN asdf global python 3.6.9
RUN pip install --upgrade pip
# RUN pip install pipenv
RUN python3 --version
RUN pip3 --version
RUN \
pip3 install --no-cache-dir -i https://artifactory.funkwerk-itk.com/api/pypi/pypi-virtual/simple --upgrade \
setuptools==59.6.0 gcovr pep8==1.7.1 pylint==2.10.2 autopep8==1.3.5 pydocstyle==2.1.1 pycodestyle==2.3.1 \
flake8==3.5.0 flake8-blind-except==0.1.1 flake8-docstrings==1.3.0 autoflake==1.1 \
flake8_quotes==0.13.0 flake8-isort==3.0.1 mccabe==0.6.1 pyflakes==1.6.0 \
autobahn selenium==3.13.0 behave==1.2.6 aiohttp==3.6.2 pymongo polib==1.1.0 \
psycopg2-binary \
docker==3.2.1 dockerpty==0.4.1 ipywidgets pyaml
# make pylint and whatnot available by reshimming
RUN asdf update && asdf reshim python 3.6.9
# Set the working directory
WORKDIR /app
# Copy your application files to the container (if needed)
COPY . /app
# Specify the default command to run when the container starts
CMD ["python", "your_script.py"]
# set all the things to be sure bash is always used as the default shell
RUN cd /bin && ln -sf bash sh && chsh -s /bin/bash
ENV SHELL=bash
ENV PATH=$PATH:/root/.bin
ENTRYPOINT [ "/bin/bash", "-lc" ]
@thinkingerrol
Copy link
Author

got as far as being able to run our 3.6.9 based python code successfully under ubuntu 22.04 where normal python is 3.10.

however, only as root: we have an elaborate dev container spawner script that calls "useradd" and mimicks the host $USER inside the fresh container, and I haven't been able to make it transparently "source" the asdf initialization scripts or do the re-shimming, even after installing asdf under /opt instead of /root and following asdf-vm/asdf#577

so for now I'm giving up on 3.6.9 under ubuntu 22.04 and will try to instead upgrade our python code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment