docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.55k stars 481 forks source link

git submodule init: not a git repository #2172

Closed eruizc-dev closed 10 months ago

eruizc-dev commented 10 months ago

Contributing guidelines

I've found a bug and checked that ...

Description

I'm trying to build Ollama directly from the URL but it fails to clone the

docker buildx build \
  https://github.com/jmorganca/ollama.git\#main \
  -f Dockerfile.build \
  --build-arg=GOFLAGS="'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"

Expected behaviour

I'd expect it to build the image successfully

Actual behaviour

It fails with not a git repository

4.140 + git submodule init
4.164 fatal: not a git repository (or any of the parent directories): .git
4.165 llm/llama.cpp/generate_linux.go:3: running "bash": exit status 128

Buildx version

github.com/docker/buildx 0.12.0 542e5d810e4a1a155684f5f3c5bd7e797632a12f

Docker info

Client:
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  0.12.0
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  2.23.3
    Path:     /usr/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 17
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  Supports d_type: true
  Using metacopy: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 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 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 64b8a811b07ba6288238eefc14d898ee0b5b99ba.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.6.8-zen1-1-zen
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.54GiB
 Name: archlinux
 ID: fa67ab3b-c0a5-4a89-ab0e-99b45a7d7df5
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Builders list

NAME/NODE DRIVER/ENDPOINT STATUS  BUILDKIT             PLATFORMS
default * docker                                       
  default default         running v0.11.7+d3e6c1360f6e linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386

Configuration

I guess you could try the command directly or using the compose file

docker buildx build \
  https://github.com/jmorganca/ollama.git\#main \
  -f Dockerfile.build \
  --build-arg=GOFLAGS="'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"
version: '3'

services:
  ollama:
    entrypoint: /go/src/github.com/jmorganca/ollama/ollama
    command: serve
    build:
      context: https://github.com/jmorganca/ollama.git#main
      dockerfile: Dockerfile.build
      args:
        GOFLAGS: "'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"
    restart: unless-stopped

Build logs

No response

Additional info

Cloning the repository (without its submodules) works without issue:

git clone https://github.com/jmorganca/ollama.git --depth 1
docker buildx build \
  ./ollama \
  -f ./ollama/Dockerfile.build \
  --build-arg=GOFLAGS="'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"
tonistiigi commented 10 months ago

I can't reproduce this.

Note that in order for builds from Git to work, you need to have git installed so that buildkitd (in your case dockerd as you seem to be using the docker driver) can call it. In the default setups like Docker Desktop or moby/buildkit image this should be the case automatically.

eruizc-dev commented 10 months ago

I've checked and I do have git installed, I'll share the entire docker-compose.yml file that I'm trying to compile wit the corresponding logs.

Ollama fails to compile not because it doesn't have git installed, but rather because it cannot find the .git directory when it tries to clone the submodules. Ollama-webui has no submodules and it compiles successfully, so I'm assuming that buildkit is cloning the repositories without the .git directory in them which is fine until you need to run some git command during the build process.

Changing the services.ollama.build.context property to /path/to/repo fixes the issue, but means that I have to clone and update the repository myself

version: '3'

services:
  ollama:
    container_name: ollama
    entrypoint: /go/src/github.com/jmorganca/ollama/ollama
    command: serve
    environment:
      - OLLAMA_HOST=0.0.0.0:11434
      - OLLAMA_ORIGINS=*
      - HSA_OVERRIDE_GFX_VERSION=10.3.0 # Only required for some Radeon GPUs
    build:
      context: https://github.com/jmorganca/ollama.git#main
      dockerfile: Dockerfile.build
      args:
        GOFLAGS: "'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"
    ports:
      - 11434:11434/tcp
    devices: # Give access to AMD GPU
      - /dev/kfd
      - /dev/dri
    volumes:
      - ./ollama_data:/root/.ollama
    restart: unless-stopped

  ollama-webui:
    container_name: ollama-webui
    build:
      context: https://github.com/ollama-webui/ollama-webui.git#main
      args:
        OLLAMA_API_BASE_URL: '/ollama/api'
    depends_on:
      - ollama
    ports:
      - 3000:8080/tcp
    environment:
      - OLLAMA_SKIP_PATCHING=true
      - OLLAMA_API_BASE_URL=http://ollama:11434/api
    volumes:
      - ./ollama_webui:/app/backend/data
    restart: unless-stopped
❯ docker compose up -d --build
[+] Building 10.3s (12/12) FINISHED                                                                                                                           docker:default
 => [ollama internal] load git source https://github.com/jmorganca/ollama.git#main                                                                                      1.6s
 => [ollama internal] load metadata for docker.io/library/ubuntu:20.04                                                                                                  1.2s
 => [ollama base-amd64 1/3] FROM docker.io/library/ubuntu:20.04@sha256:f2034e7195f61334e6caff6ecf2e965f92d11e888309065da85ff50c617732b8                                 0.0s 
 => => resolve docker.io/library/ubuntu:20.04@sha256:f2034e7195f61334e6caff6ecf2e965f92d11e888309065da85ff50c617732b8                                                   0.0s 
 => [ollama] https://dl.google.com/go/go1.21.3.linux-amd64.tar.gz                                                                                                       0.1s 
 => CACHED [ollama base-amd64 2/3] RUN apt-get update &&     apt-get install -y wget gnupg &&     wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu  0.0s 
 => CACHED [ollama base-amd64 3/3] RUN wget -qO- https://github.com/CNugteren/CLBlast/archive/refs/tags/1.6.1.tar.gz | tar zxv -C /tmp/ &&     cd /tmp/CLBlast-1.6.1 &  0.0s
 => CACHED [ollama stage-2 1/6] RUN apt-get update &&     DEBIAN_FRONTEND=noninteractive apt-get install -y gcc-10 g++-10 cpp-10 git ocl-icd-opencl-dev &&     update-  0.0s
 => CACHED [ollama stage-2 2/6] ADD https://dl.google.com/go/go1.21.3.linux-amd64.tar.gz /tmp/go1.21.3.tar.gz                                                           0.0s
 => CACHED [ollama stage-2 3/6] RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.3.tar.gz                                                                   0.0s
 => CACHED [ollama stage-2 4/6] WORKDIR /go/src/github.com/jmorganca/ollama                                                                                             0.0s
 => [ollama stage-2 5/6] COPY . .                                                                                                                                       0.3s
 => ERROR [ollama stage-2 6/6] RUN /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build .                                                              6.9s
