Skip to content

Commit

Permalink
Reduce image size by consolidating build run
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed Mar 4, 2020
1 parent 7fbe639 commit 4c91bdb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
.DS_Store
.git
dive.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dive.log
36 changes: 20 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
39 changes: 33 additions & 6 deletions root-files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() -
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

0 comments on commit 4c91bdb

Please sign in to comment.