Skip to content

Commit

Permalink
Merge pull request #130 from whoan/issue-127
Browse files Browse the repository at this point in the history
Issue 127
  • Loading branch information
whoan committed Jun 8, 2023
2 parents d4f4c0a + a33ae1b commit a3bc6f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ or
- `on:push`: Push only if the workflow was triggered by a push.
- `on:pull_request`: Push only if the workflow was triggered by a pull_request.

- **services_regex**: Regex to filter services from compose file. Only valid when **compose_file** was provided. Default is `.+` (all services).

[branch tip]: https://stackoverflow.com/questions/16080342/what-is-a-branch-tip-in-git

#### Ignored if `compose_file` is set
Expand Down Expand Up @@ -182,6 +184,18 @@ With a compose file override:
compose_file: docker-compose.yml > docker-compose.override.yml
```

Filtering services by regex:

```yml
- uses: whoan/docker-build-with-cache-action@v5
with:
username: whoan
password: "${{ secrets.GITHUB_TOKEN }}"
registry: docker.pkg.github.com
compose_file: docker-compose.yml
services_regex: '(service_1|extra_service.*)' # eg: builds services called exactly "service_1" plus the ones which start with "extra_service" and may have extra chars after
```

### Example with more options

```yml
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
compose_file:
description: Path to compose file
required: false
services_regex:
description: (Optional) Regex to filter services from compose file
required: false
default: '.+'
username:
description: (Optional) Docker's registry user (needed to push image to repository, or to pull from private repository)
required: false
Expand Down
9 changes: 8 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ _gather_images() {
local registry=$INPUT_REGISTRY
: "${registry:=$INPUT_USERNAME}" # an empty registry defaults to DockerHub, and a username is needed to detect its images
: "${registry:?Either registry or username (for DockerHub) is needed to build from a compose file}"

images=()
mapfile -t images < <(_yq e ".services.[].image | select(. != null and test(\"^${registry}/\"))" "$merged_compose")
mapfile -t images < <(_yq e "
.services
| with_entries(select(.key | test(\"^${INPUT_SERVICES_REGEX:-.+}\$\")))
| .[].image
| select(. != null and test(\"^${registry}/\"))
" "$merged_compose"
)
}

_set_variables() {
Expand Down

0 comments on commit a3bc6f0

Please sign in to comment.