Skip to content

Commit 408e432

Browse files
authored
Merge pull request moby#2376 from akhramov/feature/freebsd-port
FreeBSD port
2 parents 964dd90 + c415d85 commit 408e432

File tree

20 files changed

+373
-25
lines changed

20 files changed

+373
-25
lines changed

.github/workflows/test-os.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ jobs:
8585
with:
8686
name: test-reports
8787
path: ./bin/testreports
88+
89+
test-freebsd-amd64:
90+
runs-on: macos-12
91+
env:
92+
VAGRANT_VAGRANTFILE: hack/Vagrantfile.freebsd13
93+
steps:
94+
-
95+
name: Checkout
96+
uses: actions/checkout@v2
97+
-
98+
name: Cache Vagrant boxes
99+
uses: actions/cache@v2
100+
with:
101+
path: ~/.vagrant.d/boxes
102+
key: ${{ runner.os }}-vagrant-${{ hashFiles('hack/Vagrantfile.freebsd13') }}
103+
restore-keys: |
104+
${{ runner.os }}-vagrant-
105+
-
106+
name: Set up vagrant
107+
run: vagrant up
108+
-
109+
name: Integration smoke test
110+
run: |
111+
vagrant ssh -- "cp /vagrant/hack/dockerfiles/freebsd-smoke.Dockerfile /vagrant/cmd/buildctl/Dockerfile"
112+
vagrant ssh -- "cd /vagrant/cmd/buildctl; go run . build --frontend dockerfile.v0 --local context=. --local dockerfile=."

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ COPY --link --from=buildctl /usr/bin/buildctl /
116116
FROM scratch AS binaries-windows
117117
COPY --link --from=buildctl /usr/bin/buildctl /buildctl.exe
118118

119+
FROM scratch AS binaries-freebsd
120+
COPY --link --from=buildkitd /usr/bin/buildkitd /
121+
COPY --link --from=buildctl /usr/bin/buildctl /
122+
119123
FROM binaries-$TARGETOS AS binaries
120124
# enable scanning for this stage
121125
ARG BUILDKIT_SBOM_SCAN_STAGE=true
@@ -215,6 +219,9 @@ ENTRYPOINT ["buildkitd"]
215219

216220
FROM binaries AS buildkit-darwin
217221

222+
FROM binaries AS buildkit-freebsd
223+
ENTRYPOINT ["/buildkitd"]
224+
218225
FROM binaries AS buildkit-windows
219226
# this is not in binaries-windows because it is not intended for release yet, just CI
220227
COPY --link --from=buildkitd /usr/bin/buildkitd /buildkitd.exe

