Skip to content

Commit

Permalink
Merge pull request #100 from telekom-mms/remove_duplicates_keep_sort_…
Browse files Browse the repository at this point in the history
…order

remove duplicates but keep sort order of variables
  • Loading branch information
rndmh3ro authored Jul 27, 2023
2 parents 83c0cb7 + 1815af2 commit ef58957
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 5 additions & 7 deletions examples/full_build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
packages:
- ansible
- kubectl
- helm
- terraform
Expand All @@ -22,19 +21,18 @@ binaries:
google:
- google-cloud-cli
requirements:
pip:
packages:
- awsume
requirements:
- https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
ansible:
roles:
- telekom_mms.grafana
collections:
- telekom_mms.acme
- telekom_mms.icinga_director
pip:
packages:
- awsume
- ansible
requirements:
- https://raw.githubusercontent.com/T-Systems-MMS/ansible-role-maxscale/master/requirements.yml
- https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
extensions:
az:
- front-door
Expand Down
8 changes: 4 additions & 4 deletions render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)}')

Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions template.d/21_requirements
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## requirements
RUN if [ -n "${REQUIREMENTS}" ]; then \
### pip should alway be the first element in array
REQUIREMENTS=$(echo ${REQUIREMENTS} | awk -F 'pip;' '{print FS$NR$NF}') && \
IFS=';' && \
for REQUIREMENT in ${REQUIREMENTS[@]}; \
do \
Expand Down

0 comments on commit ef58957

Please sign in to comment.