Skip to content

Commit 14686aa

Browse files
committed
git-launcher: default config path
1 parent 67a101f commit 14686aa

3 files changed

Lines changed: 44 additions & 18 deletions

File tree

git-launcher/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# git-launcher
22

33
`git-launcher` runs a workload from one exact Git commit inside a dstack
4-
container. You give it a Git repository URL, a full commit SHA, and a checkout
5-
directory. It fetches that commit, verifies that `HEAD` is exactly the commit
6-
you configured, and then hands control to the workload's entry script.
4+
container. You give it a config file with a Git repository URL, a full commit
5+
SHA, and a checkout directory. It fetches that commit, verifies that `HEAD` is
6+
exactly the commit you configured, and then hands control to the workload's
7+
entry script.
78

89
Use it when you want a generic launcher image whose image digest is stable and
910
auditable, while the workload identity comes from an attested config file.
@@ -48,7 +49,9 @@ Do not use it when:
4849

4950
On startup, `git-launcher`:
5051

51-
1. Parses a line-oriented config file. The config is parsed, not sourced.
52+
1. Parses a line-oriented config file. By default it reads
53+
`/etc/git-launcher/config.conf`; you can pass a different path for local
54+
testing. The config is parsed, not sourced.
5255
2. Rejects missing required keys, unknown keys, short SHAs, branches, and tags.
5356
3. Creates or reuses `WORK_DIR` if it is a Git checkout for the same `REPO_URL`.
5457
4. Runs `git fetch --tags --prune origin`.
@@ -120,7 +123,9 @@ Rules:
120123
## Run locally
121124

122125
Local runs require `bash`, `git`, and standard coreutils. After writing a
123-
config file for a real workload commit, run the launcher script directly:
126+
config file for a real workload commit, run the launcher script directly.
127+
Pass the path explicitly when your local config is not at the container default
128+
`/etc/git-launcher/config.conf`:
124129

125130
```sh
126131
./bin/git-launcher ./config.conf
@@ -163,7 +168,6 @@ or the workload pin changes the attestation.
163168
services:
164169
workload:
165170
image: docker.io/<org>/git-launcher@sha256:<launcher-digest>
166-
command: ["/etc/git-launcher/config.conf"]
167171
configs:
168172
- source: pin
169173
target: /etc/git-launcher/config.conf
@@ -201,8 +205,7 @@ pin, build a small downstream image:
201205

202206
```dockerfile
203207
FROM docker.io/<org>/git-launcher@sha256:<launcher-digest>
204-
COPY web-app.conf /etc/git-launcher/config.conf
205-
CMD ["/etc/git-launcher/config.conf"]
208+
COPY config.conf /etc/git-launcher/config.conf
206209
```
207210

208211
Deploy the derived image by its own digest. The derived image digest now binds
@@ -218,9 +221,8 @@ For local iteration, bind-mounting the config is convenient:
218221
services:
219222
workload:
220223
image: docker.io/<org>/git-launcher@sha256:<launcher-digest>
221-
command: ["/etc/git-launcher/config.conf"]
222224
volumes:
223-
- ./web-app.conf:/etc/git-launcher/config.conf:ro
225+
- ./config.conf:/etc/git-launcher/config.conf:ro
224226
- workload-checkout:/var/lib/git-launcher
225227
- /var/run/dstack.sock:/var/run/dstack.sock
226228
restart: unless-stopped

git-launcher/bin/git-launcher

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@
2323
set -euo pipefail
2424

2525
PROG=$(basename "$0")
26+
DEFAULT_CONFIG_FILE=/etc/git-launcher/config.conf
2627

2728
log() { printf '[%s] %s\n' "$PROG" "$*" >&2; }
2829
die() { printf '[%s] error: %s\n' "$PROG" "$*" >&2; exit 1; }
2930

3031
usage() {
3132
cat >&2 <<EOF
32-
Usage: $PROG <config-file>
33+
Usage: $PROG [config-file]
3334
3435
The config file is a line-oriented KEY=VALUE env file. It is parsed, NOT
3536
sourced; the launcher only executes (via 'bash -c' / 'bash <script>') the
3637
workload's own entry point, plus optional INSTALL_CMD / RUN_CMD overrides.
3738
39+
If config-file is omitted, the launcher reads:
40+
$DEFAULT_CONFIG_FILE
41+
3842
Required keys:
3943
REPO_URL Git URL of the pinned repo (https://... or git@...).
4044
COMMIT_SHA Full 40-hex (SHA-1) or 64-hex (SHA-256) commit hash.
@@ -73,16 +77,16 @@ Unknown keys are rejected.
7377
EOF
7478
}
7579

76-
if [[ $# -ne 1 ]]; then
77-
usage
78-
exit 2
79-
fi
80-
8180
case ${1:-} in
8281
-h|--help) usage; exit 0 ;;
8382
esac
8483

85-
CONFIG_FILE=$1
84+
if [[ $# -gt 1 ]]; then
85+
usage
86+
exit 2
87+
fi
88+
89+
CONFIG_FILE=${1:-$DEFAULT_CONFIG_FILE}
8690

8791
require_tool() {
8892
command -v "$1" >/dev/null 2>&1 || die "required tool not found in PATH: $1"

git-launcher/tests/run-tests.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,26 @@ EOF
494494
}
495495

496496
test_help_flag() {
497-
"$LAUNCHER" --help >/dev/null
497+
local out=$TMPROOT/help.out
498+
"$LAUNCHER" --help >"$out" 2>&1
499+
grep -q "Usage: .*\\[config-file\\]" "$out" || { echo "help does not show optional config file" >&2; cat "$out" >&2; return 1; }
500+
grep -q "/etc/git-launcher/config.conf" "$out" || { echo "help does not document default config path" >&2; cat "$out" >&2; return 1; }
501+
}
502+
503+
test_default_config_path_when_omitted() {
504+
# The container path is absolute, so this test verifies selection by checking
505+
# the missing-file error. If a developer machine happens to have that file,
506+
# the image-level behavior is still covered by the help text and Dockerfile.
507+
if [[ -e /etc/git-launcher/config.conf ]]; then
508+
echo "default config exists on this host; skipping missing-file assertion" >&2
509+
return 0
510+
fi
511+
local err=$TMPROOT/default-config.err
512+
if "$LAUNCHER" 2>"$err"; then
513+
echo "launcher succeeded without an explicit config path on a host with no default config" >&2
514+
return 1
515+
fi
516+
grep -q "config file not found: /etc/git-launcher/config.conf" "$err" || { echo "launcher did not use default config path" >&2; cat "$err" >&2; return 1; }
498517
}
499518

500519
test_release_workflow_attests_image_digest() {
@@ -564,6 +583,7 @@ run_case "entrypoint_script_override" test_entrypoint_script_override
564583
run_case "entrypoint_script_escape_rejected" test_entrypoint_script_escape_rejected
565584
run_case "install_cmd_without_run_cmd_fails" test_install_cmd_without_run_cmd_fails
566585
run_case "help_flag" test_help_flag
586+
run_case "default_config_path_when_omitted" test_default_config_path_when_omitted
567587
run_case "release_workflow_attests_image_digest" test_release_workflow_attests_image_digest
568588
run_case "dockerfile_runtime_is_minimal_launcher" test_dockerfile_runtime_is_minimal_launcher
569589
run_case "verify_doc_present_and_linked" test_verify_doc_present_and_linked

0 commit comments

Comments
 (0)