From 4c91bdb8534551122487d80c0f936714b3d90c66 Mon Sep 17 00:00:00 2001 From: Robert Lemke Date: Wed, 4 Mar 2020 18:39:18 +0100 Subject: [PATCH] Reduce image size by consolidating build run --- .dockerignore | 4 ++++ .gitignore | 1 + Dockerfile | 36 ++++++++++++++++++++---------------- root-files/build.sh | 39 +++++++++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..608fe31 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.cache +.DS_Store +.git +dive.log diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a58fef --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dive.log diff --git a/Dockerfile b/Dockerfile index e116b5d..941376e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,34 +16,38 @@ ENV FLOWNATIVE_LIB_PATH="/opt/flownative/lib" \ PHP_BASE_PATH="/opt/flownative/php" \ PATH="/opt/flownative/php/bin:$PATH" \ BEACH_APPLICATION_PATH=/application \ - LOG_DEBUG=false + LOG_DEBUG=true COPY --from=docker.pkg.github.com/flownative/bash-library/bash-library:1 /lib $FLOWNATIVE_LIB_PATH COPY root-files/opt /opt COPY root-files/build.sh / - -RUN /build.sh init -RUN /build.sh prepare -RUN /build.sh build - COPY extensions $PHP_BASE_PATH/build/extensions -RUN /build.sh build_extension vips -RUN /build.sh build_extension imagick -RUN /build.sh build_extension yaml -RUN /build.sh build_extension phpredis +RUN /build.sh init \ + && /build.sh prepare \ + && /build.sh build \ + && /build.sh build_extension vips \ + && /build.sh build_extension imagick \ + && /build.sh build_extension yaml \ + && /build.sh build_extension phpredis -# Migrate this to further up: - -ENV LOG_DEBUG=true -COPY root-files/entrypoint.sh / COPY more-root-files/opt /opt +#RUN /build.sh clean -RUN rm -rf ${PHP_BASE_PATH}/src -RUN /build.sh clean +RUN chown -R root:root "${PHP_BASE_PATH}" \ + && chmod -R g+rwX "${PHP_BASE_PATH}"\ + && chmod 777 "${PHP_BASE_PATH}"/etc\ + && rm -rf \ + /var/cache/* \ + /var/log/* \ + "${PHP_BASE_PATH}/src" + +COPY root-files/entrypoint.sh / USER 1000 EXPOSE 9000 9001 + +WORKDIR $BEACH_APPLICATION_PATH ENTRYPOINT [ "/entrypoint.sh" ] CMD [ "run" ] diff --git a/root-files/build.sh b/root-files/build.sh index 2565630..e5b974d 100755 --- a/root-files/build.sh +++ b/root-files/build.sh @@ -51,11 +51,9 @@ build_get_build_packages() { pkg-config re2c file - gettext libxml2-dev libssl-dev - libssl1.1 libcurl4-openssl-dev libreadline6-dev libmcrypt-dev @@ -78,6 +76,21 @@ build_get_build_packages() { echo $packages } +# --------------------------------------------------------------------------------------- +# build_get_runtime_packages() - Returns a list of packages which are needed during runtime +# +# @global PHP_BASE_PATH +# @return List of packages +# +build_get_runtime_packages() { + local packages=" + gettext + + libssl1.1 + " + echo $packages +} + # --------------------------------------------------------------------------------------- # build_compile_php() - # @@ -130,8 +143,6 @@ build_compile_php() { make -j"$(nproc)" > $(debug_device) make install > $(debug_device) - ln -s /usr/local/bin/php /usr/bin/php - info "🛠 Cleaning up ..." make clean > $(debug_device) rm -rf /tmp/pear @@ -258,6 +269,19 @@ build_adjust_permissions() { chmod 777 "${PHP_BASE_PATH}"/etc } +# --------------------------------------------------------------------------------------- +# build_clean() - Clean up obsolete building artifacts and temporary files +# +# @global PHP_BASE_PATH +# @return void +# +build_clean() { + rm -rf \ + /var/cache/* \ + /var/log/* \ + "${PHP_BASE_PATH}/src" +} + # --------------------------------------------------------------------------------------- # Main routine @@ -267,8 +291,8 @@ case $1 in build_create_directories ;; prepare) + packages_install $(build_get_runtime_packages) 1>$(debug_device) packages_install $(build_get_build_packages) 1>$(debug_device) - packages_remove_docs_and_caches 1>$(debug_device) ;; build) build_compile_php @@ -278,6 +302,9 @@ case $1 in ;; clean) build_adjust_permissions - packages_remove_docs_and_caches + + packages_remove $(build_get_build_packages) 1>$(debug_device) + packages_remove_docs_and_caches 1>$(debug_device) + build_clean ;; esac