dockersamples / example-voting-app

Example distributed app composed of multiple containers for Docker, Compose, Swarm, and Kubernetes
Apache License 2.0
4.75k stars 10.99k forks source link

Add .gitattributes file to this repo so that the *.sh files will always use eol=lf #287

Open nighanxiety opened 1 year ago

nighanxiety commented 1 year ago

PLEASE ONLY USE THIS ISSUE TRACKER TO SUBMIT ISSUES WITH THE EXAMPLE VOTING APP

Please provide the following information so we can assess the issue you're having

Description Git recommends users on Windows set the core.autocrlf setting to True.
When this user clones the repo to a local repository, git converts the end-of-line characters of all files from LF \n to CRLF \r\n automatically. This breaks the *.sh scripts used for the healthchecks by the redis and postgres containers, as they are mounted to the containers from the local filesystem, as opposed to copied into the Linux file system on the container. As a result, the vote, worker and results containers will not come up.

It may also not be clear to the user what the issue is, as inspecting the container says the healthcheck *.sh file wasn't found, but it also appears as mounted in the filesystem on the container.

Steps to reproduce the issue, if relevant: Two options to reproduce - both working on a Windows system

  1. git config -- global core.autocrlf true
  2. Clone this repo to a local repository.
  3. Then in the repository docker compose up

Alternative if you don't want to mess with your git settings:

  1. Clone this repo to a local repository.
  2. In VS Code, open the *.sh files in the healthchecks folder. If the info bar on the bottom indicates they are LF, click on that and change them to CRLF, then save.
  3. docker compose up

Describe the results you received: Only the redis and db containers will come up. If you check docker container ls, both containers will have a status of unhealthy. If you inspect either container and check the Health data you'll see something like:

"Health": {
                "Status": "unhealthy",
                "FailingStreak": 107,
                "Log": [
                    {
                        "Start": "2023-03-07T23:04:02.6546463Z",
                        "End": "2023-03-07T23:04:02.7550449Z",
                        "ExitCode": 127,
                        "Output": "/bin/sh: /healthchecks/postgres.sh: not found\n"
                    },

Ano

Describe the results you expected: I expected to be able to build and bring the example up without having to mess with EOL problems. I was originally pointed to this repository but a somewhat older Docker for Beginners course, which apparently predates the addition of the healthchecks.

Additional information you deem important (e.g. issue happens only occasionally): This can be worked around if you know what to look for, but the cause of the error is non-obvious. In VSCode, the files can be opened and manually switched from CRLF to LF in the local repository. Another option is to run dos2unix {filename} in the Git bash terminal to convert the files.

Output of docker version:

Client:
 Cloud integration: v1.0.31
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:43:10 2023
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.17.0 (99724)
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:32:04 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.3)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.1.0)
  extension: Manages Docker extensions (Docker Inc., v0.2.18)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.25.0)
  scout: Command line tool for Docker Scout (Docker Inc., v0.6.0)

Server:
 Containers: 6
  Running: 2
  Paused: 0
  Stopped: 4
 Images: 11
 Server Version: 20.10.23
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.102.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 12.33GiB
 Name: docker-desktop
 ID: XUZH:O4PL:63CS:VMLE:IDGE:QU3L:6GZZ:AELE:VGII:FFRL:DXUD:Y54I
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

Additional environment details (AWS, Docker for Mac, Docker for Windows, VirtualBox, physical, etc.): Windows 10 Home, Docker for Windows, Docker Desktop git version 2.33.0.windows.2

BretFisher commented 1 year ago

This issue can be avoided by following the Docker recommended strategy of cloning your repos to the WSL2 drive and avoiding NTFS filesystems altogether.

https://docs.docker.com/desktop/windows/wsl/#best-practices

Then I'd recommend running your docker commands alongside the code repos in WSL2. Here's some more info: https://www.youtube.com/watch?v=rATNU0Fr8zs&t=678s

I don't see .gitattributes files in other popular repos, so I'm not sure if changing how git behaves for this repo is the correct way for us to solve this issue.