Skip to content

refactor: harden Docker helper scripts - #25

Merged
mjun0812 merged 1 commit into
mainfrom
refactor/harden-docker-scripts
Sep 3, 2026
Merged

refactor: harden Docker helper scripts#25
mjun0812 merged 1 commit into
mainfrom
refactor/harden-docker-scripts

Conversation

@mjun0812

Copy link
Copy Markdown
Owner

Overview and Background

This PR hardens the template's Docker helper scripts while preserving their build and run behavior. The previous scripts relied on unquoted expansions, legacy command substitution, and string-based optional arguments, which could split paths or user commands unexpectedly.

Related Issues

None.

Implementation Approach

The scripts now use Bash strict mode, quoted path and variable expansions, modern $(...) command substitution, and arrays for optional Docker flags and forwarded commands. Each terminal Docker or gosu invocation uses exec, so the helper process is replaced directly. Both the repository CI and generated-project CI install and run shfmt and ShellCheck against their respective Docker scripts.

Changes

  • Harden build.sh, run.sh, and entrypoint.sh with safe quoting and strict execution.
  • Preserve optional GPU and TTY flags in an argument array, and preserve arbitrary command arguments without word splitting or glob expansion.
  • Add shfmt and ShellCheck checks to .github/workflows/test.yml and template/.github/workflows/ci.yml.

Impact

Docker image build and run interfaces remain unchanged. Paths and command arguments containing spaces or glob characters are now forwarded as single arguments. CI gains a shell-tool installation step and static checks for Docker scripts; no application runtime or dependency changes are introduced.

Validation Results

  • shellcheck template/docker/*.sh: passed.
  • shfmt --list template/docker/*.sh: passed with no unformatted files.
  • bash -n template/docker/*.sh: passed.
  • Generated a project with uvx copier copy --vcs-ref HEAD ./ /tmp/test-copier-docker ...: passed.
  • shellcheck /tmp/test-copier-docker/docker/*.sh, shfmt --list /tmp/test-copier-docker/docker/*.sh, and bash -n /tmp/test-copier-docker/docker/*.sh: passed.
  • Ran the generated run.sh with a fake Docker CLI and arguments containing spaces and glob characters; all arguments were preserved.
  • ./docker/build.sh: could not complete because the local Docker daemon denied BuildKit activity-file access (operation not permitted).

- Quote paths and variables while using strict Bash execution
- Preserve Docker flags and user commands through safe argument arrays
- Run shellcheck and shfmt in source and generated project CI
@mjun0812mjun0812 self-assigned this Sep 2, 2026

@mjun0812mjun0812 left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex PR Review

Summary

This pull request hardens the Docker helper scripts with strict Bash execution, safe argument handling, and direct process replacement, and adds shell checks to CI. No blocking findings were confirmed. The Contract axis was skipped because no spec source was available.

Verdict

APPROVE

Findings

N/A


Reviewed by Codex at 78797fe

@mjun0812
mjun0812 merged commit 23e3bfe into mainSep 3, 2026
6 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@mjun0812