Skip to content

Commit

Permalink
Updated tests in frontend/dockerfile/dockerfile_test.go to run on Win…
Browse files Browse the repository at this point in the history
…dows.

Partially addressing #4485

Signed-off-by: Billy Owire <billyowire95@gmail.com>
  • Loading branch information
crazy-max authored and billywr committed Sep 26, 2024
2 parents 1da789b + 49142c5 commit b8d3322
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 44 deletions.
25 changes: 9 additions & 16 deletions .github/workflows/test-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ jobs:
uses: crazy-max/ghaction-dump-context@v2

test-freebsd-amd64:
runs-on: macos-13
runs-on: ubuntu-22.04
needs:
- build
env:
VAGRANT_VAGRANTFILE: hack/Vagrantfile.freebsd13
GOOS: freebsd
steps:
-
Expand All @@ -195,25 +194,23 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.vagrant.d/boxes
key: ${{ runner.os }}-vagrant-${{ hashFiles('hack/Vagrantfile.freebsd13') }}
key: ${{ runner.os }}-vagrant-${{ hashFiles('hack/Vagrantfile.freebsd') }}
restore-keys: |
${{ runner.os }}-vagrant-
-
name: Install vagrant and VirtualBox
run: |
set -x
brew tap hashicorp/tap
brew install hashicorp/tap/hashicorp-vagrant
brew install --cask virtualbox
-
name: Check versions
name: Install vagrant
run: |
set -x
sudo apt-get update
sudo apt-get install -y libvirt-daemon libvirt-daemon-system vagrant vagrant-libvirt ruby-libvirt
sudo systemctl enable --now libvirtd
sudo chmod a+rw /var/run/libvirt/libvirt-sock
vagrant plugin install vagrant-libvirt
vagrant --version
VBoxManage -v
-
name: Set up vagrant
run: |
ln -sf hack/Vagrantfile.freebsd Vagrantfile
vagrant up --no-tty
-
name: Smoke test
Expand All @@ -233,7 +230,3 @@ jobs:
if: always()
run: |
vagrant ssh -- "sudo cat /vagrant/.tmp/logs/containerd"
-
name: Dump context
if: failure()
uses: crazy-max/ghaction-dump-context@v2
7 changes: 5 additions & 2 deletions cache/contenthash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
scanPath = resolvedPath
}

err = filepath.Walk(scanPath, func(itemPath string, fi os.FileInfo, err error) error {
walkFunc := func(itemPath string, fi os.FileInfo, err error) error {
if scanCounterEnable {
scanCounter.Add(1)
}
Expand Down Expand Up @@ -1073,7 +1073,10 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
txn.Insert(k, cr)
}
return nil
})
}

err = cc.walk(scanPath, walkFunc)

if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions cache/contenthash/checksum_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows
// +build !windows

package contenthash

import "path/filepath"

func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
return filepath.Walk(scanPath, walkFunc)
}
16 changes: 16 additions & 0 deletions cache/contenthash/checksum_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package contenthash

import (
"path/filepath"

"github.com/Microsoft/go-winio"
)

func (cc *cacheContext) walk(scanPath string, walkFunc filepath.WalkFunc) error {
// elevating the admin privileges to walk special files/directory
// like `System Volume Information`, etc. See similar in #4994
privileges := []string{winio.SeBackupPrivilege}
return winio.RunWithPrivileges(privileges, func() error {
return filepath.Walk(scanPath, walkFunc)
})
}
74 changes: 52 additions & 22 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4404,13 +4404,20 @@ COPY foo bar
}

func testMultiStageImplicitFrom(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
FROM scratch
COPY --from=busybox /etc/passwd test
`)
`, `
FROM nanoserver AS build
RUN echo test> test
FROM nanoserver
COPY --from=build /test /test
`,
))

dir := integration.Tmpdir(
t,
Expand Down Expand Up @@ -4439,17 +4446,25 @@ COPY --from=busybox /etc/passwd test

dt, err := os.ReadFile(filepath.Join(destDir, "test"))
require.NoError(t, err)
require.Contains(t, string(dt), "root")
require.Contains(t, string(dt), integration.UnixOrWindows("root", "test"))

// testing masked image will load actual stage

dockerfile = []byte(`
dockerfile = []byte(integration.UnixOrWindows(
`
FROM busybox AS golang
RUN mkdir -p /usr/bin && echo -n foo > /usr/bin/go
FROM scratch
COPY --from=golang /usr/bin/go go
`)
`, `
FROM nanoserver AS golang
RUN echo foo> go
FROM nanoserver
COPY --from=golang /go /go
`,
))

