Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#137] FreeBSD support #361

Merged
merged 3 commits into from Sep 21, 2021

Conversation

akhramov
Copy link
Contributor

Now that containerd supports FreeBSD, we can port nerdctl, too!
🚀. For full-fledged functionality, we will need to port

  • buildkit. Status: POC is ready, need to upstream fixes to
    dependencies.
  • runtime + containerd shim. runj/knast should work just fine.
  • CNI bridge plugin for networking.

This change fixes FreeBSD compilation errors by renaming linux files
to unix where necessary, or otherwise introducing FreeBSD versions for
the necessary files.

Signed-off-by: Artem Khramov akhramov@pm.me

@akhramov akhramov force-pushed the feature/FreeBSD-support branch 4 times, most recently from 1ca61e2 to 14b0025 Compare September 15, 2021 11:11
@AkihiroSuda
Copy link
Member

Thanks for working on this.

Could you update make artifacts to cross-compile GOOS=freebsd GOARCH=amd64 binary on GitHub Actions?

nerdctl/Makefile

Lines 83 to 84 in 95dd996

GOOS=windows GOARCH=amd64 make -C $(CURDIR) binaries
tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-windows-amd64.tar.gz _output/nerdctl.exe

Also please add docs/freebsd.md to clarify the installation steps, usage, and the known limitations.

Eventually we should have CI, but it can be another PR if it is difficult.
We can use Cirrus CI to run FreeBSD virtual machines. https://cirrus-ci.org/guide/FreeBSD/

return
}

func bashCompleteNamespaceNames(clicontext *cli.Context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code shouldn't be OS-dependent

return
}

func bashCompleteSnapshotterNames(clicontext *cli.Context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code shouldn't be OS-dependent

WithoutRunMount(), // unmount default tmpfs on "/run": https://github.com/containerd/nerdctl/issues/157
)

if runtime.GOOS != "freebsd" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: runtime.GOOS == "linux" would be more accurate check

}

func WithoutRunMount() func(ctx context.Context, client oci.Client, c *containers.Container, s *oci.Spec) error {
// not valid on windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not windows

)

func runBashComplete(clicontext *cli.Context) {
// noop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be noop, but can be deferred to another PR

gocni "github.com/containerd/go-cni"
)

const AppArmorProfileName = "nerdctl-default"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be empty.

Eventually this variable should be only referred from *_linux.go, though.


// DefaultPropagationMode is the default propagation of mounts
// where user doesn't specify mount propagation explicitly.
// See also: https://github.com/moby/moby/blob/v20.10.7/volume/mounts/windows_parser.go#L440-L442
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not windows

@AkihiroSuda
Copy link
Member

Probably we need to update

