Skip to content

Commit c1f36ae

Browse files
committed
feat(docker-services): Add environment variable expansion for volume paths
Implement envsubst-based expansion of $VAR and ${VAR} references in volume entries, enabling portable bind-mount paths like $GITHUB_WORKSPACE/... that resolve at runtime. Update documentation to clarify this syntax replaces ${{ github.workspace }}, which evaluates to empty string before runner assignment.
1 parent fe7faf5 commit c1f36ae

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

.github/actions/docker-services-up/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ inputs:
99
description: |
1010
Multiline YAML list describing services to start. Each entry supports:
1111
name (required), image (required), ports, env, volumes, options,
12-
health-cmd, health-timeout.
12+
health-cmd, health-timeout. Env-var references ($VAR / ${VAR}) in
13+
volume entries are expanded at runtime (e.g. $GITHUB_WORKSPACE/...).
1314
required: true
1415

1516
runs:

.github/actions/docker-services-up/up.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fi
1111

1212
command -v yq >/dev/null || { echo "::error::yq is required but not installed"; exit 1; }
1313
command -v docker >/dev/null || { echo "::error::docker is required but not installed"; exit 1; }
14+
command -v envsubst >/dev/null || { echo "::error::envsubst is required but not installed (usually in gettext-base)"; exit 1; }
1415

1516
# Output one entry per line from a field that may be:
1617
# - missing (no output)
@@ -80,9 +81,12 @@ for i in $(seq 0 $((count - 1))); do
8081
args+=(--env-file "$env_file")
8182
fi
8283

83-
# Volumes
84+
# Volumes. Env-var references are expanded so callers can use
85+
# `$GITHUB_WORKSPACE/...` for bind-mount paths. Only $VAR / ${VAR} forms
86+
# are substituted; command substitution ($() / backticks) is not.
8487
while IFS= read -r vol; do
8588
[[ -z "$vol" ]] && continue
89+
vol=$(envsubst <<<"$vol")
8690
args+=(-v "$vol")
8791
done < <(extract_lines "$i" volumes)
8892

.github/workflows/elixir-test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ on:
112112
volumes, options, health-cmd, health-timeout. Ports are published on
113113
localhost. Containers share the 'ci-services' network and are removed
114114
automatically at the end of the test job.
115+
Env-var references ($VAR / ${VAR}) inside volume entries are
116+
expanded at runtime, so $GITHUB_WORKSPACE/... can be used for
117+
bind-mount paths. ${{ github.workspace }} is NOT a valid substitute
118+
here: the expression is evaluated at workflow-call time, before any
119+
runner is assigned, so it resolves to the empty string.
115120
Example:
116121
services: |
117122
- name: redis
@@ -121,7 +126,7 @@ on:
121126
- name: mosquitto
122127
image: eclipse-mosquitto:2
123128
ports: 1883:1883
124-
volumes: ./ci/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
129+
volumes: $GITHUB_WORKSPACE/ci/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
125130
secrets:
126131
hex-organization-key:
127132
required: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
- name: mosquitto
118118
image: eclipse-mosquitto:2
119119
ports: 1883:1883
120-
volumes: ${{ github.workspace }}/ci/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
120+
volumes: $GITHUB_WORKSPACE/ci/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
121121
```
122122

123123
Supported per-service fields: `name` (required), `image` (required), `ports`,

0 commit comments

Comments
 (0)