------                                                                                                                                                                       
 > [ollama stage-2 6/6] RUN /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build .:                                                                         
0.198 go: downloading golang.org/x/term v0.13.0                                                                                                                              
0.200 go: downloading github.com/emirpasic/gods v1.18.1                                                                                                                      
0.209 go: downloading github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58                                                                                            
0.209 go: downloading github.com/olekukonko/tablewriter v0.0.5                                                                                                               
0.210 go: downloading golang.org/x/crypto v0.14.0
0.214 go: downloading github.com/gin-contrib/cors v1.4.0
0.217 go: downloading github.com/spf13/cobra v1.7.0
0.218 go: downloading github.com/gin-gonic/gin v1.9.1
0.221 go: downloading golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
0.233 go: downloading golang.org/x/sync v0.3.0
0.521 go: downloading github.com/mattn/go-runewidth v0.0.14
0.637 go: downloading golang.org/x/sys v0.13.0
0.844 go: downloading github.com/spf13/pflag v1.0.5
0.962 go: downloading github.com/gin-contrib/sse v0.1.0
0.962 go: downloading github.com/mattn/go-isatty v0.0.19
0.962 go: downloading golang.org/x/net v0.17.0
0.965 go: downloading github.com/pelletier/go-toml/v2 v2.0.8
0.966 go: downloading github.com/ugorji/go/codec v1.2.11
0.969 go: downloading google.golang.org/protobuf v1.30.0
1.096 go: downloading gopkg.in/yaml.v3 v3.0.1
1.118 go: downloading github.com/go-playground/validator/v10 v10.14.0
1.667 go: downloading github.com/gabriel-vasile/mimetype v1.4.2
1.667 go: downloading golang.org/x/text v0.13.0
1.667 go: downloading github.com/go-playground/universal-translator v0.18.1
1.667 go: downloading github.com/leodido/go-urn v1.2.4
1.944 go: downloading github.com/go-playground/locales v0.14.1
2.741 go: downloading github.com/rivo/uniseg v0.2.0
6.687 + set -o pipefail
6.687 + echo 'Starting linux generate script'
6.687 + '[' -z '' -a -x /usr/local/cuda/bin/nvcc ']'
6.687 Starting linux generate script
6.687 + export CUDACXX=/usr/local/cuda/bin/nvcc
6.687 + CUDACXX=/usr/local/cuda/bin/nvcc
6.687 + COMMON_CMAKE_DEFS='-DCMAKE_POSITION_INDEPENDENT_CODE=on -DLLAMA_ACCELERATE=on -DLLAMA_NATIVE=off -DLLAMA_AVX=on -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off'
6.688 ++ dirname ./gen_linux.sh
6.689 + source ./gen_common.sh
6.690 + init_vars
6.690 + LLAMACPP_DIR=gguf
6.690 + PATCHES=0001-Expose-callable-API-for-server.patch
6.690 + CMAKE_DEFS=-DLLAMA_ACCELERATE=on
6.690 + CMAKE_TARGETS='--target ggml --target ggml_static --target llama --target build_info --target common --target ext_server --target llava_static'
6.690 + echo ''
6.690 + grep -- -g
6.693 + CMAKE_DEFS='-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off -DLLAMA_ACCELERATE=on'
6.693 + git_module_setup
6.693 + '[' -n '' ']'
6.693 + git submodule init
6.716 fatal: not a git repository (or any of the parent directories): .git
6.717 llm/llama.cpp/generate_linux.go:3: running "bash": exit status 128
------
failed to solve: process "/bin/sh -c /usr/local/go/bin/go generate ./... &&     /usr/local/go/bin/go build ." did not complete successfully: exit code: 1
tonistiigi commented 10 months ago

Ah, this error does not come from BuildKit doing the Git checkout (eg. https://github.com/moby/buildkit/blob/master/source/git/source.go#L626 ) but your own container process calling git binary internally. I only tested the first steps. If you need .git directory in checkout then add BUILDKIT_CONTEXT_KEEP_GIT_DIR build arg https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg

eruizc-dev commented 10 months ago

That worked, thank you! I was expecting the default to keep the .git directory, my bad on that.

I'll share the working docker-compose file that worked, in case someone has the same problem in the future.

version: '3'

services:
  ollama:
    entrypoint: /go/src/github.com/jmorganca/ollama/ollama
    command: serve
    build:
      context: https://github.com/jmorganca/ollama.git#main
      dockerfile: Dockerfile.build
      args:
        GOFLAGS: "'-ldflags=-w -s -X=github.com/jmorganca/ollama/server.mode=release'"
        BUILDKIT_CONTEXT_KEEP_GIT_DIR: true # Added this
    restart: unless-stopped