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

Add FreeBSD support #357

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/umoci.cov*
/.cache
/release
*.swp
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ RUN zypper -n in \
python-xattr \
runc \
skopeo \
tar
tar \
which
RUN useradd -u 1000 -m -d /home/rootless -s /bin/bash rootless

ENV GOPATH=/go PATH=/go/bin:$PATH
Expand Down
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# limitations under the License.

# Use bash, so that we can do process substitution.
SHELL = /bin/bash
SHELL := $(shell which bash)

# Go tools.
GO ?= go
GO_MD2MAN ?= go-md2man
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
export GO111MODULE=on

# Set up the ... lovely ... GOPATH hacks.
Expand Down Expand Up @@ -68,13 +70,20 @@ BASE_FLAGS := ${BUILD_FLAGS} -tags "${BUILDTAGS}"
BASE_LDFLAGS := -s -w -X ${PROJECT}.gitCommit=${COMMIT} -X ${PROJECT}.version=${VERSION}

# Specific build flags for build type.
DYN_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
ifeq ($(GOOS), linux)
TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test" DYN_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
else
DYN_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
endif


STATIC_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS} -extldflags '-static'"

# Installation directories.
DESTDIR ?=
PREFIX ?=/usr
PREFIX ?=/usr/local
BINDIR ?=$(PREFIX)/bin
MANDIR ?=$(PREFIX)/share/man

Expand All @@ -85,7 +94,7 @@ GO_SRC = $(shell find . -type f -name '*.go')
# NOTE: If you change these make sure you also update local-validate-build.

umoci: $(GO_SRC)
$(GO) build ${DYN_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build ${DYN_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}

umoci.static: $(GO_SRC)
env CGO_ENABLED=0 $(GO) build ${STATIC_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}
Expand Down
5 changes: 3 additions & 2 deletions oci/layer/generate_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/opencontainers/umoci/pkg/fseval"
"github.com/opencontainers/umoci/pkg/system"
"github.com/stretchr/testify/assert"
"github.com/vbatts/go-mtree"
"golang.org/x/sys/unix"
Expand All @@ -32,7 +33,7 @@ func TestInsertLayerTranslateOverlayWhiteouts(t *testing.T) {
}

testNode := path.Join(dir, "test")
err = unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err = system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
mateuszkwiatkowski marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(err)

packOptions := RepackOptions{TranslateOverlayWhiteouts: true}
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestGenerateLayerTranslateOverlayWhiteouts(t *testing.T) {
}

testNode := path.Join(dir, "test")
err = unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err = system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
assert.NoError(err)

packOptions := RepackOptions{TranslateOverlayWhiteouts: true}
Expand Down
3 changes: 2 additions & 1 deletion oci/layer/tar_extract_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"path/filepath"
"testing"

"github.com/opencontainers/umoci/pkg/system"
"golang.org/x/sys/unix"
)

func canMknod(dir string) (bool, error) {
testNode := filepath.Join(dir, "test")
err := unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err := system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
mateuszkwiatkowski marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
if os.IsPermission(err) {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/fseval/fseval_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (fs osFsEval) RemoveAll(path string) error {

// Mknod is equivalent to unix.Mknod.
func (fs osFsEval) Mknod(path string, mode os.FileMode, dev uint64) error {
return unix.Mknod(path, uint32(mode), int(dev))
return system.Mknod(path, uint32(mode), dev)
}

// MkdirAll is equivalent to os.MkdirAll.
Expand Down
28 changes: 28 additions & 0 deletions pkg/system/mknod_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package system

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

// Mknod creates a filesystem node (file, device special file or named pipe) named path
// with attributes specified by mode and dev.
func Mknod(path string, mode uint32, dev uint64) error {
return unix.Mknod(path, mode, dev)
}
25 changes: 6 additions & 19 deletions pkg/system/mknod_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !freebsd

/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
Expand All @@ -18,26 +20,11 @@
package system

import (
"archive/tar"

"golang.org/x/sys/unix"
)

// Tarmode takes a Typeflag (from a tar.Header for example) and returns the
// corresponding os.Filemode bit. Unknown typeflags are treated like regular
// files.
func Tarmode(typeflag byte) uint32 {
switch typeflag {
case tar.TypeSymlink:
return unix.S_IFLNK
case tar.TypeChar:
return unix.S_IFCHR
case tar.TypeBlock:
return unix.S_IFBLK
case tar.TypeFifo:
return unix.S_IFIFO
case tar.TypeDir:
return unix.S_IFDIR
}
return 0
// Mknod creates a filesystem node (file, device special file or named pipe) named path
// with attributes specified by mode and dev.
func Mknod(path string, mode uint32, dev uint64) error {
return unix.Mknod(path, mode, int(dev))
}
43 changes: 43 additions & 0 deletions pkg/system/tarmode_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package system

import (
"archive/tar"

"golang.org/x/sys/unix"
)

// Tarmode takes a Typeflag (from a tar.Header for example) and returns the
// corresponding os.Filemode bit. Unknown typeflags are treated like regular
// files.
func Tarmode(typeflag byte) uint32 {
switch typeflag {
case tar.TypeSymlink:
return unix.S_IFLNK
case tar.TypeChar:
return unix.S_IFCHR
case tar.TypeBlock:
return unix.S_IFBLK
case tar.TypeFifo:
return unix.S_IFIFO
case tar.TypeDir:
return unix.S_IFDIR
}
return 0
}
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/unpriv/unpriv.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func MkdirAll(path string, perm os.FileMode) error {
// required access bits to modify or resolve the path.
func Mknod(path string, mode os.FileMode, dev uint64) error {
return errors.Wrap(Wrap(path, func(path string) error {
return unix.Mknod(path, uint32(mode), int(dev))
return system.Mknod(path, uint32(mode), dev)
}), "unpriv.mknod")
}

Expand Down