From d261e10cf944da2f3828459d8e89a7684536f3c9 Mon Sep 17 00:00:00 2001 From: Michaela Mattes Date: Thu, 27 Jul 2023 13:36:03 +0200 Subject: [PATCH 1/4] remove duplicates but keep sort order of variables, https://github.com/telekom-mms/docker-management-container/issues/85 --- examples/full_build.yaml | 2 +- render.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/full_build.yaml b/examples/full_build.yaml index 83e36dd..408ed5f 100644 --- a/examples/full_build.yaml +++ b/examples/full_build.yaml @@ -1,5 +1,4 @@ packages: - - ansible - kubectl - helm - terraform @@ -25,6 +24,7 @@ requirements: pip: packages: - awsume + - ansible requirements: - https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt ansible: diff --git a/render.sh b/render.sh index ee2b937..b7f42d0 100644 --- a/render.sh +++ b/render.sh @@ -65,15 +65,15 @@ echo > "${DOCKERFILE}" build_template parse_yaml "${ENV_FILE}" > "${BUILD_FILE}" -KEYS=$(cut -d '=' -f1 "${BUILD_FILE}" | sort -u) +KEYS=$(cut -d '=' -f1 "${BUILD_FILE}" | awk '!a[$0]++') ## generate ARG=VALUE for replacement for KEY in ${KEYS} do if [ "$(grep -c "^${KEY}=" "${BUILD_FILE}")" -gt 1 ]; then - VALUE=$(grep "^${KEY}=" "${BUILD_FILE}" | cut -d '=' -f2- | sort -u | tr '\n' ';') + VALUE=$(grep "^${KEY}=" "${BUILD_FILE}" | cut -d '=' -f2- | awk '!a[$0]++' | tr '\n' ';') else - VALUE=$(grep "^${KEY}=" "${BUILD_FILE}" | cut -d '=' -f2- | sort -u | tr -d '\n') + VALUE=$(grep "^${KEY}=" "${BUILD_FILE}" | cut -d '=' -f2- | awk '!a[$0]++' | tr -d '\n') fi ARG=$(echo "${KEY}" | awk '{print toupper($0)}') @@ -90,7 +90,7 @@ sed -r "${SED_REPLACE}" "${DOCKERFILE_TEMPLATE}" > "${DOCKERFILE}" ## append ARG if [ "${SED_APPEND_ARGS}" != "" ]; then - SED_APPEND_KEYS=$(echo "$SED_APPEND_ARGS" | tr '#' '\n' | cut -d '=' -f1 | sort -u | xargs) + SED_APPEND_KEYS=$(echo "$SED_APPEND_ARGS" | tr '#' '\n' | cut -d '=' -f1 | awk '!a[$0]++' | xargs) for SED_APPEND_KEY in ${SED_APPEND_KEYS}; do SED_APPEND_KEY_ARG=$(echo "${SED_APPEND_ARGS}" | tr '#' '\n' | sed -n "s/${SED_APPEND_KEY}=/ARG /p" | sed 's/$/\\n/g' | tr -d '\n') From f69e4a566f73e7bbe0af963f24a464c1b197cc66 Mon Sep 17 00:00:00 2001 From: Michaela Mattes Date: Thu, 27 Jul 2023 14:44:37 +0200 Subject: [PATCH 2/4] pip alway be the first element int array --- examples/full_build.yaml | 12 ++++++------ template.d/21_requirements | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/full_build.yaml b/examples/full_build.yaml index 408ed5f..c6d7c1d 100644 --- a/examples/full_build.yaml +++ b/examples/full_build.yaml @@ -21,12 +21,6 @@ binaries: google: - google-cloud-cli requirements: - pip: - packages: - - awsume - - ansible - requirements: - - https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt ansible: roles: - telekom_mms.grafana @@ -35,6 +29,12 @@ requirements: - telekom_mms.icinga_director requirements: - https://raw.githubusercontent.com/T-Systems-MMS/ansible-role-maxscale/master/requirements.yml + pip: + packages: + - awsume + - ansible + requirements: + - https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt extensions: az: - front-door diff --git a/template.d/21_requirements b/template.d/21_requirements index b503a3d..e0bf285 100644 --- a/template.d/21_requirements +++ b/template.d/21_requirements @@ -1,5 +1,12 @@ ## requirements RUN if [ -n "${REQUIREMENTS}" ]; then \ + ### pip should alway be the first element in array + if [ $(echo ${REQUIREMENTS} | grep -wc "pip") -gt 0 ]; then \ + REQS=$(echo ${REQUIREMENTS} | awk -F 'pip;' '{print "pip;"$1$2}'); else \ + REQS=${REQUIREMENTS}; fi && \ + \ + REQUIREMENTS="${REQS}" && \ + \ IFS=';' && \ for REQUIREMENT in ${REQUIREMENTS[@]}; \ do \ From 7abad0b4f40507a5177f38b96e0b1ff316ce17d3 Mon Sep 17 00:00:00 2001 From: Michaela Mattes Date: Thu, 27 Jul 2023 14:51:29 +0200 Subject: [PATCH 3/4] remove example for ansible requirements file --- examples/full_build.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/full_build.yaml b/examples/full_build.yaml index c6d7c1d..1af3ab6 100644 --- a/examples/full_build.yaml +++ b/examples/full_build.yaml @@ -27,8 +27,6 @@ requirements: collections: - telekom_mms.acme - telekom_mms.icinga_director - requirements: - - https://raw.githubusercontent.com/T-Systems-MMS/ansible-role-maxscale/master/requirements.yml pip: packages: - awsume From 1815af2f0a2927b8dbb2aa713c9f3d08be5d26f1 Mon Sep 17 00:00:00 2001 From: Michaela Mattes Date: Thu, 27 Jul 2023 15:53:02 +0200 Subject: [PATCH 4/4] simplify order command --- template.d/21_requirements | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/template.d/21_requirements b/template.d/21_requirements index e0bf285..36d28d0 100644 --- a/template.d/21_requirements +++ b/template.d/21_requirements @@ -1,12 +1,7 @@ ## requirements RUN if [ -n "${REQUIREMENTS}" ]; then \ ### pip should alway be the first element in array - if [ $(echo ${REQUIREMENTS} | grep -wc "pip") -gt 0 ]; then \ - REQS=$(echo ${REQUIREMENTS} | awk -F 'pip;' '{print "pip;"$1$2}'); else \ - REQS=${REQUIREMENTS}; fi && \ - \ - REQUIREMENTS="${REQS}" && \ - \ + REQUIREMENTS=$(echo ${REQUIREMENTS} | awk -F 'pip;' '{print FS$NR$NF}') && \ IFS=';' && \ for REQUIREMENT in ${REQUIREMENTS[@]}; \ do \