Skip to content

Commit d826beb

Browse files
Add Windows service support
This branch adds the abilitity to run buildkitd as a Windows service. Most of this code is shared with dockerd and containerd, with slight changes to adapt it to buildkit. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent b0c05cd commit d826beb

File tree

10 files changed

+1435
-0
lines changed

10 files changed

+1435
-0
lines changed

cmd/buildkitd/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func main() {
199199
},
200200
)
201201
app.Flags = append(app.Flags, appFlags...)
202+
app.Flags = append(app.Flags, serviceFlags()...)
202203

203204
app.Action = func(c *cli.Context) error {
204205
// TODO: On Windows this always returns -1. The actual "are you admin" check is very Windows-specific.
@@ -254,6 +255,15 @@ func main() {
254255
return errors.Wrapf(err, "failed to create %s", root)
255256
}
256257

258+
// Stop if we are registering or unregistering against Windows SCM.
259+
stop, err := registerUnregisterService(cfg.Root)
260+
if err != nil {
261+
logrus.Fatal(err)
262+
}
263+
if stop {
264+
return nil
265+
}
266+
257267
lockPath := filepath.Join(root, "buildkitd.lock")
258268
lock := flock.New(lockPath)
259269
locked, err := lock.TryLock()
@@ -291,6 +301,12 @@ func main() {
291301
}
292302
}
293303
}
304+
305+
// Launch as a Windows Service if necessary
306+
if err := launchService(server); err != nil {
307+
logrus.Fatal(err)
308+
}
309+
294310
errCh := make(chan error, 1)
295311
if err := serveGRPC(cfg.GRPC, server, errCh); err != nil {
296312
return err
@@ -486,6 +502,8 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
486502
if tlsca := c.String("tlscacert"); tlsca != "" {
487503
cfg.GRPC.TLS.CA = tlsca
488504
}
505+
applyPlatformFlags(c)
506+
489507
return nil
490508
}
491509

cmd/buildkitd/service_unix.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package main
5+
6+
import (
7+
"github.com/urfave/cli"
8+
"google.golang.org/grpc"
9+
)
10+
11+
// serviceFlags returns an array of flags for configuring buildkitd to run
12+
// as a service. Only relevant on Windows.
13+
func serviceFlags() []cli.Flag {
14+
return []cli.Flag{}
15+
}
16+
17+
// applyPlatformFlags applies platform-specific flags.
18+
func applyPlatformFlags(context *cli.Context) {
19+
}
20+
21+
// registerUnregisterService is only relevant on Windows.
22+
func registerUnregisterService(root string) (bool, error) {
23+
return false, nil
24+
}
25+
26+
// launchService is only relevant on Windows.
27+
func launchService(s *grpc.Server) error {
28+
return nil
29+
}

0 commit comments

Comments
 (0)