Skip to content

Instantly share code, notes, and snippets.

@terabyte
Created December 8, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terabyte/b32b6ed3f2f9cf33188a729b40cf7edf to your computer and use it in GitHub Desktop.
Save terabyte/b32b6ed3f2f9cf33188a729b40cf7edf to your computer and use it in GitHub Desktop.
Example dockerfile that sets up pyenv and a virtualenv
FROM debian:11
RUN apt-get update && apt-get install --no-install-recommends -y \
curl jq tzdata coreutils bash git build-essential ca-certificates \
stress-ng \
zlib1g-dev libffi-dev libssl-dev libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# install and set up pyenv
RUN bash -c 'set -eo pipefail; curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash'
# We must set home explicitly, because the USER directive (probably set in the
# parent image) will cause the HOME variable to be set for RUN commands (since
# they are in a shell), but NOT for add/copy/env commands, since they do NOT
# invoke a shell. Don't ask how long it took me to figure this out.
#
# https://stackoverflow.com/questions/28966198/dockerfile-home-is-not-working-with-add-copy-instructions
ENV HOME /root
# install modern python using pyenv
RUN $HOME/.pyenv/bin/pyenv install 3.10.0
RUN $HOME/.pyenv/bin/pyenv global 3.10.0
RUN $HOME/.pyenv/bin/pyenv rehash
# configure environment for using pyenv
RUN mkdir -p $HOME/bin
ENV PATH="${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:${HOME}/bin:${PATH}"
WORKDIR $HOME
# create our virtualenv
RUN pyenv virtualenv gitlab-ci-load-test && pyenv local gitlab-ci-load-test
RUN pip install --upgrade pip
# copy our script inside the image and install the requirements
COPY requirements.txt /root/
RUN pip install -r requirements.txt
COPY bin/* $HOME/bin/
#ENTRYPOINT [".pyenv/bin/pyenv", "exec", "bin/gitlab-ci-load-test"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment