From 4f2de1fd20fd603c9d8d290943cb3e2e08b184ee Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Wed, 30 Oct 2019 20:47:59 +0100 Subject: [PATCH] Makefile and Dockerfile optimizations, fixes #161 - reduces the number of dependencies on both images - optimizes layers - simplifies .travis.yml --- .travis.yml | 2 -- Makefile | 49 +++++++++++++--------------------- dockerfiles/Dockerfile-android | 20 ++++++-------- dockerfiles/Dockerfile-linux | 27 +++++++++---------- dockerfiles/start.sh | 10 ------- 5 files changed, 38 insertions(+), 70 deletions(-) delete mode 100755 dockerfiles/start.sh diff --git a/.travis.yml b/.travis.yml index 275bd43..3503874 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ services: - xvfb env: - global: - - secure: Lg6sE2VfTO4SeBi0eI17alK0/Bd+2YNpXL41szC1qztuj3r0HBOHuU27bBTGiUQ2fCMI9hTPdFNliKJaFbn4SNckCVIGyslkPu+gB6qMUzkiY1Mzhxos1q3FMxESsFeM1wYArvIyrsxhtFlAHk8xeHb7h/jbkFoY4gi3ubXdKVolbGFzeQDv7D18MTJ1/e4LaHG9h7nLrs41D8I8CMECD+pE4y2kMbKUqbIHVXF3IggQHoq15bAppHUjM+ofI7jxpXf+qwlnIQYDnRgKisuCb7hI9EmJ1gMKX4DKo/r1KHsHBaQoS9//SlYZ8+usleCYw/y/40w7ZobeILxUKyEpcxyDeYFGAeP7iFln5KVpqpirpdpraG0F9e2mktRNWKqiZcNWuFftYayHYx12ON7u9cu5gLVG6m7Wfwk6b6+fRQM3OECx0+w4d+6ANPLEeFgGf4+OwB5m8AIwJMLXvNrh/BweLD91lFfB95r3ByW30aHajD6YsomL68vm36imXunk0bxvwfzK09Lux3xgSpMlj+KTRkfkPD+08ufMZoiGL8nXB6pqRdhL1SZiZdo09psAJCCAWyneaMNZUVN/hp6fdCmVi4e0J+TZpRJSGP8X0MFY4crtNrcfgDxeXuTAbDh1ln+/Tn02BDU7/1dbO+vTmD3wRss7CruZ9N3KnpnGYLU= matrix: - TAG=linux - TAG=android diff --git a/Makefile b/Makefile index d40f8f4..567fcf8 100644 --- a/Makefile +++ b/Makefile @@ -18,43 +18,31 @@ DOCKER_IMAGE_LINUX=andremiras/etherollapp-linux DOCKER_IMAGE_ANDROID=andremiras/etherollapp-android DOCKER_VOLUME=/tmp/.X11-unix:/tmp/.X11-unix SYSTEM_DEPENDENCIES_BASE= \ - git \ - libffi-dev \ libpython$(PYTHON_VERSION)-dev \ - pkg-config \ - python$(PYTHON_VERSION) + python$(PYTHON_VERSION) SYSTEM_DEPENDENCIES_LINUX= \ - build-essential \ - libgmp3-dev \ - libsdl2-dev \ - libsdl2-image-dev \ - libsdl2-mixer-dev \ - libsdl2-ttf-dev \ - libssl-dev \ - tox \ - virtualenv \ - xclip \ - xsel \ - libzbar-dev + build-essential \ + libgl1 \ + libzbar0 \ + python$(PYTHON_MAJOR_VERSION)-virtualenv \ + tox SYSTEM_DEPENDENCIES_ANDROID= \ autoconf \ - autogen \ automake \ - bsdtar \ - ca-certificates \ cmake \ - curl \ gettext \ + libffi-dev \ libltdl-dev \ + git \ libtool \ - openjdk-8-jdk \ - python2.7 \ - python3-pip \ - python3-setuptools \ + openjdk-8-jdk-headless \ + patch \ + pkg-config \ + python$(PYTHON_MAJOR_VERSION)-pip \ + python$(PYTHON_MAJOR_VERSION)-setuptools \ unzip \ - xz-utils \ - zip \ - zlib1g-dev + zlib1g-dev \ + zip ifndef CI DOCKER_DEVICE=--device=/dev/video0:/dev/video0 endif @@ -114,7 +102,6 @@ release/upload: $(TWINE) upload dist/* clean: - py3clean . rm -rf .pytest_cache/ find . -type d -name "__pycache__" -exec rm -r {} + find . -type d -name "*.egg-info" -exec rm -r {} + @@ -147,13 +134,13 @@ docker/push/android: docker/push: docker/push/linux docker/push/android docker/run/test/linux: - docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) $(DOCKER_IMAGE_LINUX) 'make test' + docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_LINUX) make test docker/run/test/android: - docker run --env-file dockerfiles/env.list $(DOCKER_IMAGE_ANDROID) 'make buildozer/android/debug' + docker run --env-file dockerfiles/env.list $(DOCKER_IMAGE_ANDROID) make buildozer/android/debug docker/run/app: - docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) $(DOCKER_IMAGE_LINUX) 'make run' + docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_LINUX) make run docker/run/shell/linux: docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_LINUX) diff --git a/dockerfiles/Dockerfile-android b/dockerfiles/Dockerfile-android index 6f52258..ce436b7 100644 --- a/dockerfiles/Dockerfile-android +++ b/dockerfiles/Dockerfile-android @@ -2,9 +2,7 @@ # Build with: # docker build --tag=andremiras/etherollapp-android --file=dockerfiles/Dockerfile-android . # Run with: -# docker run andremiras/etherollapp-android /bin/sh -c 'buildozer android debug' -# Or using the entry point shortcut: -# docker run andremiras/etherollapp-android 'buildozer android debug' +# docker run -it --rm andremiras/etherollapp-android buildozer android debug # Or for interactive shell: # docker run -it --rm andremiras/etherollapp-android FROM ubuntu:18.04 @@ -24,9 +22,8 @@ ENV LANG="en_US.UTF-8" \ LANGUAGE="en_US.UTF-8" \ LC_ALL="en_US.UTF-8" -# install build dependencies (required to successfully build the project) +# install minimal system dependencies RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ - lsb-release \ make \ sudo && \ rm -rf /var/lib/apt/lists/* @@ -34,23 +31,22 @@ RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends # prepare non root env, with sudo access and no password RUN useradd --create-home --home-dir ${HOME_DIR} --shell /bin/bash ${USER} && \ usermod -append --groups sudo ${USER} && \ - echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ + mkdir ${WORK_DIR} && \ + chown ${USER}:${USER} -R ${WORK_DIR} USER ${USER} +WORKDIR ${WORK_DIR} # install system dependencies +# install buildozer & dependencies and enforces buildozer master (d483847) until next release COPY Makefile /tmp/Makefile RUN sudo make --file /tmp/Makefile system_dependencies/android && \ sudo rm /tmp/Makefile && \ sudo rm -rf /var/lib/apt/lists/* && \ - mkdir ${WORK_DIR} - -# install buildozer & dependencies and enforces buildozer master (d483847) until next release -RUN pip3 install --no-cache-dir --upgrade \ + pip3 install --no-cache-dir --upgrade \ Cython==0.28.6 \ https://github.com/kivy/buildozer/archive/d483847.zip && \ rm -rf ~/.cache/ -WORKDIR ${WORK_DIR} COPY . ${WORK_DIR} -ENTRYPOINT ["./dockerfiles/start.sh"] diff --git a/dockerfiles/Dockerfile-linux b/dockerfiles/Dockerfile-linux index 11c4d7a..f2c672f 100644 --- a/dockerfiles/Dockerfile-linux +++ b/dockerfiles/Dockerfile-linux @@ -2,14 +2,12 @@ # Build with: # docker build --tag=andremiras/etherollapp-linux --file=dockerfiles/Dockerfile-linux . # Run with: -# docker run andremiras/etherollapp-linux /bin/sh -c 'make test' -# Or using the entry point shortcut: -# docker run andremiras/etherollapp-linux 'make test' +# docker run -it --rm andremiras/etherollapp-linux make test # Or for interactive shell: # docker run -it --rm andremiras/etherollapp-linux # For running UI: # xhost +"local:docker@" -# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix andremiras/etherollapp-linux 'make uitest' +# docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --it -rm andremiras/etherollapp-linux make uitest FROM ubuntu:18.04 ENV USER="user" @@ -25,9 +23,8 @@ ENV LANG="en_US.UTF-8" \ LANGUAGE="en_US.UTF-8" \ LC_ALL="en_US.UTF-8" -# install system dependencies +# install minimal system dependencies RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ - lsb-release \ make \ sudo && \ rm -rf /var/lib/apt/lists/* @@ -35,19 +32,19 @@ RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends # prepare non root env, with sudo access and no password RUN useradd --create-home --home-dir ${HOME_DIR} --shell /bin/bash ${USER} && \ usermod -append --groups sudo ${USER} && \ - echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ + mkdir ${WORK_DIR} && \ + chown ${USER}:${USER} -R ${WORK_DIR} USER ${USER} +WORKDIR ${WORK_DIR} # install system dependencies -COPY Makefile /tmp/Makefile -RUN sudo make --file /tmp/Makefile system_dependencies/linux && \ - sudo rm /tmp/Makefile && \ +COPY Makefile requirements.txt ${WORK_DIR}/ +RUN sudo make system_dependencies/linux && \ + make virtualenv && \ + sudo rm ${WORK_DIR}/requirements.txt ${WORK_DIR}/Makefile && \ sudo rm -rf /var/lib/apt/lists/* && \ - mkdir ${WORK_DIR} + mkdir ~/.config -WORKDIR ${WORK_DIR} COPY . ${WORK_DIR} -# required by Kivy `App.user_data_dir` -RUN mkdir ~/.config -ENTRYPOINT ["./dockerfiles/start.sh"] diff --git a/dockerfiles/start.sh b/dockerfiles/start.sh deleted file mode 100755 index bdc4a52..0000000 --- a/dockerfiles/start.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -# if a some command has been passed to container, executes it and exit, -# otherwise runs bash -if [[ $@ ]]; then - eval $@ -else - /bin/bash -fi