Skip to content

Commit 6280ccb

Browse files
committed
Add buildArgs input to pass --build-args to convox build/deploy
Each space/newline-separated KEY=VALUE pair becomes a separate --build-args flag on both the build and deploy entrypoints. Enables injecting Docker ARG values (e.g. a setuptools_scm pretend-version) into external builds.
1 parent 7ee5f9d commit 6280ccb

6 files changed

Lines changed: 73 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ Builds the app and returns the release ID.
120120
cached: true # optional, default true
121121
external: false # optional, default false
122122
manifest: convox.yml # optional
123+
buildArgs: FOO=1 BAR=2 # optional; each pair becomes a --build-args flag
123124
```
124125

126+
`buildArgs` accepts space- or newline-separated `KEY=VALUE` pairs (values with
127+
spaces are not supported). Use it to pass Docker `ARG` values into the build,
128+
e.g. `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MYPKG=1.2.3`.
129+
125130
### deploy
126131

127132
Builds and deploys in a single operation (waits for completion).
@@ -134,6 +139,7 @@ Builds and deploys in a single operation (waits for completion).
134139
app: my-app
135140
description: "Deploy ${{ github.sha }}"
136141
external: false # optional, default false
142+
buildArgs: FOO=1 BAR=2 # optional; same format as build
137143
```
138144

139145
### build-migrate

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.3.2
1+
v3.4.0

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ inputs:
4141
description: Build the image locally and push directly to the rack registry, bypassing the load balancer upload
4242
required: false
4343
default: false
44+
buildArgs:
45+
description: >-
46+
(build) Docker build args in the form 'KEY1=VALUE1 KEY2=VALUE2', or
47+
newline-separated pairs. Each is passed to convox build as --build-args.
48+
required: false
4449
manifest:
4550
description: Use a custom path for your convox.yml
4651
required: false
@@ -145,6 +150,7 @@ runs:
145150
INPUT_CACHED: ${{ inputs.cached }}
146151
INPUT_ERRORONZEROSCALE: ${{ inputs.errorOnZeroScale }}
147152
INPUT_EXTERNAL: ${{ inputs.external }}
153+
INPUT_BUILDARGS: ${{ inputs.buildArgs }}
148154
INPUT_MANIFEST: ${{ inputs.manifest }}
149155
INPUT_PARAMNAME: ${{ inputs.paramName }}
150156
INPUT_PARAMVALUE: ${{ inputs.paramValue }}

entrypoint-build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ if [ "$INPUT_CACHED" = "false" ]; then set -- "$@" --no-cache; fi
1313
if [ -n "$INPUT_MANIFEST" ]; then set -- "$@" -m "$INPUT_MANIFEST"; fi
1414
if [ "$INPUT_EXTERNAL" = "true" ]; then set -- "$@" --external; fi
1515

16+
# Append --build-args for each KEY=VALUE in INPUT_BUILDARGS (space- or
17+
# newline-separated). ponytail: values with spaces aren't supported; use
18+
# newline-separated env-style parsing if a build arg ever needs one.
19+
if [ -n "$INPUT_BUILDARGS" ]; then
20+
old_ifs="$IFS"
21+
IFS="$(printf ' \n\t')"
22+
set -f
23+
for pair in $INPUT_BUILDARGS; do
24+
[ -n "$pair" ] && set -- "$@" --build-args "$pair"
25+
done
26+
set +f
27+
IFS="$old_ifs"
28+
fi
29+
1630
release=$(convox build "$@")
1731

1832
if [ -z "$release" ]; then

entrypoint-deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ if [ "$INPUT_CACHED" = "false" ]; then set -- "$@" --no-cache; fi
1515
if [ -n "$INPUT_MANIFEST" ]; then set -- "$@" -m "$INPUT_MANIFEST"; fi
1616
if [ "$INPUT_EXTERNAL" = "true" ]; then set -- "$@" --external; fi
1717

18+
# Append --build-args for each KEY=VALUE in INPUT_BUILDARGS (space- or
19+
# newline-separated). ponytail: values with spaces aren't supported.
20+
if [ -n "$INPUT_BUILDARGS" ]; then
21+
old_ifs="$IFS"
22+
IFS="$(printf ' \n\t')"
23+
set -f
24+
for pair in $INPUT_BUILDARGS; do
25+
[ -n "$pair" ] && set -- "$@" --build-args "$pair"
26+
done
27+
set +f
28+
IFS="$old_ifs"
29+
fi
30+
1831
convox deploy "$@" --wait

tests/entrypoints.bats

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,39 @@ exit 1'
467467
grep -q -- "--external" "$CONVOX_CALLS"
468468
}
469469

470+
@test "build: each buildArgs pair is passed as a separate --build-args flag" {
471+
# argc assertion proves both pairs arrive as separate --build-args flags.
472+
stub_convox 'echo "argc=$#" >> "$CONVOX_CALLS"; echo R123'
473+
export INPUT_APP="my-app"
474+
export INPUT_RACK="my-rack"
475+
export INPUT_DESCRIPTION="test-desc"
476+
export INPUT_BUILDARGS="FOO=1 BAR=2"
477+
478+
run sh entrypoint-build.sh
479+
480+
[ "$status" -eq 0 ]
481+
# argv: build --app my-app --description test-desc --id --build-args FOO=1 --build-args BAR=2 = 10
482+
grep -q "^argc=10$" "$CONVOX_CALLS"
483+
grep -F -q "FOO=1" "$CONVOX_CALLS"
484+
grep -F -q "BAR=2" "$CONVOX_CALLS"
485+
}
486+
487+
@test "deploy: each buildArgs pair is passed as a separate --build-args flag" {
488+
stub_convox 'echo "argc=$#" >> "$CONVOX_CALLS"'
489+
export INPUT_APP="my-app"
490+
export INPUT_RACK="my-rack"
491+
export INPUT_DESCRIPTION="test-desc"
492+
export INPUT_BUILDARGS="FOO=1 BAR=2"
493+
494+
run sh entrypoint-deploy.sh
495+
496+
[ "$status" -eq 0 ]
497+
# argv: deploy --app my-app --description test-desc --build-args FOO=1 --build-args BAR=2 --wait = 10
498+
grep -q "^argc=10$" "$CONVOX_CALLS"
499+
grep -F -q "FOO=1" "$CONVOX_CALLS"
500+
grep -F -q "BAR=2" "$CONVOX_CALLS"
501+
}
502+
470503
# ---------------------------------------------------------------------------
471504
# GITHUB_OUTPUT / GITHUB_ENV channel split (plan 009)
472505
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)