Skip to content

Commit

Permalink
Support compose file override
Browse files Browse the repository at this point in the history
  • Loading branch information
whoan committed Jan 30, 2021
1 parent a7389e9 commit 7f592eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ or

- **compose_file**: path to Docker Compose file. You will need to configure this action multiple times if you have a compose file which uses more than one registry.

> :star2: New in v5.10: Now you can use overrides for your compose file(s) like this: `docker-compose.yml > docker-compose.override.yml > docker-compose.override2.yml`
### Optional

- **image_tag**: Tag(s) of the image. Allows multiple comma-separated tags (e.g. `one,another`) (default: `latest`).
Expand Down
29 changes: 26 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ if [ -z "$INPUT_COMPOSE_FILE" ]; then
exit
fi

parsed_yaml=/tmp/parsed-yaml.txt
original_INPUT_IMAGE_TAG=$INPUT_IMAGE_TAG

build_from_compose_file() {
original_INPUT_IMAGE_TAG=$INPUT_IMAGE_TAG
parsed_yaml=/tmp/parsed-yaml.txt
_parse_yaml "$INPUT_COMPOSE_FILE" > "$parsed_yaml"
echo -e "\nBuilding from Compose file(s)"
_merge_yamls
_gather_images

if (( ${#images[@]} == 0 )); then
Expand All @@ -31,6 +33,27 @@ build_from_compose_file() {
done
}

# shellcheck disable=SC2086
_merge_yamls() {
local yamls=()
mapfile -d ">" -t yamls < <(echo -n "$INPUT_COMPOSE_FILE")

touch "$parsed_yaml"
local yaml
for yaml in "${yamls[@]}"; do
while read -r line; do
if [[ $line =~ ^(services[^=]+)= ]]; then
local fragment=${BASH_REMATCH[1]}
if grep -q "$fragment" "$parsed_yaml"; then
echo "Overriding: ${fragment//@/ > }"
sed -i "/$fragment/d" "$parsed_yaml"
fi
echo "$line" >> "$parsed_yaml"
fi
done < <(_parse_yaml $yaml)
done
}

# based on https://stackoverflow.com/a/21189044
_parse_yaml() {
local prefix=$2
Expand Down

0 comments on commit 7f592eb

Please sign in to comment.