Skip to content

Commit

Permalink
Merge pull request #46 from imeoer/fix-windows-cross-compile
Browse files Browse the repository at this point in the history
makefile: ensure cross-compilation compatibility
  • Loading branch information
bergwolf authored May 11, 2022
2 parents b4c0508 + caf9d49 commit f94ff19
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 46 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ jobs:
export PATH=$PATH:$(go env GOPATH)/bin
make smoke
cross-build-test:
name: Cross Build Test
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
GOOS: ['linux', 'windows', 'darwin']
GOARCH: ['amd64', 'arm64']
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.17'
- name: Check out code
uses: actions/checkout@v1
- name: cache go mod
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-go
- name: Build
run: |
make -e GOOS=${{ matrix.GOOS }} GOARCH=${{ matrix.GOARCH }}
coverage:
name: Code coverage
timeout-minutes: 10
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SUDO = $(shell which sudo)
GO_EXECUTABLE_PATH ?= $(shell which go)
NYDUS_BUILDER ?= /usr/bin/nydus-image
NYDUS_NYDUSD ?= /usr/bin/nydusd-fusedev
GOOS ?= linux
GOARCH ?= amd64
#GOPROXY ?= https://goproxy.io

ifdef GOPROXY
Expand All @@ -15,17 +17,16 @@ endif

.PHONY: build
build:
GOOS=linux ${PROXY} go build -ldflags="-s -w -X 'main.Version=${VERSION}'" -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc
GOOS=${GOOS} GOARCH=${GOARCH} ${PROXY} go build -ldflags="-s -w -X 'main.Version=${VERSION}'" -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc

static-release:
CGO_ENABLED=0 ${PROXY} GOOS=linux go build -ldflags '-s -w -X "main.Version=${VERSION}" -extldflags "-static"' -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc
CGO_ENABLED=0 ${PROXY} GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags '-s -w -X "main.Version=${VERSION}" -extldflags "-static"' -v -o bin/containerd-nydus-grpc ./cmd/containerd-nydus-grpc

