Skip to content

expand symlinks in configured workdir - #3437

Closed
vito wants to merge 3 commits into
dagger:mainfrom
vito:fix-workdir-symlink
Closed

vito wants to merge 3 commits into
dagger:mainfrom
vito:fix-workdir-symlink

Conversation

@vito

@vito vito commented Oct 19, 2022

Copy link
Copy Markdown
Contributor

otherwise host path escape assertion can fail if the workdir uses a symlink (e.g. /tmp on macOS)

@vito
vito requested a review from grouville October 19, 2022 16:04
@jpadams

jpadams commented Oct 19, 2022 •

Copy link
Copy Markdown
Contributor

Using my repro here: #3433 (comment)

I additionally cloned down dagger repo and switched to @vito 's PR.

# from /tmp/test_bug_3433
git clone https://github.com/dagger/dagger
cd dagger
gh pr checkout 3437
cd ..

then I edited my go.mod by adding the replace directive line:

require (
    go.dagger.io/dagger v0.2.35-0.20221018121957-69716572d38f
    golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
)
replace go.dagger.io/dagger => ./dagger

then I ran

go build
# ran multiarch binary
./multiarch

worked!!

#22 exporting to client
#22 copying files 10.00MB 0.5s done
#22 DONE 1.9s
build/1.18/darwin/amd64/greetings-api
build/1.18/darwin/arm64/greetings-api
build/1.18/linux/amd64/greetings-api
build/1.18/linux/arm64/greetings-api
build/1.19/darwin/amd64/greetings-api
build/1.19/darwin/arm64/greetings-api
build/1.19/linux/amd64/greetings-api
build/1.19/linux/arm64/greetings-api

@grouville

grouville commented Oct 20, 2022 •

Copy link
Copy Markdown
Member

Ok, I reversed what is happening:

go test -count=1 -race -v -run=TestHostLocalDirReadWrite ./core/integration 
=== RUN   TestHostLocalDirReadWrite
=== PAUSE TestHostLocalDirReadWrite
=== CONT  TestHostLocalDirReadWrite
WORKDIR_BEFORE /private/tmp/dago/core/integration
WORKDIR_AFTER /private/tmp/dago/core/integration
WORKDIR_BEFORE /private/tmp/dago/core/integration
WORKDIR_AFTER /private/tmp/dago/core/integration

DEBBUUUUG /var/folders/y6/3xb6hfpn7kv7vf6n9j3bq4c40000gn/T/TestHostLocalDirReadWrite3211905148/002 /var/folders/y6/3xb6hfpn7kv7vf6n9j3bq4c40000gn/T/TestHostLocalDirReadWrite3211905148/002
DEBBUUUUG2222 /private/var/folders/y6/3xb6hfpn7kv7vf6n9j3bq4c40000gn/T/TestHostLocalDirReadWrite3211905148/002 /private/var/folders/y6/3xb6hfpn7kv7vf6n9j3bq4c40000gn/T/TestHostLocalDirReadWrite3211905148/002
#1 local://dir1
#1 transferring dir1: 33B done
#1 DONE 0.0s

#2 copy / /
#2 CACHED

#3 exporting to client
#3 copying files 29B done
#3 DONE 0.0s
--- PASS: TestHostLocalDirReadWrite (10.60s)
PASS
ok      go.dagger.io/dagger/core/integration    10.926s

The PR in its current state is changing the path of the workdir from an engine perspective. However, in our tests, we directly query WithLocalDir. It is expanded at the engine level properly, but not in our tests.

There are two solutions:

  1. filepath.EvalSymlinks(localDir)
  2. Modify our tests to make sure both path are equal prior sending them to the engine.

I believe that 1) is acceptable. Adding a commit to your PR, with the fix @vito

vito and others added 2 commits October 20, 2022 15:04
otherwise host path escape assertion can fail if the workdir uses a
symlink (e.g. /tmp on macOS)

Signed-off-by: Alex Suraci <[email protected]>
Dest host path gets evalSymlinked, not localDir. Makes MacOS tests fail when `t.TempDir()`, as we directly query `WithLocalDir` that doesn't gets expanded in our tests

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the fix-workdir-symlink branch from a89c30a to 228ee28 Compare October 20, 2022 13:05
@grouville

grouville commented Oct 20, 2022 •

Copy link
Copy Markdown
Member

@vito, I cannot add you as a reviewer. Does this fix seem ok to you ? I'll approve after your review. It works on my side

When testing on an older Macbook Pro amd64, running on MacOS Catalina, tests were also failing due to the same previous issue as before. (Not on ARM/Monterey though).
EvalSymlink is the configPath is a symlink, otherwise, ignore

Signed-off-by: guillaume <[email protected]>
@grouville

grouville commented Oct 20, 2022 •

Copy link
Copy Markdown
Member

Encountered the same issue on MacOS Catalina with the configPath. The third commit fixes this part. Related #3012

@grouville

Copy link
Copy Markdown
Member

Closes #3433

@grouville

Copy link
Copy Markdown
Member

@vito, current state of PR fixes all issues on the available macs I have on hand. LGTM. Just want to double check with you the behavior

@vito

vito commented Oct 20, 2022

Copy link
Copy Markdown
Contributor Author

@grouville Makes sense, so I guess it was breaking on write instead of read for you?

I'm inclined to refactor this a bit since we'll need this "workdir bounds check" in a few APIs soon, so I'll leave it open for now and try to fix it all in one place.

@grouville

Copy link
Copy Markdown
Member

so I guess it was breaking on write instead of read for you?

Exactly

I'm inclined to refactor this a bit since we'll need this "workdir bounds check" in a few APIs soon, so I'll leave it open for now and try to fix it all in one place.

Not a problem 😇

@vito

vito commented Oct 31, 2022

Copy link
Copy Markdown
Contributor Author

This should be superseded by #3348

@vito vito closed this Oct 31, 2022
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.

4 participants