Skip to content

chore: add .gitattributes#734

Merged
doringeman merged 1 commit intodocker:mainfrom
doringeman:gitattributes
Mar 5, 2026
Merged

chore: add .gitattributes#734
doringeman merged 1 commit intodocker:mainfrom
doringeman:gitattributes

Conversation

@doringeman
Copy link
Contributor

Ensure *.sh and *.patch files are checked out with LF endings. This prevents CRLF-related execution failures inside Linux containers when developing on Windows.

E.g.,

$ make docker-run
docker buildx build --load --platform linux/amd64 --build-arg LLAMA_SERVER_VERSION=latest --build-arg LLAMA_SERVER_VARIANT=cpu --build-arg BASE_IMAGE=ubuntu:24.04 --target final-llamacpp -t docker/model-runner:latest .
[+] Building 3.9s (28/33)                                                                                                                                                                                                                                          docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                               0.1s
 => => transferring dockerfile: 8.03kB                                                                                                                                                                                                                                             0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                                                                                                                                                                                                          1.0s
 => [auth] docker/dockerfile:pull token for registry-1.docker.io                                                                                                                                                                                                                   0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6                                                                                                                                                    0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6                                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/ubuntu:24.04                                                                                                                                                                                                                    0.6s
 => [internal] load metadata for docker.io/docker/docker-model-backend-llamacpp:latest-cpu                                                                                                                                                                                         0.6s
 => [internal] load metadata for docker.io/library/golang:1.26-bookworm                                                                                                                                                                                                            0.6s
 => [auth] library/golang:pull token for registry-1.docker.io                                                                                                                                                                                                                      0.0s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                                                                                                                                                                                      0.0s
 => [auth] docker/docker-model-backend-llamacpp:pull token for registry-1.docker.io                                                                                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                  0.0s
 => => transferring context: 844B                                                                                                                                                                                                                                                  0.0s
 => [llamacpp 1/8] FROM docker.io/library/ubuntu:24.04@sha256:d1e2e92c075e5ca139d51a140fff46f84315c0fdce203eab2807c7e495eff4f9                                                                                                                                                     0.1s
 => => resolve docker.io/library/ubuntu:24.04@sha256:d1e2e92c075e5ca139d51a140fff46f84315c0fdce203eab2807c7e495eff4f9                                                                                                                                                              0.1s
 => [builder 1/7] FROM docker.io/library/golang:1.26-bookworm@sha256:2a0ba12e116687098780d3ce700f9ce3cb340783779646aafbabed748fa6677c                                                                                                                                              0.1s
 => => resolve docker.io/library/golang:1.26-bookworm@sha256:2a0ba12e116687098780d3ce700f9ce3cb340783779646aafbabed748fa6677c                                                                                                                                                      0.1s
 => CACHED [llama-server 1/1] FROM docker.io/docker/docker-model-backend-llamacpp:latest-cpu@sha256:c93030360d2a2662f8829e28578a01fef9e91c8f0896e535874e6fa1db5d72b1                                                                                                               0.1s
 => => resolve docker.io/docker/docker-model-backend-llamacpp:latest-cpu@sha256:c93030360d2a2662f8829e28578a01fef9e91c8f0896e535874e6fa1db5d72b1                                                                                                                                   0.1s
 => [internal] load build context                                                                                                                                                                                                                                                  1.0s
 => => transferring context: 20.20MB                                                                                                                                                                                                                                               1.0s
 => CACHED [llamacpp 2/8] RUN groupadd --system modelrunner && useradd --system --gid modelrunner -G video --create-home --home-dir /home/modelrunner modelrunner                                                                                                                  0.0s
 => [llamacpp 3/8] COPY scripts/ /scripts/                                                                                                                                                                                                                                         0.1s
 => CACHED [builder 2/7] RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*                                                                                                                                                       0.0s
 => CACHED [builder 3/7] WORKDIR /app                                                                                                                                                                                                                                              0.0s
 => CACHED [builder 5/7] RUN --mount=type=cache,target=/go/pkg/mod     --mount=type=cache,target=/root/.cache/go-build     go mod download                                                                                                                                         0.0s
 => CACHED [builder 4/7] COPY --link go.mod go.sum ./                                                                                                                                                                                                                              0.0s
 => ERROR [llamacpp 4/8] RUN /scripts/apt-install.sh && rm -rf /scripts                                                                                                                                                                                                            0.8s
 => [builder 6/7] COPY --link . .                                                                                                                                                                                                                                                  0.9s
 => => merging                                                                                                                                                                                                                                                                     0.2s
 => CANCELED [builder 7/7] RUN --mount=type=cache,target=/go/pkg/mod     --mount=type=cache,target=/root/.cache/go-build     CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w -X main.Version=dev" -o model-runner .                                                              0.0s
------
 > [llamacpp 4/8] RUN /scripts/apt-install.sh && rm -rf /scripts:
0.686 /bin/sh: 1: /scripts/apt-install.sh: not found
------
Dockerfile:61
--------------------
  59 |
  60 |     # Install ca-certificates for HTTPS and vulkan
  61 | >>> RUN /scripts/apt-install.sh && rm -rf /scripts
  62 |
  63 |     WORKDIR /app
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c /scripts/apt-install.sh && rm -rf /scripts" did not complete successfully: exit code: 127
make: *** [Makefile:120: docker-build] Error 1

Ensure *.sh and *.patch files are checked out with LF endings. This prevents CRLF-related execution failures inside Linux containers when developing on Windows.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a .gitattributes file to enforce LF line endings for *.sh and *.patch files, which is a good step to prevent cross-platform compatibility issues. However, this can be improved by applying the line ending normalization to all text files, not just specific extensions. This would make the configuration more robust and prevent similar issues with other file types in the future. I've added a suggestion to implement this.

Comment on lines +1 to +4
# Ensure shell scripts and patch files always use LF line endings.
# Required for correct execution in Linux containers; Windows may use CRLF.
*.sh text eol=lf
*.patch text eol=lf
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While specifying line endings for *.sh and *.patch files is a good start, this line ending issue can affect many other text-based files in a cross-platform project (e.g., Makefile, Dockerfile, source code files). To create a more robust and future-proof solution, it's better to set a default rule for all text files.

Using * text=auto eol=lf will automatically handle line endings for all files that Git detects as text, which is a common best practice for repositories with contributors on different operating systems.

# Normalize all text files to use LF line endings.
# This prevents cross-platform issues with files like scripts, Makefiles,
# and Dockerfiles when working in mixed OS environments.
* text=auto eol=lf

Copy link
Contributor

@ericcurtin ericcurtin left a comment

Choose a reason for hiding this comment

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

LGTM, which file had the CRLF line endings?

@doringeman
Copy link
Contributor Author

The shell script and the patches are checked out with CRLF by default in Git Bash. And I couldn't make docker-run without this + re-checking out/renormalizing the files. See the example in the description. Should be straight forward to reproduce.

@doringeman doringeman merged commit 88cebee into docker:main Mar 5, 2026
6 checks passed
Sign up for free to 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.

2 participants