Skip to content

Commit

Permalink
Add macOS support
Browse files Browse the repository at this point in the history
Signed-off-by: Marat Radchenko <[email protected]>
  • Loading branch information
slonopotamus committed Sep 28, 2023
1 parent 4c89091 commit 2739a7f
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 51 deletions.
4 changes: 2 additions & 2 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ func checkDescriptor(ctx context.Context, t *testing.T, cs content.Store, desc o
}

func TestMergeOp(t *testing.T) {
if runtime.GOOS == "windows" || runtime.GOOS == "freebsd" {
if runtime.GOOS != "linux" {
t.Skipf("Depends on unimplemented merge-op support on %s", runtime.GOOS)
}

Expand Down Expand Up @@ -2141,7 +2141,7 @@ func TestMergeOp(t *testing.T) {
}

func TestDiffOp(t *testing.T) {
if runtime.GOOS == "windows" || runtime.GOOS == "freebsd" {
if runtime.GOOS != "linux" {
t.Skipf("Depends on unimplemented diff-op support on %s", runtime.GOOS)
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/buildkitd/constants_unix.go

This file was deleted.

5 changes: 0 additions & 5 deletions cmd/buildkitd/constants_windows.go

This file was deleted.

7 changes: 2 additions & 5 deletions cmd/buildkitd/main_containerd_worker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build linux || windows || freebsd
// +build linux windows freebsd

package main

import (
Expand Down Expand Up @@ -45,7 +42,7 @@ func init() {
}

if defaultConf.Workers.Containerd.Address == "" {
defaultConf.Workers.Containerd.Address = defaultContainerdAddress
defaultConf.Workers.Containerd.Address = defaults.DefaultAddress
}

if defaultConf.Workers.Containerd.Namespace == "" {
Expand Down Expand Up @@ -180,7 +177,7 @@ func init() {

func applyContainerdFlags(c *cli.Context, cfg *config.Config) error {
if cfg.Workers.Containerd.Address == "" {
cfg.Workers.Containerd.Address = defaultContainerdAddress
cfg.Workers.Containerd.Address = defaults.DefaultAddress
}

if c.GlobalIsSet("containerd-worker") {
Expand Down
61 changes: 61 additions & 0 deletions executor/oci/spec_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package oci

import (
"github.com/containerd/containerd/oci"
"github.com/docker/docker/pkg/idtools"
"github.com/moby/buildkit/solver/pb"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)

func withProcessArgs(args ...string) oci.SpecOpts {
return oci.WithProcessArgs(args...)
}

func generateMountOpts(resolvConf, hostsFile string) ([]oci.SpecOpts, error) {
return nil, nil
}

// generateSecurityOpts may affect mounts, so must be called after generateMountOpts
func generateSecurityOpts(mode pb.SecurityMode, apparmorProfile string, selinuxB bool) ([]oci.SpecOpts, error) {
if mode == pb.SecurityMode_INSECURE {
return nil, errors.New("no support for running in insecure mode on Darwin")
}
return nil, nil
}

// generateProcessModeOpts may affect mounts, so must be called after generateMountOpts
func generateProcessModeOpts(mode ProcessMode) ([]oci.SpecOpts, error) {
if mode == NoProcessSandbox {
return nil, errors.New("no support for NoProcessSandbox on Darwin")
}
return nil, nil
}

func generateIDmapOpts(idmap *idtools.IdentityMapping) ([]oci.SpecOpts, error) {
if idmap == nil {
return nil, nil
}
return nil, errors.New("no support for IdentityMapping on Darwin")
}

func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) {
if len(ulimits) == 0 {
return nil, nil
}
return nil, errors.New("no support for POSIXRlimit on Darwin")
}

// tracing is not implemented on Darwin
func getTracingSocketMount(socket string) *specs.Mount {
return nil
}

// tracing is not implemented on Darwin
func getTracingSocket() string {
return ""
}

func cgroupNamespaceSupported() bool {
return false
}
3 changes: 1 addition & 2 deletions hack/Vagrantfile.freebsd13
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ Vagrant.configure("2") do |config|
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
mkdir -p /run/buildkit
daemon -o /vagrant/.tmp/logs/buildkitd /usr/local/bin/buildkitd --addr=unix:///run/buildkit/buildkitd.sock
daemon -o /vagrant/.tmp/logs/buildkitd /usr/local/bin/buildkitd
sleep 3
SHELL
end
Expand Down
17 changes: 0 additions & 17 deletions snapshot/diffapply_freebsd.go

This file was deleted.

3 changes: 0 additions & 3 deletions snapshot/diffapply_unix.go → snapshot/diffapply_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows && !freebsd
// +build !windows,!freebsd

package snapshot

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//go:build windows
// +build windows
//go:build !linux

package snapshot

import (
"context"
"runtime"

"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/snapshots"
"github.com/pkg/errors"
)

func (sn *mergeSnapshotter) diffApply(ctx context.Context, dest Mountable, diffs ...Diff) (_ snapshots.Usage, rerr error) {
return snapshots.Usage{}, errors.New("diffApply not yet supported on windows")
return snapshots.Usage{}, errors.New("diffApply not yet supported on " + runtime.GOOS)
}

func needsUserXAttr(ctx context.Context, sn Snapshotter, lm leases.Manager) (bool, error) {
return false, errors.New("needs userxattr not supported on windows")
return false, errors.New("needs userxattr not supported on " + runtime.GOOS)
}
67 changes: 67 additions & 0 deletions snapshot/localmounter_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package snapshot

import (
"golang.org/x/sys/unix"
"os"

"github.com/containerd/containerd/mount"
"github.com/pkg/errors"
)

func (lm *localMounter) Mount() (string, error) {
lm.mu.Lock()
defer lm.mu.Unlock()

if lm.mounts == nil && lm.mountable != nil {
mounts, release, err := lm.mountable.Mount()
if err != nil {
return "", err
}
lm.mounts = mounts
lm.release = release
}

if len(lm.mounts) == 1 && lm.mounts[0].Type == "bind" {
ro := false
for _, opt := range lm.mounts[0].Options {
if opt == "ro" {
ro = true
break
}
}
if !ro {
return lm.mounts[0].Source, nil
}
}

dir, err := os.MkdirTemp("", "buildkit-mount")
if err != nil {
return "", errors.Wrap(err, "failed to create temp dir")
}

if err := mount.All(lm.mounts, dir); err != nil {
os.RemoveAll(dir)
return "", errors.Wrapf(err, "failed to mount %s: %+v", dir, lm.mounts)
}
lm.target = dir
return dir, nil
}

func (lm *localMounter) Unmount() error {
lm.mu.Lock()
defer lm.mu.Unlock()

if lm.target != "" {
if err := mount.UnmountRecursive(lm.target, unix.MNT_FORCE); err != nil {
return err
}
os.RemoveAll(lm.target)
lm.target = ""
}

if lm.release != nil {
return lm.release()
}

return nil
}
12 changes: 12 additions & 0 deletions source/git/source_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package git

import (
"context"
"errors"
"os/exec"
"runtime"
)

func runWithStandardUmask(ctx context.Context, cmd *exec.Cmd) error {
return errors.New("runWithStandardUmask not supported on " + runtime.GOOS)
}
3 changes: 0 additions & 3 deletions source/git/source_unix.go → source/git/source_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows && !freebsd
// +build !windows,!freebsd

package git

import (
Expand Down
6 changes: 6 additions & 0 deletions util/appdefaults/appdefaults_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package appdefaults

const (
Address = "unix:///run/buildkit/buildkitd.sock"
traceSocketPath = "/run/buildkit/otel-grpc.sock"
)
3 changes: 1 addition & 2 deletions util/appdefaults/appdefaults_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

const (
Address = "unix:///run/buildkit/buildkitd.sock"
Root = "/var/lib/buildkit"
ConfigDir = "/etc/buildkit"
DefaultCNIBinDir = "/opt/cni/bin"
Expand Down Expand Up @@ -78,5 +77,5 @@ func TraceSocketPath(inUserNS bool) string {
return filepath.Join(dirs[0], "buildkit", "otel-grpc.sock")
}
}
return "/run/buildkit/otel-grpc.sock"
return traceSocketPath
}
8 changes: 8 additions & 0 deletions util/appdefaults/appdefaults_unix_nonlinux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !linux && !windows

package appdefaults

const (
Address = "unix:///var/run/buildkit/buildkitd.sock"
traceSocketPath = "/var/run/buildkit/otel-grpc.sock"
)

0 comments on commit 2739a7f

Please sign in to comment.