Skip to content

Commit

Permalink
Move yq helpers to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
whoan committed Oct 28, 2023
1 parent 30dd604 commit a72afad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
21 changes: 21 additions & 0 deletions _yq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

_yq() {
local yq
yq=$(which yq || true)
if [ -z "$yq" ]; then
yq=/usr/bin/yq
_copy_yq_from_docker_image "$yq" > /dev/null
fi
"$yq" "$@"
}

_copy_yq_from_docker_image() {
local yq_path=$1
: "${yq_path:?I need a path where yq will be copied}"
local hash
docker pull whoan/yq:4.35.2 >&2
hash=$(docker create whoan/yq:4.35.2)
docker cp "$hash":/usr/bin/yq "$yq_path"
docker rm "$hash"
}
22 changes: 2 additions & 20 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if [ -z "$INPUT_COMPOSE_FILE" ]; then
exit
fi

source ./_yq.sh

merged_compose=/tmp/merged-compose.yml
original_INPUT_IMAGE_TAG=$INPUT_IMAGE_TAG
original_INPUT_CONTEXT=$INPUT_CONTEXT
Expand All @@ -34,26 +36,6 @@ build_from_compose_file() {
done
}

_yq() {
local yq
yq=$(which yq || true)
if [ -z "$yq" ]; then
yq=/usr/bin/yq
_copy_yq_from_docker_image "$yq" > /dev/null
fi
"$yq" "$@"
}

_copy_yq_from_docker_image() {
local yq_path=$1
: "${yq_path:?I need a path where yq will be copied}"
local hash
docker pull whoan/yq:4.35.2 >&2
hash=$(docker create whoan/yq:4.35.2)
docker cp "$hash":/usr/bin/yq "$yq_path"
docker rm "$hash"
}

_merge_yamls() (
local yamls=()
mapfile -d ">" -t yamls < <(echo -n "$INPUT_COMPOSE_FILE")
Expand Down

0 comments on commit a72afad

Please sign in to comment.