cache/contenthash/filehash_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func setUnixOpt(path string, fi os.FileInfo, stat *fstypes.Stat) error {
2020
stat.Gid = s.Gid
2121

2222
if !fi.IsDir() {
23-
if s.Mode&syscall.S_IFBLK != 0 ||
24-
s.Mode&syscall.S_IFCHR != 0 {
23+
if s.Mode&syscall.S_IFLNK == 0 && (s.Mode&syscall.S_IFBLK != 0 ||
24+
s.Mode&syscall.S_IFCHR != 0) {
2525
stat.Devmajor = int64(unix.Major(uint64(s.Rdev)))
2626
stat.Devminor = int64(unix.Minor(uint64(s.Rdev)))
2727
}

cache/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,8 @@ func checkDescriptor(ctx context.Context, t *testing.T, cs content.Store, desc o
20222022
}
20232023

20242024
func TestMergeOp(t *testing.T) {
2025-
if runtime.GOOS == "windows" {
2026-
t.Skip("Depends on unimplemented merge-op support on Windows")
2025+
if runtime.GOOS == "windows" || runtime.GOOS == "freebsd" {
2026+
t.Skipf("Depends on unimplemented merge-op support on %s", runtime.GOOS)
20272027
}
20282028

20292029
// This just tests the basic Merge method and some of the logic with releasing merge refs.
@@ -2140,8 +2140,8 @@ func TestMergeOp(t *testing.T) {
21402140
}
21412141

21422142
func TestDiffOp(t *testing.T) {
2143-
if runtime.GOOS == "windows" {
2144-
t.Skip("Depends on unimplemented diff-op support on Windows")
2143+
if runtime.GOOS == "windows" || runtime.GOOS == "freebsd" {
2144+
t.Skipf("Depends on unimplemented diff-op support on %s", runtime.GOOS)
21452145
}
21462146

21472147
// This just tests the basic Diff method and some of the logic with releasing diff refs.

cmd/buildkitd/main_containerd_worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build linux || windows
2-
// +build linux windows
1+
//go:build linux || windows || freebsd
2+
// +build linux windows freebsd
33

44
package main
55

docs/freebsd.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Experimental FreeBSD support
2+
3+
Buildkit also has experimental FreeBSD support. The container infrastructure on FreeBSD is still at an early stage, so problems may occur.
4+
5+
Dependencies:
6+
7+
- [runj](https://github.com/samuelkarp/runj)
8+
- [containerd](https://github.com/containerd/containerd)
9+
10+
These dependencies can be installed from the ports tree, or using the `pkg` command:
11+
12+
```csh
13+
% pkg install containerd runj
14+
```
15+
16+
For BuildKit build instructions see [`..github/CONTRIBUTING.md`](../.github/CONTRIBUTING.md).

executor/containerdexecutor/executor.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"path/filepath"
8+
"runtime"
89
"sync"
910
"syscall"
1011
"time"
@@ -209,11 +210,20 @@ func (w *containerdExecutor) Run(ctx context.Context, id string, root executor.M
209210
cioOpts = append(cioOpts, cio.WithTerminal)
210211
}
211212

212-
task, err := container.NewTask(ctx, cio.NewCreator(cioOpts...), containerd.WithRootFS([]mount.Mount{{
213+
rootfs := containerd.WithRootFS([]mount.Mount{{
213214
Source: rootfsPath,
214215
Type: "bind",
215216
Options: []string{"rbind"},
216-
}}))
217+
}})
218+
if runtime.GOOS == "freebsd" {
219+
rootfs = containerd.WithRootFS([]mount.Mount{{
220+
Source: rootfsPath,
221+
Type: "nullfs",
222+
Options: []string{},
223+
}})
224+
}
225+
226+
task, err := container.NewTask(ctx, cio.NewCreator(cioOpts...), rootfs)
217227
if err != nil {
218228
return nil, err
219229
}

executor/oci/spec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
197197
}
198198

199199
if tracingSocket != "" {
200-
s.Mounts = append(s.Mounts, getTracingSocketMount(tracingSocket))
200+
if mount := getTracingSocketMount(tracingSocket); mount != nil {
201+
s.Mounts = append(s.Mounts, *mount)
202+
}
201203
}
202204

203205
s.Mounts = dedupMounts(s.Mounts)

executor/oci/spec_freebsd.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package oci
2+
3+
import (
4+
"github.com/containerd/containerd/oci"
5+
"github.com/docker/docker/pkg/idtools"
6+
"github.com/moby/buildkit/solver/pb"
7+
specs "github.com/opencontainers/runtime-spec/specs-go"
8+
"github.com/pkg/errors"
9+
)
10+
11+
func generateMountOpts(resolvConf, hostsFile string) ([]oci.SpecOpts, error) {
12+
return nil, nil
13+
}
14+
15+
// generateSecurityOpts may affect mounts, so must be called after generateMountOpts
16+
func generateSecurityOpts(mode pb.SecurityMode, apparmorProfile string, selinuxB bool) ([]oci.SpecOpts, error) {
17+
if mode == pb.SecurityMode_INSECURE {
18+
return nil, errors.New("no support for running in insecure mode on FreeBSD")
19+
}
20+
return nil, nil
21+
}
22+
23+
// generateProcessModeOpts may affect mounts, so must be called after generateMountOpts
24+
func generateProcessModeOpts(mode ProcessMode) ([]oci.SpecOpts, error) {
25+
if mode == NoProcessSandbox {
26+
return nil, errors.New("no support for NoProcessSandbox on FreeBSD")
27+
}
28+
return nil, nil
29+
}
30+
31+
func generateIDmapOpts(idmap *idtools.IdentityMapping) ([]oci.SpecOpts, error) {
32+
if idmap == nil {
33+
return nil, nil
34+
}
35+
return nil, errors.New("no support for IdentityMapping on FreeBSD")
36+
}
37+
38+
func generateRlimitOpts(ulimits []*pb.Ulimit) ([]oci.SpecOpts, error) {
39+
if len(ulimits) == 0 {
40+
return nil, nil
41+
}
42+
return nil, errors.New("no support for POSIXRlimit on FreeBSD")
43+
}
44+
45+
// tracing is not implemented on FreeBSD
46+
func getTracingSocketMount(socket string) *specs.Mount {
47+
return nil
48+
}
49+
50+
// tracing is not implemented on FreeBSD
51+
func getTracingSocket() string {
52+
return ""
53+
}
54+
55+
func cgroupNamespaceSupported() bool {
56+
return false
57+
}

executor/oci/spec_unix.go renamed to executor/oci/spec_linux.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build !windows
2-
// +build !windows
3-
41
package oci
52

63
import (
@@ -134,8 +131,8 @@ func withDefaultProfile() oci.SpecOpts {
134131
}
135132
}
136133

137-
func getTracingSocketMount(socket string) specs.Mount {
138-
return specs.Mount{
134+
func getTracingSocketMount(socket string) *specs.Mount {
135+
return &specs.Mount{
139136
Destination: tracingSocketPath,
140137
Type: "bind",
141138
Source: socket,

0 commit comments

Comments
 (0)