forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buildkit code is mostly generic enough to support FreeBSD, however there are some quirks / infrastructural pieces that need to be addressed for full support, to name some - contenthash.NewFromStat attempts to set Devmajor / Devminor for regular files, assuming that RDev is zero for regular files. Unlike on Linux, it's not the case for FreeBSD. - containerdexecutor.Run uses bind mounts for rootfs. Bind mounts are not supported in FreeBSD and we should use nullfs instead - There is no CI job to run tests on FreeBSD - Some dependencies weren't ported This change ports buildkit to FreeBSD Signed-off-by: Artem Khramov <[email protected]> Co-authored-by: Akihiro Suda <[email protected]>
- Loading branch information
1 parent
4733c51
commit c415d85
Showing
20 changed files
with
373 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Experimental FreeBSD support | ||
|
||
Buildkit also has experimental FreeBSD support. The container infrastructure on FreeBSD is still at an early stage, so problems may occur. | ||
|
||
Dependencies: | ||
|
||
- [runj](https://github.com/samuelkarp/runj) | ||
- [containerd](https://github.com/containerd/containerd) | ||
|
||
These dependencies can be installed from the ports tree, or using the `pkg` command: | ||
|
||
```csh | ||
% pkg install containerd runj | ||
``` | ||
|
||
For BuildKit build instructions see [`..github/CONTRIBUTING.md`](../.github/CONTRIBUTING.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 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 FreeBSD") | ||
} | ||
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 FreeBSD") | ||
} | ||
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 FreeBSD") | ||
} | ||
|
||
func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) { | ||
if len(ulimits) == 0 { | ||
return nil, nil | ||
} | ||
return nil, errors.New("no support for POSIXRlimit on FreeBSD") | ||
} | ||
|
||
// tracing is not implemented on FreeBSD | ||
func getTracingSocketMount(socket string) *specs.Mount { | ||
return nil | ||
} | ||
|
||
// tracing is not implemented on FreeBSD | ||
func getTracingSocket() string { | ||
return "" | ||
} | ||
|
||
func cgroupNamespaceSupported() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This code is taken from the Vagrantfile from libjail-rs | ||
# https://github.com/fubarnetes/libjail-rs/blob/727353bd6565c5e7a9be2664258d0197a1c8bb35/Vagrantfile | ||
# licensed under BSD-3 Clause License: | ||
# BSD 3-Clause License | ||
|
||
# Copyright (c) 2018, Fabian Freyer <[email protected]> All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
# * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
Vagrant.configure("2") do |config| | ||
# Stable version | ||
# | ||
config.vm.define "fbsd_13_2" do |fbsd_13_2| | ||
fbsd_13_2.vm.box = "freebsd/FreeBSD-13.2-RELEASE" | ||
end | ||
|
||
config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__auto: true | ||
|
||
config.vm.provision "shell", inline: <<-SHELL | ||
kldload nullfs | ||
echo 'FreeBSD: { url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest" }' > /usr/local/etc/pkg/repos/FreeBSD.conf | ||
|
||
pkg bootstrap | ||
pkg install -y go git containerd runj wait_on | ||
|
||
mkdir -p /vagrant/coverage | ||
daemon -o /var/log/containerd.log containerd | ||
|
||
mkdir -p /run/buildkit | ||
cd /vagrant/cmd/buildkitd | ||
go build -buildvcs=false . | ||
echo "launching buildkitd..." | ||
mkdir -p /run/buildkit | ||
daemon ./buildkitd | ||
wait_on -t 5 /run/buildkit | ||
echo "launched buildkitd" | ||
SHELL | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM dougrabson/freebsd-minimal:13.1 | ||
|
||
RUN echo "Hello, buildkit!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package snapshot | ||
|
||
import ( | ||
"context" | ||
|
||
"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 FreeBSD") | ||
} | ||
|
||
func needsUserXAttr(ctx context.Context, sn Snapshotter, lm leases.Manager) (bool, error) { | ||
return false, errors.New("needs userxattr not supported on FreeBSD") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package snapshot | ||
|
||
import ( | ||
"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 == "nullfs" { | ||
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.Unmount(lm.target, 0); err != nil { | ||
return err | ||
} | ||
os.RemoveAll(lm.target) | ||
lm.target = "" | ||
} | ||
|
||
if lm.release != nil { | ||
return lm.release() | ||
} | ||
|
||
return nil | ||
} |
3 changes: 0 additions & 3 deletions
3
snapshot/localmounter_unix.go → snapshot/localmounter_linux.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package snapshot | ||
|
||
import ( | ||
|
Oops, something went wrong.