buildg icon indicating copy to clipboard operation
buildg copied to clipboard

First line on Dockerfile's Syntax seems to terminate debugging session instantly

Open danielschulz opened this issue 3 years ago • 4 comments

Thank you for this cool OpenSource project! :bowtie:

I have an issue, when debugging my Dockerfiles, which start using Docker BuildKit's Dockerfile-Syntax declarations like this one. Screenshot_20221110_080438

When I remove this first line "# syntax = docker/dockerfile:1.4.3", the debugger IS working perfectly. Having this first line included results in weird output of it:

Screenshot_20221110_080816

The debugger seems to not understand this line and terminates directly — even when this image is present locally in my repository.

danielschulz avatar Nov 10 '22 07:11 danielschulz

@danielschulz Thank you for reporting this issue. Which version of buildg are you using?

And according to the 1st screenshot you shared, BASE_IMAGE arg at line 5 seems blank.

# syntax=docker/dockerfile:1.4.3
...(omit)...
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

Could you set BASE_IMAGE arg to an existing image and try it again?

If the above doesn't solve the issue, could you try $ buildg debug /path/to/your/dockerfile/dir on terminal and share the output?

ktock avatar Nov 10 '22 07:11 ktock

Thank you for getting back to me so swiftly. This got nothing to do with the empty build argument: I provided this in both cases. So the only difference in working and not-working setups was the first line pertaining Dockerfile's Syntax.

I am using the latest buildg, which I build from sources using GoLang 17.5. I used this Docker image to build it and am using buildg wo/ any container since this... golang:1.17.5-buster (Building image)

I am using Docker version: Screenshot_20221111_163922

Do you need more information to work on my findings?

danielschulz avatar Nov 11 '22 15:11 danielschulz

@danielschulz I've tried to reproduce your problem following the steps you provided but can't reproduce the problem and all builds worked perfectly on my matchine.

  1. Could you try the following test on your environment and provide the result?
  2. If the following tests work perfectly on your machine as well, could you provide a minimal complete reproducer for the issue you're reporting so that we can analyze this problem deeper?

Tests on my machine:

  • Version information:
    • Ubuntu 20.04
    • buildg: 176d749a80081d6a5ca47e1d5f39b5d30dffc2c9 (main)
    • docker
      $ docker version
      Client: Docker Engine - Community
       Version:           20.10.21
       API version:       1.41
       Go version:        go1.18.7
       Git commit:        baeda1f
       Built:             Tue Oct 25 18:02:21 2022
       OS/Arch:           linux/amd64
       Context:           default
       Experimental:      true
      
      Server: Docker Engine - Community
       Engine:
        Version:          20.10.21
        API version:      1.41 (minimum version 1.12)
        Go version:       go1.18.7
        Git commit:       3056208
        Built:            Tue Oct 25 18:00:04 2022
        OS/Arch:          linux/amd64
        Experimental:     false
       containerd:
        Version:          1.6.9
        GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
       runc:
        Version:          1.1.4
        GitCommit:        v1.1.4-0-g5fd4c4d
       docker-init:
        Version:          0.19.0
        GitCommit:        de40ad0
      
    • vscode: v1.7.3
    • vscode-buildg: v0.2.0

Preparation: build and install the latest commit of buildg

$ pwd
/home/ktock/go/src/github.com/ktock/buildg
$ cat <<'EOF' > Dockerfile.repro
FROM golang:1.17.5-buster AS dev
COPY . /go/src/github.com/ktock/buildg
WORKDIR /go/src/github.com/ktock/buildg
RUN PREFIX=/out/ make

FROM scratch
COPY --from=dev /out/buildg /
EOF
$ docker build --output=type=local,dest=/tmp/out/ -f Dockerfile.repro .
$ mv /tmp/out/buildg /home/ktock/.local/bin/buildg
$ buildg version
buildg v999.999.999-25-g176d749 176d749a80081d6a5ca47e1d5f39b5d30dffc2c9

Create Dockerfile to test

Contains # syntax=.

$ mkdir -p /tmp/test && cat <<'EOF' >  /tmp/test/Dockerfile
# syntax=docker/dockerfile:1.4.3
FROM ubuntu:22.04
RUN echo 1 > /1
RUN echo 2 > /2
RUN echo 3 > /3
RUN echo 4 > /4
EOF

Test on CLI with # syntax=

Everything works perfectly.

$ buildg debug /tmp/test/
...(omit)...
INFO[2022-11-15T17:36:50+09:00] debug session started. type "help" for command reference. 
Filename: "Dockerfile"
      1| # syntax=docker/dockerfile:1.4.3
 =>   2| FROM ubuntu:22.04
      3| RUN echo 1 > /1
      4| RUN echo 2 > /2
      5| RUN echo 3 > /3
(buildg) n
...(omit)...
#9 [2/5] RUN echo 1 > /1
Filename: "Dockerfile"
      1| # syntax=docker/dockerfile:1.4.3
      2| FROM ubuntu:22.04
 =>   3| RUN echo 1 > /1
      4| RUN echo 2 > /2
      5| RUN echo 3 > /3
      6| RUN echo 4 > /4
(buildg) exec cat /1
1

Test on VS Code with # syntax=

Everything works perfectly.

$ mkdir -p /tmp/test/.vscode && cat <<'EOF' > /tmp/test/.vscode/launch.json 
{
	"version": "0.2.0",
	"configurations": [
		{
			"type": "dockerfile",
			"request": "launch",
			"name": "Debug Dockerfile",
			"program": "${workspaceFolder}/Dockerfile",
			"stopOnEntry": true,
		},
	]
}
EOF

breakpoint

ktock avatar Nov 15 '22 09:11 ktock

Thank you so much for your setup. I will give this a try soon.

For the time being: I am working on your latest release and experience this issue. Here are my versions, which tend to align with your mentioned ones.

Versions

Screenshot_20221115_201747 Screenshot_20221115_201512 Screenshot_20221115_201456

Here is my failing attempt in these versions shown before.

buildg-issue-Dockerfile-syntax2.webm

danielschulz avatar Nov 15 '22 19:11 danielschulz