diff --git a/Dockerfile b/Dockerfile index 98bc00b96..8e0830700 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,12 +27,16 @@ ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)" # xx is a helper for cross-compilation FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx +# osxcross contains the MacOSX cross toolchain for xx +FROM crazymax/osxcross:11.3-alpine AS osxcross + FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base COPY --from=xx / / RUN apk add --no-cache \ + clang \ docker \ file \ findutils \ @@ -73,10 +77,12 @@ EOT FROM build-base AS build ARG BUILD_TAGS ARG TARGETPLATFORM -RUN xx-go --wrap RUN --mount=type=bind,target=. \ --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \ + xx-go --wrap && \ + if [ "$(xx-info os)" == "darwin" ]; then export CGO_ENABLED=1; fi && \ make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/usr/bin && \ xx-verify --static /usr/bin/docker-compose diff --git a/Makefile b/Makefile index ba209eda6..d3fc2cecc 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ all: build .PHONY: build ## Build the compose cli-plugin build: - CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd + GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd .PHONY: binary binary: diff --git a/go.mod b/go.mod index 815017e91..e06376b24 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect github.com/docker/go-metrics v0.0.1 // indirect github.com/felixge/httpsnoop v1.0.2 // indirect + github.com/fsnotify/fsevents v0.1.1 github.com/fvbommel/sortorder v1.0.2 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/go.sum b/go.sum index 66df6f4f7..66b066632 100644 --- a/go.sum +++ b/go.sum @@ -254,6 +254,8 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw= +github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= diff --git a/pkg/watch/notify_test.go b/pkg/watch/notify_test.go index eed784631..0185923b5 100644 --- a/pkg/watch/notify_test.go +++ b/pkg/watch/notify_test.go @@ -435,7 +435,7 @@ func TestWatchNonexistentDirectory(t *testing.T) { t.Fatal(err) } - // for directories that were the root of an Add, we don't report creation, cf. watcher_fsevent.go + // for directories that were the root of an Add, we don't report creation, cf. watcher_darwin.go f.assertEvents() f.events = nil diff --git a/pkg/watch/watcher_fsevent.go b/pkg/watch/watcher_darwin.go similarity index 96% rename from pkg/watch/watcher_fsevent.go rename to pkg/watch/watcher_darwin.go index b88799de8..46d6dc06e 100644 --- a/pkg/watch/watcher_fsevent.go +++ b/pkg/watch/watcher_darwin.go @@ -19,9 +19,6 @@ package watch -/** -FIXME this implementation requires CGO - import ( "path/filepath" "time" @@ -130,7 +127,7 @@ func (d *fseventNotify) Errors() chan error { return d.errors } -func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, error) { +func newWatcher(paths []string, ignore PathMatcher) (Notify, error) { dw := &fseventNotify{ ignore: ignore, stream: &fsevents.EventStream{ @@ -158,4 +155,3 @@ func newFSEventWatcher(paths []string, ignore PathMatcher) (*fseventNotify, erro } var _ Notify = &fseventNotify{} -**/ diff --git a/pkg/watch/watcher_naive.go b/pkg/watch/watcher_naive.go index a81e96dff..60056df1a 100644 --- a/pkg/watch/watcher_naive.go +++ b/pkg/watch/watcher_naive.go @@ -1,3 +1,6 @@ +//go:build !darwin +// +build !darwin + /* Copyright 2020 Docker Compose CLI authors @@ -294,7 +297,7 @@ func (d *naiveNotify) add(path string) error { return nil } -func newWatcher(paths []string, ignore PathMatcher) (*naiveNotify, error) { +func newWatcher(paths []string, ignore PathMatcher) (Notify, error) { if ignore == nil { return nil, fmt.Errorf("newWatcher: ignore is nil") }