.PHONY: clear
clear:
rm -f bin/*
rm -rf _out


.PHONY: install
install: static-release
sudo install -D -m 755 bin/containerd-nydus-grpc /usr/local/bin/containerd-nydus-grpc
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
github.com/containerd/containerd v1.6.1
github.com/containerd/continuity v0.2.2
github.com/containerd/fifo v1.0.0
github.com/docker/cli v20.10.0-beta1.0.20201029214301-1d20b15adc38+incompatible
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/google/go-containerregistry v0.5.1
Expand All @@ -29,7 +30,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/fifo v1.0.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
Expand Down
30 changes: 3 additions & 27 deletions pkg/converter/convert.go → pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

/*
* Copyright (c) 2022. Nydus Developers. All rights reserved.
*
Expand All @@ -20,7 +23,6 @@ import (
"github.com/containerd/containerd/archive/compression"
"github.com/containerd/containerd/content"
"github.com/containerd/fifo"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

Expand All @@ -32,32 +34,6 @@ const bootstrapNameInTar = "image.boot"
const envNydusBuilder = "NYDUS_BUILDER"
const envNydusWorkdir = "NYDUS_WORKDIR"

type Layer struct {
// Digest represents the hash of whole tar blob.
Digest digest.Digest
// ReaderAt holds the reader of whole tar blob.
ReaderAt content.ReaderAt
}

type ConvertOption struct {
// RafsVersion specifies nydus format version, possible values:
// `5`, `6` (EROFS-compatible), default is `5`.
RafsVersion string
// ChunkDictPath holds the bootstrap path of chunk dict image.
ChunkDictPath string
// PrefetchPatterns holds file path pattern list want to prefetch.
PrefetchPatterns string
}

type MergeOption struct {
// ChunkDictPath holds the bootstrap path of chunk dict image.
ChunkDictPath string
// PrefetchPatterns holds file path pattern list want to prefetch.
PrefetchPatterns string
// WithTar puts bootstrap into a tar stream (no gzip).
WithTar bool
}

func getBuilder() string {
builderPath := os.Getenv(envNydusBuilder)
if builderPath == "" {
Expand Down
24 changes: 24 additions & 0 deletions pkg/converter/convert_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build windows
// +build windows

/*
* Copyright (c) 2022. Nydus Developers. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package converter

import (
"context"
"fmt"
"io"
)

func Convert(ctx context.Context, dest io.Writer, opt ConvertOption) (io.WriteCloser, error) {
return nil, fmt.Errorf("not implemented")
}

func Merge(ctx context.Context, layers []Layer, dest io.Writer, opt MergeOption) error {
return fmt.Errorf("not implemented")
}
38 changes: 38 additions & 0 deletions pkg/converter/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022. Nydus Developers. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package converter

import (
"github.com/containerd/containerd/content"
"github.com/opencontainers/go-digest"
)

type Layer struct {
// Digest represents the hash of whole tar blob.
Digest digest.Digest
// ReaderAt holds the reader of whole tar blob.
ReaderAt content.ReaderAt
}

type ConvertOption struct {
// RafsVersion specifies nydus format version, possible values:
// `5`, `6` (EROFS-compatible), default is `5`.
RafsVersion string
// ChunkDictPath holds the bootstrap path of chunk dict image.
ChunkDictPath string
// PrefetchPatterns holds file path pattern list want to prefetch.
PrefetchPatterns string
}

type MergeOption struct {
// ChunkDictPath holds the bootstrap path of chunk dict image.
ChunkDictPath string
// PrefetchPatterns holds file path pattern list want to prefetch.
PrefetchPatterns string
// WithTar puts bootstrap into a tar stream (no gzip).
WithTar bool
}
3 changes: 3 additions & 0 deletions pkg/utils/mount/mount_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

package mount

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

package mount

import "fmt"

type Mounter struct {
}

func (m *Mounter) Umount(target string) error {
return nil
return fmt.Errorf("not implemented")
}

func (m *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil
return false, fmt.Errorf("not implemented")
}
9 changes: 5 additions & 4 deletions snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
Expand All @@ -37,6 +36,10 @@ import (
"github.com/containerd/nydus-snapshotter/pkg/process"
"github.com/containerd/nydus-snapshotter/pkg/signature"
"github.com/containerd/nydus-snapshotter/pkg/snapshot"

// Import the converter package so that it can be compiled during
// `go build` to ensure cross-compilation compatibility.
_ "github.com/containerd/nydus-snapshotter/pkg/converter"
)

const (
Expand Down Expand Up @@ -541,9 +544,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
return storage.Snapshot{}, errors.Wrap(err, "failed to stat parent")
}

stat := st.Sys().(*syscall.Stat_t)

if err := os.Lchown(filepath.Join(td, "fs"), int(stat.Uid), int(stat.Gid)); err != nil {
if err := lchown(filepath.Join(td, "fs"), st); err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
Expand Down
8 changes: 0 additions & 8 deletions snapshot/snapshot_darwin.go

This file was deleted.

15 changes: 14 additions & 1 deletion snapshot/snapshot_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
//go:build linux
// +build linux

package snapshot

import "github.com/containerd/continuity/fs"
import (
"os"
"syscall"

"github.com/containerd/continuity/fs"
)

func getSupportsDType(dir string) (bool, error) {
return fs.SupportsDType(dir)
}

func lchown(target string, st os.FileInfo) error {
stat := st.Sys().(*syscall.Stat_t)
return os.Lchown(target, int(stat.Uid), int(stat.Gid))
}
17 changes: 17 additions & 0 deletions snapshot/snapshot_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !linux
// +build !linux

package snapshot

import (
"fmt"
"os"
)

func getSupportsDType(dir string) (bool, error) {
return false, fmt.Errorf("not implemented")
}

func lchown(target string, st os.FileInfo) error {
return fmt.Errorf("not implemented")
}

0 comments on commit f94ff19

Please sign in to comment.