From 2914be8a8899665f1f84fbf278d7c1001960c9a2 Mon Sep 17 00:00:00 2001 From: Mirco Date: Fri, 15 Dec 2023 16:11:49 +0100 Subject: [PATCH] better structuring to docker image building --- infrastructure/clj-cljs/image/Dockerfile | 2 +- .../clj-cljs/image/resources/install.sh | 2 +- infrastructure/clj/image/Dockerfile | 2 +- infrastructure/clj/image/resources/install.sh | 2 +- infrastructure/ddadevops/image/Dockerfile | 6 ++--- .../ddadevops/image/resources/install.sh | 6 +++-- .../dind/image/resources/install.sh | 9 ++++--- infrastructure/kotlin/image/Dockerfile | 2 +- .../kotlin/image/resources/install.sh | 4 +-- infrastructure/python/image/Dockerfile | 5 ++-- .../python/image/resources/install.sh | 6 +++-- .../application/image_build_service.py | 6 +++++ .../image/resources/install_functions.sh | 3 +++ .../resources/install_functions_alpine.sh | 21 ++++++++++++++++ .../resources/install_functions_debian.sh | 25 +++++++++++++++++++ 15 files changed, 80 insertions(+), 21 deletions(-) create mode 100755 src/main/resources/docker/image/resources/install_functions_alpine.sh create mode 100755 src/main/resources/docker/image/resources/install_functions_debian.sh diff --git a/infrastructure/clj-cljs/image/Dockerfile b/infrastructure/clj-cljs/image/Dockerfile index 7efb8ef..ff83d09 100644 --- a/infrastructure/clj-cljs/image/Dockerfile +++ b/infrastructure/clj-cljs/image/Dockerfile @@ -1,4 +1,4 @@ FROM node:lts-bookworm-slim ADD resources /tmp -RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes /tmp/install.sh \ No newline at end of file +RUN /tmp/install.sh \ No newline at end of file diff --git a/infrastructure/clj-cljs/image/resources/install.sh b/infrastructure/clj-cljs/image/resources/install.sh index 88b88cf..a66f796 100755 --- a/infrastructure/clj-cljs/image/resources/install.sh +++ b/infrastructure/clj-cljs/image/resources/install.sh @@ -45,4 +45,4 @@ function checksum() { } source /tmp/install_functions.sh -main \ No newline at end of file +DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes main \ No newline at end of file diff --git a/infrastructure/clj/image/Dockerfile b/infrastructure/clj/image/Dockerfile index 97197c0..f02ebd2 100644 --- a/infrastructure/clj/image/Dockerfile +++ b/infrastructure/clj/image/Dockerfile @@ -1,6 +1,6 @@ FROM debian:stable-slim ADD resources /tmp -RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes /tmp/install.sh +RUN /tmp/install.sh ENV LANG=en_US.UTF-8 \ JAVA_HOME=/usr/lib64/graalvm/graalvm-community-java17 \ No newline at end of file diff --git a/infrastructure/clj/image/resources/install.sh b/infrastructure/clj/image/resources/install.sh index 42dec9a..e2d5ac7 100755 --- a/infrastructure/clj/image/resources/install.sh +++ b/infrastructure/clj/image/resources/install.sh @@ -55,4 +55,4 @@ function checksum() { } source /tmp/install_functions.sh -main \ No newline at end of file +DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes main \ No newline at end of file diff --git a/infrastructure/ddadevops/image/Dockerfile b/infrastructure/ddadevops/image/Dockerfile index 17c2654..6e0efb3 100644 --- a/infrastructure/ddadevops/image/Dockerfile +++ b/infrastructure/ddadevops/image/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.10-alpine -WORKDIR /tmp -ADD resources ./ -RUN ./install.sh +ADD resources /tmp + +RUN /tmp/install.sh diff --git a/infrastructure/ddadevops/image/resources/install.sh b/infrastructure/ddadevops/image/resources/install.sh index 79c19d0..f9ed593 100755 --- a/infrastructure/ddadevops/image/resources/install.sh +++ b/infrastructure/ddadevops/image/resources/install.sh @@ -4,14 +4,16 @@ set -exo pipefail function main() { { + #upgradeSystem apk -U upgrade apk add --no-cache python3 py3-pip openssl-dev bash git curl python3 -m pip install -U pip pip3 install pybuilder ddadevops deprecation dda-python-terraform boto3 pyyaml inflection + #cleanupDocker apk cache clean + rm -rf /tmp/* } > /dev/null - - rm -rf /tmp/* } +#source /tmp/install_functions_alpine.sh main diff --git a/infrastructure/dind/image/resources/install.sh b/infrastructure/dind/image/resources/install.sh index 80e2ce6..1325232 100755 --- a/infrastructure/dind/image/resources/install.sh +++ b/infrastructure/dind/image/resources/install.sh @@ -4,14 +4,15 @@ set -exo pipefail function main() { { + #upgradeSystem apk -U upgrade apk add --no-cache python3 py3-pip openssl-dev bash git - python3 -m pip install -U pip - pip3 install pybuilder ddadevops deprecation dda-python-terraform boto3 pyyaml inflection + pip3 --break-system-packages install pybuilder ddadevops deprecation dda-python-terraform boto3 pyyaml inflection + #cleanupDocker apk cache clean + rm -rf /tmp/* } > /dev/null - - rm -rf /tmp/* } +#source /tmp/install_functions_alpine.sh main diff --git a/infrastructure/kotlin/image/Dockerfile b/infrastructure/kotlin/image/Dockerfile index 4113cf7..23a32d6 100644 --- a/infrastructure/kotlin/image/Dockerfile +++ b/infrastructure/kotlin/image/Dockerfile @@ -1,4 +1,4 @@ FROM debian:stable-slim ADD resources /tmp -RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes /tmp/install.sh +RUN /tmp/install.sh diff --git a/infrastructure/kotlin/image/resources/install.sh b/infrastructure/kotlin/image/resources/install.sh index 12602e5..dd01a61 100755 --- a/infrastructure/kotlin/image/resources/install.sh +++ b/infrastructure/kotlin/image/resources/install.sh @@ -7,11 +7,11 @@ function main() { apt-get -qqy install curl git kotlin gradle iputils-ping ssh python3 python3-pip - pip3 install pybuilder 'ddadevops>=4.7.0' deprecation dda-python-terraform boto3 pyyaml inflection --break-system-packages + pip3 install --break-system-packages pybuilder 'ddadevops>=4.7.0' deprecation dda-python-terraform boto3 pyyaml inflection cleanupDocker } > /dev/null } source /tmp/install_functions.sh -main \ No newline at end of file +DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes main \ No newline at end of file diff --git a/infrastructure/python/image/Dockerfile b/infrastructure/python/image/Dockerfile index 86f7192..0258b37 100644 --- a/infrastructure/python/image/Dockerfile +++ b/infrastructure/python/image/Dockerfile @@ -1,5 +1,4 @@ FROM python:3.10-alpine -WORKDIR /tmp -ADD resources ./ -RUN ./install.sh \ No newline at end of file +ADD resources /tmp +RUN /tmp/install.sh \ No newline at end of file diff --git a/infrastructure/python/image/resources/install.sh b/infrastructure/python/image/resources/install.sh index fc2578c..d57bd24 100755 --- a/infrastructure/python/image/resources/install.sh +++ b/infrastructure/python/image/resources/install.sh @@ -4,15 +4,17 @@ set -exo pipefail function main() { { + #upgradeSystem apk -U upgrade apk add --no-cache build-base rust python3 python3-dev py3-pip py3-setuptools py3-wheel libffi-dev openssl-dev cargo bash git curl python3 -m pip install -U pip pip3 install pybuilder ddadevops deprecation dda-python-terraform boto3 pyyaml inflection \ coverage flake8 flake8-polyfill mypy mypy-extensions pycodestyle pyflakes pylint pytest pytest-cov pytest-datafiles types-setuptools types-PyYAML + #cleanupDocker apk cache clean + rm -rf /tmp/* } > /dev/null - - rm -rf /tmp/* } +#source /tmp/install_functions_alpine.sh main diff --git a/src/main/python/ddadevops/application/image_build_service.py b/src/main/python/ddadevops/application/image_build_service.py index 59117da..8f5dfc6 100644 --- a/src/main/python/ddadevops/application/image_build_service.py +++ b/src/main/python/ddadevops/application/image_build_service.py @@ -31,6 +31,12 @@ class ImageBuildService: self.__copy_build_resource_file_from_package__( "image/resources/install_functions.sh", devops ) + self.__copy_build_resource_file_from_package__( + "image/resources/install_functions_debian.sh", devops + ) + self.__copy_build_resource_file_from_package__( + "image/resources/install_functions_alpine.sh", devops + ) def __copy_build_resources_from_dir__(self, devops: Devops): image = devops.specialized_builds[BuildType.IMAGE] diff --git a/src/main/resources/docker/image/resources/install_functions.sh b/src/main/resources/docker/image/resources/install_functions.sh index 53d9f0b..e0fc5f2 100755 --- a/src/main/resources/docker/image/resources/install_functions.sh +++ b/src/main/resources/docker/image/resources/install_functions.sh @@ -1,3 +1,6 @@ +# +#deprecated, we recommend to use install_functions_debian.sh instead. We will going to remove install_functions.sh in a future release. +# function upgradeSystem() { { apt-get update diff --git a/src/main/resources/docker/image/resources/install_functions_alpine.sh b/src/main/resources/docker/image/resources/install_functions_alpine.sh new file mode 100755 index 0000000..d1118da --- /dev/null +++ b/src/main/resources/docker/image/resources/install_functions_alpine.sh @@ -0,0 +1,21 @@ +function upgradeSystem() { + apk -U upgrade +} + +function cleanupDocker() { + rm -f /root/.ssh/authorized_keys + rm -f /root/.ssh/authorized_keys2 + + apk cache clean + + rm -rf /tmp/* + + find /var/cache -type f -exec rm -rf {} \; + find /var/log/ -name '*.log' -exec rm -f {} \; +} + +function cleanupAmi() { + rm -f /home/ubuntu/.ssh/authorized_keys + rm -f /home/ubuntu/.ssh/authorized_keys2 + cleanupDocker +} diff --git a/src/main/resources/docker/image/resources/install_functions_debian.sh b/src/main/resources/docker/image/resources/install_functions_debian.sh new file mode 100755 index 0000000..d75ccf8 --- /dev/null +++ b/src/main/resources/docker/image/resources/install_functions_debian.sh @@ -0,0 +1,25 @@ +function upgradeSystem() { + apt-get update + apt-get -qqy upgrade +} + +function cleanupDocker() { + rm -f /root/.ssh/authorized_keys + rm -f /root/.ssh/authorized_keys2 + + apt-get clean + apt-get -qqy autoremove --purge + apt-get -qqy autoclean + rm -rf /var/lib/apt/lists/ + + rm -rf /tmp/* + + find /var/cache -type f -exec rm -rf {} \; + find /var/log/ -name '*.log' -exec rm -f {} \; +} + +function cleanupAmi() { + rm -f /home/ubuntu/.ssh/authorized_keys + rm -f /home/ubuntu/.ssh/authorized_keys2 + cleanupDocker +}