From 33367587085258e4243fa039d7fbcca720e946c2 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 14 Aug 2019 12:51:43 -0700 Subject: [PATCH] disable starting the daemon on windows --- .drone.yml | 4 ++-- daemon.go | 26 ++++++++++++++++++++++++++ daemon_win.go | 10 ++++++++++ docker.go | 17 +---------------- docker/docker/Dockerfile.windows.1903 | 4 +++- 5 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 daemon.go create mode 100644 daemon_win.go diff --git a/.drone.yml b/.drone.yml index b33a826..0d3b2fe 100644 --- a/.drone.yml +++ b/.drone.yml @@ -59,7 +59,7 @@ steps: commands: # TODO use the new DRONE_SEMVER_SHORT environment variables to # publish docker images for tag events. - - go build -o release/windows/amd64/drone-docker.exe + - go build -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker - docker login -u $env:USERNAME -p $env:PASSWORD - docker build -f docker/docker/Dockerfile.windows.1809 -t plugins/docker:windows-1809-amd64 . - docker push plugins/docker:windows-1809-amd64 @@ -97,7 +97,7 @@ steps: commands: # TODO use the new DRONE_SEMVER_SHORT environment variables to # publish docker images for tag events. - - go build -o release/windows/amd64/drone-docker.exe + - go build -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker - docker login -u $env:USERNAME -p $env:PASSWORD - docker build -f docker/docker/Dockerfile.windows.1903 -t plugins/docker:windows-1903-amd64 . - docker push plugins/docker:windows-1903-amd64 diff --git a/daemon.go b/daemon.go new file mode 100644 index 0000000..5bf1119 --- /dev/null +++ b/daemon.go @@ -0,0 +1,26 @@ +// +build !windows + +package docker + +import ( + "io/ioutil" + "os" +) + +const dockerExe = "/usr/local/bin/docker" +const dockerdExe = "/usr/local/bin/dockerd" + +func (p Plugin) startDaemon() { + cmd := commandDaemon(p.Daemon) + if p.Daemon.Debug { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + } else { + cmd.Stdout = ioutil.Discard + cmd.Stderr = ioutil.Discard + } + go func() { + trace(cmd) + cmd.Run() + }() +} \ No newline at end of file diff --git a/daemon_win.go b/daemon_win.go new file mode 100644 index 0000000..062cf5e --- /dev/null +++ b/daemon_win.go @@ -0,0 +1,10 @@ +// +build windows + +package docker + +const dockerExe = "C:\\bin\\docker.exe" +const dockerdExe = "" + +func (p Plugin) startDaemon() { + // this is a no-op on windows +} diff --git a/docker.go b/docker.go index e6e5386..9c2a136 100644 --- a/docker.go +++ b/docker.go @@ -2,7 +2,6 @@ package docker import ( "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -69,18 +68,7 @@ type ( func (p Plugin) Exec() error { // start the Docker daemon server if !p.Daemon.Disabled { - cmd := commandDaemon(p.Daemon) - if p.Daemon.Debug { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - } else { - cmd.Stdout = ioutil.Discard - cmd.Stderr = ioutil.Discard - } - go func() { - trace(cmd) - cmd.Run() - }() + p.startDaemon() } // poll the docker daemon until it is started. This ensures the daemon is @@ -154,9 +142,6 @@ func (p Plugin) Exec() error { return nil } -const dockerExe = "/usr/local/bin/docker" -const dockerdExe = "/usr/local/bin/dockerd" - // helper function to create the docker login command. func commandLogin(login Login) *exec.Cmd { if login.Email != "" { diff --git a/docker/docker/Dockerfile.windows.1903 b/docker/docker/Dockerfile.windows.1903 index b0d03ad..a6eadef 100644 --- a/docker/docker/Dockerfile.windows.1903 +++ b/docker/docker/Dockerfile.windows.1903 @@ -13,7 +13,8 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl Invoke-WebRequest $('https://github.com/docker/toolbox/releases/download/v{0}/DockerToolbox-{0}.exe' -f $env:DOCKER_VERSION) -OutFile 'dockertoolbox.exe' -UseBasicParsing RUN /innoextract.exe dockertoolbox.exe -FROM mcr.microsoft.com/windows/servercore:1903 +FROM mcr.microsoft.com/windows/nanoserver:1903 +USER ContainerAdministrator LABEL maintainer="Drone.IO Community " ` org.label-schema.name="Drone Docker" ` @@ -21,6 +22,7 @@ LABEL maintainer="Drone.IO Community " ` org.label-schema.schema-version="1.0" RUN mkdir C:\bin +COPY --from=download /windows/system32/netapi32.dll /windows/system32/netapi32.dll COPY --from=download /app/docker.exe C:/bin/docker.exe ADD release/windows/amd64/drone-docker.exe C:/bin/drone-docker.exe ENTRYPOINT [ "C:\\bin\\drone-docker.exe" ]