if strings.HasPrefix(runtimeStr, "io.containerd.") {
too, if we want to support wtf.sbk.runj.v1

@AkihiroSuda
Copy link
Member

cc @samuelkarp

@AkihiroSuda AkihiroSuda added this to the v0.12.0 milestone Sep 16, 2021
@akhramov akhramov force-pushed the feature/FreeBSD-support branch 6 times, most recently from 4e87563 to 856eaf8 Compare September 17, 2021 17:33
@@ -747,7 +752,7 @@ func withCustomHosts(src string) func(context.Context, oci.Client, *containers.C
}

func generateLogURI(dataStore string) (*url.URL, error) {
selfExe, err := os.Readlink("/proc/self/exe")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda This seems to be os-specific. is -d broken now on windows?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nerdctl run on Windows is completely WIP (help wanted)
#197

@@ -161,3 +161,21 @@ jobs:
command: ssh default -- "CONTAINERD_SNAPSHOTTER=fuse-overlayfs /vagrant/nerdctl.test -test.v -test.kill-daemon"
- name: "Uninstall rootless containerd"
run: ssh default -- containerd-rootless-setuptool.sh uninstall

test-unit-freebsd-amd64:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda Instead of using Cirrus, we can run FreeBSD jobs in GH actions this way. What do you think?

cmd/nerdctl/run_freebsd.go Outdated Show resolved Hide resolved
@akhramov
Copy link
Contributor Author

@AkihiroSuda thanks for the thorough review.

I'm going to focus on resolving the crosscompilation issue.

Also I would like to hear your input on doc -- I wasn't sure what to put there.

@akhramov akhramov force-pushed the feature/FreeBSD-support branch 2 times, most recently from 1aa2823 to 55768c3 Compare September 19, 2021 09:50
ln -sf hack/Vagrantfile Vagrantfile
vagrant up ${{ matrix.box }}
- name: "Run unit tests"
run: vagrant ssh ${{ matrix.box }} -- "cd /vagrant; go test -v ./pkg/..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would is be possible to run nerdctl run SOME-IMAGE echo hello here?


// executablePath returns the absolute path to the current binary
func executablePath() (string, error) {
return filepath.Abs(os.Args[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akhramov akhramov force-pushed the feature/FreeBSD-support branch 7 times, most recently from 42886b4 to e69cc74 Compare September 21, 2021 10:06
@AkihiroSuda
Copy link
Member

AkihiroSuda commented Sep 21, 2021

9s
Run vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'freebsd/FreeBSD-13.0-STABLE' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'freebsd/FreeBSD-13.0-STABLE'
    default: URL: https://vagrantcloud.com/freebsd/FreeBSD-13.0-STABLE
==> default: Adding box 'freebsd/FreeBSD-13.0-STABLE' (v2021.09.16) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/freebsd/boxes/FreeBSD-13.0-STABLE/versions/2021.09.16/providers/virtualbox.box

Progress: 0% (Rate: 0*/s, Estimated time remaining: --:--:--)
Progress: 100% (Rate: 635/s, Estimated time remaining: --:--:--)
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

The requested URL returned error: 429

vagrant up seems extremely flaky.
Could you mirror the image to somewhere more stable, or could you use Cirrus instead of Vagrant?

@akhramov
Copy link
Contributor Author

@AkihiroSuda indeed it's flaky. I'm sorry for the notifications mess I caused. I mitigated the problem using the cache action.

Let's test that, otherwise I'll set up a Cirrus pipeline.

with:
path: ~/.vagrant.d/boxes
key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
restore-keys: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different from key?

config.vm.provision "shell", inline: <<-SHELL
pkg bootstrap
pkg install -y go containerd runj
cp /usr/local/bin/containerd-shim-runj-v1 /usr/local/bin/containerd-shim-runc-v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks slightly invalid.
I’d suggest just setting the default runtime to runj

@akhramov akhramov force-pushed the feature/FreeBSD-support branch 2 times, most recently from 7521254 to b0ad974 Compare September 21, 2021 12:41
Now that containerd supports FreeBSD, we can port nerdctl, too!
:rocket:. For full-fledged functionality, we will need to port

* buildkit. Status: POC is ready, need to upstream fixes to
  dependencies.
* runtime + containerd shim. runj/knast should work just fine.
* CNI bridge plugin for networking.

This change fixes FreeBSD compilation errors by renaming linux files
to unix where necessary, or otherwise introducing FreeBSD versions for
the necessary files.

Signed-off-by: Artem Khramov <akhramov@pm.me>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed follow-up commits.

LGTM if green.

Thanks!

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@AkihiroSuda
Copy link
Member

AkihiroSuda commented Sep 21, 2021

CI seems flaky.

Can be fixed later, though

time="2021-09-21T14:19:05Z" level=fatal msg="failed to create shim: failed to mount rootfs component &{nullfs /var/lib/containerd/io.containerd.snapshotter.v1.native/snapshots/3 [rw]}: mount [[-o rw -t nullfs /var/lib/containerd/io.containerd.snapshotter.v1.native/snapshots/3 /run/containerd/io.containerd.runtime.v2.task/default/70886b2a11483b463360ab4f419294075698a64754c02bc1dda57fc642e60ba9/rootfs]] failed: "mount_nullfs: /run/containerd/io.containerd.runtime.v2.task/default/70886b2a11483b463360ab4f419294075698a64754c02bc1dda57fc642e60ba9/rootfs: Resource deadlock avoided\n": exit status 1: unknown"

@leandroscardua
Copy link

Hi Team,

Any update on the FreeBSD support on ContainerD/nerdctl?

@gmshake
Copy link

gmshake commented May 7, 2022

@leandroscardua
There is a known issue #868 and WIP PR to resolve it: moby/sys#114 .
Hopefully nerdctl on FreeBSD can work smoothly when the issue is resolved.

@leandroscardua
Copy link

Thank you for the information @gmshake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants