From bbba134aa270d7b91340eb45a28056089654aa4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20L=C3=B6thman?= Date: Thu, 23 Mar 2017 13:32:56 +0100 Subject: [PATCH] Splits the Dockerfile into two. * Splits the Dockerfile into a base image and a webapp image. * Makes the build.sh script to build the base image explicitly. This will solve the problem of hanging builds the first time you build the project. * Various pptimizations of the docker images making it go from 12G to 7G in size. --- server/docker-base/Dockerfile | 115 +++++++++++++++ server/{docker => docker-base}/TODO.md | 0 .../build-darwin-toolchain.sh | 0 server/{docker => docker-base}/hw.c | 0 .../test-ios-toolchain.sh | 0 server/{docker => docker-base}/test.sh | 0 server/docker/Dockerfile | 132 +----------------- server/scripts/build.sh | 6 +- server/scripts/start-test-server.sh | 2 + server/src/main/resources/application.yml | 2 +- 10 files changed, 129 insertions(+), 128 deletions(-) create mode 100644 server/docker-base/Dockerfile rename server/{docker => docker-base}/TODO.md (100%) rename server/{docker => docker-base}/build-darwin-toolchain.sh (100%) rename server/{docker => docker-base}/hw.c (100%) rename server/{docker => docker-base}/test-ios-toolchain.sh (100%) rename server/{docker => docker-base}/test.sh (100%) diff --git a/server/docker-base/Dockerfile b/server/docker-base/Dockerfile new file mode 100644 index 00000000..94b40cca --- /dev/null +++ b/server/docker-base/Dockerfile @@ -0,0 +1,115 @@ +FROM ubuntu:16.04 + +# Base stuff +RUN \ + dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y software-properties-common && \ + add-apt-repository -y ppa:webupd8team/java && \ + apt-get update && \ + echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \ + apt-get install -y --no-install-recommends \ + oracle-java8-installer \ + wine \ + gcc \ + g++ \ + libssl-dev \ + openssl \ + libtool \ + autoconf \ + automake \ + uuid-dev \ + libxi-dev \ + libopenal-dev \ + libgl1-mesa-dev \ + libglw1-mesa-dev \ + freeglut3-dev \ + unzip && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /var/cache/oracle-jdk8-installer + +# Android SDK/NDK +ENV ANDROID_ROOT /opt/android +ENV ANDROID_SDK_FILENAME android-sdk_r24.3.3-linux.tgz +ENV ANDROID_SDK_URL http://dl.google.com/android/${ANDROID_SDK_FILENAME} +ENV ANDROID_BUILD_TOOLS_VERSION 23.0.2 +ENV ANDROID_HOME ${ANDROID_ROOT}/android-sdk-linux + +ENV ANDROID_NDK_VERSION 10e +ENV ANDROID_NDK_API_VERSION 14 +ENV ANDROID_TARGET_API_LEVEL 23 +ENV ANDROID_MIN_API_LEVEL 9 +ENV ANDROID_GCC_VERSION 4.8 +ENV ANDROID_NDK_PATH ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION} +ENV ANDROID_NDK_INCLUDE ${ANDROID_ROOT}/tmp/android-ndk-r${ANDROID_NDK_VERSION}/platforms/android-${ANDROID_NDK_API_VERSION}/arch-arm/usr/include +ENV ANDROID_STL_INCLUDE ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/include +ENV ANDROID_STL_ARCH_INCLUDE ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/libs/armeabi-v7a/include +ENV ANDROID_STL_LIB ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/libs/armeabi-v7a +ENV ANDROID_SYSROOT ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/platforms/android-${ANDROID_NDK_API_VERSION}/arch-arm +ENV ANDROID_BIN_PATH ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VERSION}/prebuilt/linux-x86_64/bin +ENV ANDROID_SDK_BUILD_TOOLS_PATH ${ANDROID_ROOT}/android-sdk/build-tools/${ANDROID_BUILD_TOOLS_VERSION} + +ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_BIN_PATH}:${ANDROID_SDK_BUILD_TOOLS_PATH} + +ENV ANDROID_NDK_FILENAME android-ndk-r${ANDROID_NDK_VERSION}-linux-x86_64.zip +ENV ANDROID_NDK_URL https://dl.google.com/android/repository/${ANDROID_NDK_FILENAME} + +RUN mkdir -p cd ${ANDROID_ROOT} && \ + cd ${ANDROID_ROOT} && \ + wget -q -O - ${ANDROID_SDK_URL} | tar -zxvf - && \ + echo y | android update sdk --no-ui -a --filter tools,platform-tools,android-${ANDROID_TARGET_API_LEVEL},build-tools-${ANDROID_BUILD_TOOLS_VERSION} && \ + ln -s android-sdk-linux android-sdk && \ + wget -q ${ANDROID_NDK_URL} && \ + chmod +x ${ANDROID_NDK_FILENAME} && \ + unzip ${ANDROID_NDK_FILENAME} && \ + chmod +r -R ${ANDROID_ROOT} && \ + rm ${ANDROID_NDK_FILENAME} && \ + chmod -R 755 ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION} + +ENV S3_URL https://s3-eu-west-1.amazonaws.com/defold-packages + +RUN wget -q -O - ${S3_URL}/clang%2Bllvm-3.9.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz | tar xJ -C /usr/local --strip-components=1 + +# Windows +ENV PROGRAM_FILES "/root/.wine/drive_c/Program Files" + +RUN \ + mkdir -p "/root/.wine/drive_c/windows/system32" && \ + wget -P /usr/bin ${S3_URL}/prepreg-vc10-dx09-32.exe && \ + ls /root/.wine/drive_c/windows/system32 && \ + mkdir -p "${PROGRAM_FILES}" && \ + wget -q -O - ${S3_URL}/Microsoft-Visual-Studio-10.0.tar.gz | tar xz -C "${PROGRAM_FILES}" + +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +RUN \ + apt-get update && \ + apt-get install -y git && \ + cd /tmp && \ + git clone https://github.com/tpoechtrager/cctools-port.git && \ + cd cctools-port/cctools && \ + git checkout 84ce22dbb22a26ce7f392e9de0ee39c2efe6fd68 && \ + ./autogen.sh && \ + ./configure --prefix=/usr/local --target=arm-apple-darwin11 && \ + make -j8 && \ + make install && \ + make distclean && \ + ./autogen.sh && \ + ./configure --prefix=/usr/local --target=x86_64-apple-darwin11 && \ + make -j8 && \ + make install && \ + apt-get remove -y git + +# Right now, the package contains iPhoneOS.sdk, in the future, we want iPhoneOS9.3.sdk +RUN \ + wget -q -O - ${S3_URL}/iPhoneOS9.3.sdk.tar.gz | tar xz -C /opt && \ + mv /opt/iPhoneOS.sdk /opt/iPhoneOS9.3.sdk && \ + ln -s /opt/iPhoneOS9.3.sdk /opt/iPhoneOS.sdk && \ + wget -q -O - ${S3_URL}/MacOSX10.11.sdk.tar.gz | tar xz -C /opt && \ + ln -s /usr/local/bin/llvm-dsymutil /usr/local/bin/dsymutil && \ + ln -s /usr/local/bin/clang /usr/local/bin/arm-apple-darwin11-clang && \ + ln -s /usr/local/bin/clang /usr/local/bin/x86_64-apple-darwin11-clang && \ + ln -s /usr/local/bin/llvm-ar /usr/local/bin/x86_64-apple-darwin11-clang-ar diff --git a/server/docker/TODO.md b/server/docker-base/TODO.md similarity index 100% rename from server/docker/TODO.md rename to server/docker-base/TODO.md diff --git a/server/docker/build-darwin-toolchain.sh b/server/docker-base/build-darwin-toolchain.sh similarity index 100% rename from server/docker/build-darwin-toolchain.sh rename to server/docker-base/build-darwin-toolchain.sh diff --git a/server/docker/hw.c b/server/docker-base/hw.c similarity index 100% rename from server/docker/hw.c rename to server/docker-base/hw.c diff --git a/server/docker/test-ios-toolchain.sh b/server/docker-base/test-ios-toolchain.sh similarity index 100% rename from server/docker/test-ios-toolchain.sh rename to server/docker-base/test-ios-toolchain.sh diff --git a/server/docker/test.sh b/server/docker-base/test.sh similarity index 100% rename from server/docker/test.sh rename to server/docker-base/test.sh diff --git a/server/docker/Dockerfile b/server/docker/Dockerfile index 5df566f4..60dab7bd 100644 --- a/server/docker/Dockerfile +++ b/server/docker/Dockerfile @@ -1,131 +1,11 @@ -FROM ubuntu:16.04 +FROM extender-base -# Base stuff -RUN apt-get update && apt-get install -y software-properties-common -RUN dpkg --add-architecture i386 RUN \ - echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \ - add-apt-repository -y ppa:webupd8team/java && \ - apt-get update && \ - apt-get install -y\ - curl \ - oracle-java8-installer \ - wine \ - git \ - gcc \ - g++ \ - libssl-dev \ - openssl \ - libtool \ - autoconf \ - automake \ - ccache \ - uuid-dev \ - libxi-dev \ - libopenal-dev \ - valgrind python-setuptools \ - libgl1-mesa-dev \ - libglw1-mesa-dev \ - freeglut3-dev \ - unzip && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /var/cache/oracle-jdk8-installer - -# Android SDK/NDK -ENV ANDROID_ROOT /opt/android -ENV ANDROID_SDK_FILENAME android-sdk_r24.3.3-linux.tgz -ENV ANDROID_SDK_URL http://dl.google.com/android/${ANDROID_SDK_FILENAME} -ENV ANDROID_BUILD_TOOLS_VERSION 23.0.2 -ENV ANDROID_HOME ${ANDROID_ROOT}/android-sdk-linux - -ENV ANDROID_NDK_VERSION 10e -ENV ANDROID_NDK_API_VERSION 14 -ENV ANDROID_TARGET_API_LEVEL 23 -ENV ANDROID_MIN_API_LEVEL 9 -ENV ANDROID_GCC_VERSION 4.8 -ENV ANDROID_NDK_PATH ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION} -ENV ANDROID_NDK_INCLUDE ${ANDROID_ROOT}/tmp/android-ndk-r${ANDROID_NDK_VERSION}/platforms/android-${ANDROID_NDK_API_VERSION}/arch-arm/usr/include -ENV ANDROID_STL_INCLUDE ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/include -ENV ANDROID_STL_ARCH_INCLUDE ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/libs/armeabi-v7a/include -ENV ANDROID_STL_LIB ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VERSION}/libs/armeabi-v7a -ENV ANDROID_SYSROOT ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/platforms/android-${ANDROID_NDK_API_VERSION}/arch-arm -ENV ANDROID_BIN_PATH ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VERSION}/prebuilt/linux-x86_64/bin -ENV ANDROID_SDK_BUILD_TOOLS_PATH ${ANDROID_ROOT}/android-sdk/build-tools/${ANDROID_BUILD_TOOLS_VERSION} - -ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_BIN_PATH}:${ANDROID_SDK_BUILD_TOOLS_PATH} -RUN mkdir -p cd ${ANDROID_ROOT} && \ - cd ${ANDROID_ROOT} && \ - wget -q ${ANDROID_SDK_URL} && \ - tar -xzf ${ANDROID_SDK_FILENAME} && \ - rm ${ANDROID_SDK_FILENAME} && \ - echo y | android update sdk --no-ui -a --filter tools,platform-tools,android-${ANDROID_TARGET_API_LEVEL},build-tools-${ANDROID_BUILD_TOOLS_VERSION} && \ - ln -s android-sdk-linux android-sdk - -ENV ANDROID_NDK_FILENAME android-ndk-r${ANDROID_NDK_VERSION}-linux-x86_64.zip -ENV ANDROID_NDK_URL https://dl.google.com/android/repository/${ANDROID_NDK_FILENAME} - -RUN cd ${ANDROID_ROOT} && \ - wget -q ${ANDROID_NDK_URL} && \ - chmod +x ${ANDROID_NDK_FILENAME} && \ - unzip ${ANDROID_NDK_FILENAME} && \ - chmod +r -R ${ANDROID_ROOT} && \ - rm ${ANDROID_NDK_FILENAME} - -ENV S3_URL https://s3-eu-west-1.amazonaws.com/defold-packages - -RUN wget -q -O - ${S3_URL}/clang%2Bllvm-3.9.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz | tar xJ -C /usr/local --strip-components=1 - -# Windows -ENV PROGRAM_FILES "/root/.wine/drive_c/Program Files" - -RUN mkdir -p "/root/.wine/drive_c/windows/system32" -RUN wget -P /usr/bin ${S3_URL}/prepreg-vc10-dx09-32.exe -RUN ls /root/.wine/drive_c/windows/system32 - - -RUN mkdir -p "${PROGRAM_FILES}" - -RUN wget -q -O - ${S3_URL}/Microsoft-Visual-Studio-10.0.tar.gz | tar xz -C "${PROGRAM_FILES}" - -RUN useradd builder - -RUN locale-gen en_US.UTF-8 -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - - -ADD hw.c /tmp -ADD test.sh /tmp -ADD build-darwin-toolchain.sh /tmp -RUN /tmp/build-darwin-toolchain.sh 84ce22dbb22a26ce7f392e9de0ee39c2efe6fd68 - -# Right now, the package contains iPhoneOS.sdk, in the future, we want iPhoneOS9.3.sdk -RUN wget -q -O - ${S3_URL}/iPhoneOS9.3.sdk.tar.gz | tar xz -C /opt -# Until we've fixed the package -RUN mv /opt/iPhoneOS.sdk /opt/iPhoneOS9.3.sdk -# backwards compatible -RUN ln -s /opt/iPhoneOS9.3.sdk /opt/iPhoneOS.sdk - -RUN wget -q -O - ${S3_URL}/MacOSX10.11.sdk.tar.gz | tar xz -C /opt - -RUN ln -s /usr/local/bin/llvm-dsymutil /usr/local/bin/dsymutil -RUN ln -s /usr/local/bin/clang /usr/local/bin/arm-apple-darwin11-clang -RUN ln -s /usr/local/bin/clang /usr/local/bin/x86_64-apple-darwin11-clang -RUN ln -s /usr/local/bin/llvm-ar /usr/local/bin/x86_64-apple-darwin11-clang-ar - -ADD test-ios-toolchain.sh /tmp - -# Create user "extender" with fixed user ID and run the webapp as that user. -RUN useradd -r -u 2222 extender - -RUN mkdir -p /var/extender -RUN chown extender: /var/extender - -RUN chown extender: $(readlink -f /usr/bin/java) -RUN chmod +s $(readlink -f /usr/bin/java) - -RUN chmod -R 755 ${ANDROID_ROOT}/android-ndk-r${ANDROID_NDK_VERSION} + useradd -r -u 2222 extender && \ + mkdir -p /var/extender && \ + chown extender: /var/extender && \ + chown extender: $(readlink -f /usr/bin/java) && \ + chmod +s $(readlink -f /usr/bin/java) USER extender diff --git a/server/scripts/build.sh b/server/scripts/build.sh index a527813c..9615f7fd 100755 --- a/server/scripts/build.sh +++ b/server/scripts/build.sh @@ -1,5 +1,9 @@ #!/bin/bash +set -e + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -${DIR}/../../gradlew buildDocker \ No newline at end of file +docker build -t extender-base ${DIR}/../docker-base + +${DIR}/../../gradlew buildDocker diff --git a/server/scripts/start-test-server.sh b/server/scripts/start-test-server.sh index cb0e319e..197f1b0b 100755 --- a/server/scripts/start-test-server.sh +++ b/server/scripts/start-test-server.sh @@ -4,6 +4,8 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +docker build -t extender-base ${DIR}/../docker-base + ${DIR}/../../gradlew buildDocker -x test docker run -d --rm --name extender -p 9000:9000 -v ${DIR}/../test-data/sdk:/var/extender/sdk extender/extender diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index a3cc10f9..9b187825 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -4,7 +4,7 @@ server: extender: sdk-location: /var/extender/sdk - sdk-cache-size: 3 + sdk-cache-size: 10 # Slightly bigger than production in order to not remove version controlled SDK build-location: /var/extender/builds spring.http.multipart.max-file-size: 500mb