From a15c44d9610229bd6682f9f3bbe56c90fe5effcb Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 13 Oct 2019 22:22:13 +0200 Subject: [PATCH] Dockerfiles improvements - investigates Docker image caching not fully leveraged, refs #160 - tries to keep image light in size, refs #161 --- Makefile | 4 ++-- dockerfiles/Dockerfile-android | 33 ++++++++++++++++++--------------- dockerfiles/Dockerfile-linux | 26 +++++++++++++++----------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index db22353..4dd0375 100644 --- a/Makefile +++ b/Makefile @@ -60,11 +60,11 @@ endif system_dependencies_linux: ifeq ($(OS), Ubuntu) - sudo apt update -qq > /dev/null && sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_LINUX) + sudo apt update -qq > /dev/null && sudo apt -qq install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_LINUX) endif system_dependencies_android: ifeq ($(OS), Ubuntu) - sudo apt update -qq > /dev/null && sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_ANDROID) + sudo apt update -qq > /dev/null && sudo apt -qq install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_ANDROID) endif diff --git a/dockerfiles/Dockerfile-android b/dockerfiles/Dockerfile-android index a82530d..d375640 100644 --- a/dockerfiles/Dockerfile-android +++ b/dockerfiles/Dockerfile-android @@ -11,7 +11,7 @@ FROM ubuntu:18.04 ENV USER="user" ENV HOME_DIR="/home/${USER}" -ENV WORK_DIR="${HOME_DIR}" \ +ENV WORK_DIR="${HOME_DIR}/app" \ PATH="${HOME_DIR}/.local/bin:${PATH}" ENV DOCKERFILES_VERSION="develop" \ DOCKERFILES_URL="https://raw.githubusercontent.com/AndreMiras/dockerfiles" @@ -21,7 +21,8 @@ ENV MAKEFILES_URL="${DOCKERFILES_URL}/${DOCKERFILES_VERSION}/buildozer_android" # configure locale RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ locales && \ - locale-gen en_US.UTF-8 + locale-gen en_US.UTF-8 && \ + rm -rf /var/lib/apt/lists/* ENV LANG="en_US.UTF-8" \ LANGUAGE="en_US.UTF-8" \ LC_ALL="en_US.UTF-8" @@ -32,25 +33,27 @@ ENV LANG="en_US.UTF-8" \ RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ lsb-release \ make \ - sudo + sudo && \ + rm -rf /var/lib/apt/lists/* -# prepare non root env -RUN useradd --create-home --shell /bin/bash ${USER} -# with sudo access and no password -RUN usermod -append --groups sudo ${USER} -RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# 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 USER ${USER} WORKDIR ${WORK_DIR} -COPY Makefile ${WORK_DIR} -RUN sudo make system_dependencies_android +COPY Makefile /tmp/Makefile +RUN sudo make --file /tmp/Makefile system_dependencies_android && \ + sudo rm /tmp/Makefile && \ + sudo rm -rf /var/lib/apt/lists/* -# install buildozer and dependencies -RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk -RUN make -f buildozer.mk -# enforces buildozer master (d483847) until next release -RUN pip3 install --upgrade https://github.com/kivy/buildozer/archive/d483847.zip +# install buildozer & dependencies and enforces buildozer master (d483847) until next release +RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output /tmp/buildozer.mk && \ + make --file /tmp/buildozer.mk && \ + rm /tmp/buildozer.mk && \ + pip3 install --no-cache-dir --upgrade https://github.com/kivy/buildozer/archive/d483847.zip COPY . ${WORK_DIR} ENTRYPOINT ["./dockerfiles/start.sh"] diff --git a/dockerfiles/Dockerfile-linux b/dockerfiles/Dockerfile-linux index e354d1d..8754c5f 100644 --- a/dockerfiles/Dockerfile-linux +++ b/dockerfiles/Dockerfile-linux @@ -14,12 +14,13 @@ FROM ubuntu:18.04 ENV USER="user" ENV HOME_DIR="/home/${USER}" -ENV WORK_DIR="${HOME_DIR}" +ENV WORK_DIR="${HOME_DIR}/app" # configure locale -RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \ +RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ locales && \ - locale-gen en_US.UTF-8 + locale-gen en_US.UTF-8 && \ + rm -rf /var/lib/apt/lists/* ENV LANG="en_US.UTF-8" \ LANGUAGE="en_US.UTF-8" \ LC_ALL="en_US.UTF-8" @@ -28,19 +29,22 @@ ENV LANG="en_US.UTF-8" \ RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ lsb-release \ make \ - sudo + sudo && \ + rm -rf /var/lib/apt/lists/* -# prepare non root env -RUN useradd --create-home --shell /bin/bash ${USER} -# with sudo access and no password -RUN usermod -append --groups sudo ${USER} -RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# 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 USER ${USER} WORKDIR ${WORK_DIR} -COPY Makefile ${WORK_DIR} -RUN sudo make system_dependencies_linux +COPY Makefile /tmp/Makefile +RUN sudo make --file /tmp/Makefile system_dependencies_linux && \ + sudo rm /tmp/Makefile && \ + sudo rm -rf /var/lib/apt/lists/* + COPY . ${WORK_DIR} # required by Kivy `App.user_data_dir` RUN mkdir ~/.config