dir = integration.Tmpdir(
t,
Expand Down Expand Up @@ -4477,17 +4492,18 @@ COPY --from=golang /usr/bin/go go
}

func testMultiStageCaseInsensitive(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
FROM scratch AS STAge0
dockerfileStr := `
FROM %s AS STAge0
COPY foo bar
FROM scratch AS staGE1
FROM %s AS staGE1
COPY --from=staGE0 bar baz
FROM scratch
FROM %s
COPY --from=stage1 baz bax
`)
`
baseImage := integration.UnixOrWindows("scratch", "nanoserver")
dockerfile := []byte(fmt.Sprintf(dockerfileStr, baseImage, baseImage, baseImage))
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand Down Expand Up @@ -5496,10 +5512,10 @@ COPY --from=build out .
}

func testBuiltinArgs(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)

dockerfile := []byte(`
dockerfile := []byte(integration.UnixOrWindows(
`
FROM busybox AS build
ARG FOO
ARG BAR
Expand All @@ -5508,7 +5524,17 @@ RUN echo -n $HTTP_PROXY::$NO_PROXY::$FOO::$BAR::$BAZ > /out
FROM scratch
COPY --from=build /out /
`)
`, `
FROM nanoserver AS build
ARG FOO
ARG BAR
ARG BAZ=bazcontent
RUN echo %HTTP_PROXY%::%NO_PROXY%::%FOO%::%BAR%::%BAZ%> out
FROM nanoserver
COPY --from=build out /
`,
))

dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand Down Expand Up @@ -5543,7 +5569,9 @@ COPY --from=build /out /

dt, err := os.ReadFile(filepath.Join(destDir, "out"))
require.NoError(t, err)
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
// Windows can't interpret empty env variables, %BAR% handles empty values.
expectedStr := integration.UnixOrWindows(`hpvalue::npvalue::foocontents::::bazcontent`, "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
require.Equal(t, expectedStr, string(dt))

// repeat with changed default args should match the old cache
destDir = t.TempDir()
Expand All @@ -5570,7 +5598,8 @@ COPY --from=build /out /

dt, err = os.ReadFile(filepath.Join(destDir, "out"))
require.NoError(t, err)
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
expectedStr = integration.UnixOrWindows("hpvalue::npvalue::foocontents::::bazcontent", "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
require.Equal(t, expectedStr, string(dt))

// changing actual value invalidates cache
destDir = t.TempDir()
Expand All @@ -5597,7 +5626,8 @@ COPY --from=build /out /

dt, err = os.ReadFile(filepath.Join(destDir, "out"))
require.NoError(t, err)
require.Equal(t, "hpvalue2::::foocontents2::::bazcontent", string(dt))
expectedStr = integration.UnixOrWindows("hpvalue2::::foocontents2::::bazcontent", "hpvalue2::%NO_PROXY%::foocontents2::%BAR%::bazcontent\r\n")
require.Equal(t, expectedStr, string(dt))
}

func testTarContext(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -5713,15 +5743,15 @@ COPY foo bar
}

func testFrontendUseForwardedSolveResults(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

dockerfile := []byte(`
FROM scratch
dockerfileStr := `
FROM %s
COPY foo foo2
`)
`
dockerfile := []byte(fmt.Sprintf(dockerfileStr, integration.UnixOrWindows("scratch", "nanoserver")))
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
Expand Down
5 changes: 1 addition & 4 deletions hack/Vagrantfile.freebsd13 → hack/Vagrantfile.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.define "fbsd_13_2" do |fbsd_13_2|
fbsd_13_2.vm.box = "freebsd/FreeBSD-13.2-RELEASE"
end

config.vm.box = "generic/freebsd14"
config.vm.boot_timeout = 900
config.vm.synced_folder ".", "/vagrant", type: "rsync"
config.ssh.keep_alive = true
Expand Down

0 comments on commit b8d3322

Please sign in to comment.