Skip to content

Commit

Permalink
Update dev build to better support multi-os (#1069)
Browse files Browse the repository at this point in the history
* Update development build
 * Fixed an issue where the development build could use an incorrect uid / gid
 * Fix an issue where .python-version is in an incorrect version
 * Optimize build to install pyenv as the user
 * Reduce number of layers during build
  • Loading branch information
Expl0dingBanana authored Dec 19, 2020
1 parent 3aa9bd9 commit 05b0066
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = PIL,aioconsole,apkutils,bitstring,configargparse,cv2,flask,flask_caching,gevent,google,gpapi,gpxdata,imutils,loguru,mysql,numpy,pkg_resources,psutil,pytesseract,pytest,requests,s2sphere,urllib3,websockets,werkzeug
known_third_party = PIL,aioconsole,apkutils,bitstring,configargparse,cv2,dataclasses,flask,flask_caching,gevent,google,gpapi,gpxdata,imutils,loguru,mysql,numpy,pkg_resources,psutil,pytesseract,pytest,requests,s2sphere,urllib3,websockets,werkzeug
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ up:
docker-compose -f ${COMPOSE_FILE_DEV} up --detach

shell: up
docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) $(CONTAINER_NAME) $(CMD)
docker-compose -f ${COMPOSE_FILE_DEV} exec $(CONTAINER_NAME) $(CMD)

root-shell: up
docker-compose -f ${COMPOSE_FILE_DEV} exec -u root $(CONTAINER_NAME) $(CMD)
Expand All @@ -125,10 +125,10 @@ down:
docker-compose -f ${COMPOSE_FILE_DEV} down

tests: up
docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox
docker-compose -f ${COMPOSE_FILE_DEV} exec mapadroid-dev tox

unittests: up
docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e py37
docker-compose -f ${COMPOSE_FILE_DEV} exec mapadroid-dev tox -e py37

# Run bash within a defined tox environment
# Specify a valid tox environment as such:
Expand All @@ -137,9 +137,9 @@ unittests: up
# make shell-py37 RECREATE=1
shell-%: up
ifdef RECREATE
docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e $* --recreate -- bash
docker-compose -f ${COMPOSE_FILE_DEV} exec mapadroid-dev tox -e $* --recreate -- bash
else
docker-compose -f ${COMPOSE_FILE_DEV} exec -u $(UID) mapadroid-dev tox -e $* -- bash
docker-compose -f ${COMPOSE_FILE_DEV} exec mapadroid-dev tox -e $* -- bash
endif

versions:
Expand Down
41 changes: 22 additions & 19 deletions docker/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
# Development env
FROM local_mad_production:latest AS dev_test
RUN pip install tox
# Versions of python to install for pyenv. These are used when tox executes specific
# python versions. The correct versions need to be added to tox.ini under tox/envlist
ENV PYTHON_VERSIONS 3.6.0 3.7.0 3.8.0
COPY requirements-test.txt /usr/src/app/
# User information related to how to run within the shell
ARG USER_NAME=dockeruser
ARG UID=1000
ARG GID=1000
ENV USER $USER_NAME
ENTRYPOINT ["bash"]

# Need to re-add some required dependencies for tox to compile the new envs
RUN apt-get install -y --no-install-recommends \
# pyenv
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 python-openssl git \
# python build
libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev
libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev && \
# Create user
groupadd -g $GID $USER_NAME; \
useradd -l -r -m -u $UID -g $GID $USER_NAME && \
# Install tox
pip install tox

# Map the user to avoid perm conflict
ARG USER_NAME=dockeruser
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID $USER_NAME; useradd -l -r -m -u $UID -g $GID $USER_NAME
ENV USER $USER_NAME
# Install pyenv
# @TODO - How to install as a user and not root?
ENV HOME=/home/dockeruser
ENV HOME=/home/${USER}
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH="$PYENV_ROOT/bin:$PATH"
ENV PATH="$PYENV_ROOT/shims:$PATH"
RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
RUN chown -R dockeruser:dockeruser -R $HOME
RUN for version in $PYTHON_VERSIONS; do \
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
WORKDIR ${HOME}
USER $USER_NAME
RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash && \
for version in $PYTHON_VERSIONS; do \
pyenv install $version; \
pyenv local $version; \
pip install --upgrade setuptools pip; \
pyenv local --unset; \
done
RUN echo "pyenv local $PYTHON_VERSIONS" >> ~/.bashrc
RUN pyenv local $PYTHON_VERSIONS
done && \
echo "pyenv local $PYTHON_VERSIONS" >> ~/.bashrc && \
pyenv local $PYTHON_VERSIONS
WORKDIR /usr/src/app

0 comments on commit 05b0066

Please sign in to comment.