Skip to content

Commit

Permalink
makefile: unify the makefiles for contrib components
Browse files Browse the repository at this point in the history
Unify the makefiles for contrib components by use the same template.
Also refine the global makefile targets to make them symmetric.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
  • Loading branch information
jiangliu committed Sep 26, 2022
1 parent a4a7a0f commit ab8ccd8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 70 deletions.
90 changes: 61 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
all: build

all-build: build contrib-build

all-release: release contrib-release

all-static-release: static-release docker-static contrib-release

all-install: install contrib-install

all-clean: clean contrib-clean

TEST_WORKDIR_PREFIX ?= "/tmp"
DOCKER ?= "true"

Expand All @@ -24,6 +34,11 @@ endif
endif
RUST_TARGET_STATIC ?= $(STATIC_TARGET)

CTR-REMOTE_PATH = contrib/ctr-remote
DOCKER-GRAPHDRIVER_PATH = contrib/docker-nydus-graphdriver
NYDUSIFY_PATH = contrib/nydusify
NYDUS-OVERLAYFS_PATH = contrib/nydus-overlayfs

current_dir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
env_go_path := $(shell go env GOPATH 2> /dev/null)
go_path := $(if $(env_go_path),$(env_go_path),"$(HOME)/go")
Expand All @@ -49,7 +64,8 @@ define build_golang
fi
endef

.PHONY: all .release_version .format .musl_target build release static-release
.PHONY: .release_version .format .musl_target \
all all-build all-release all-static-release build release static-release

.release_version:
$(eval CARGO_BUILD_FLAGS += --release)
Expand Down Expand Up @@ -82,13 +98,8 @@ ut:
TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) RUST_BACKTRACE=1 ${CARGO} test --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) -- --skip integration --nocapture --test-threads=8

smoke: ut
# TODO: Put each test function into separated rs file.
$(SUDO) TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) $(CARGO) test --test '*' $(CARGO_COMMON) -- --nocapture --test-threads=8

docker-static:
docker build -t nydus-rs-static --build-arg RUST_TARGET=${RUST_TARGET_STATIC} misc/musl-static
docker run --rm ${CARGO_BUILD_GEARS} -e RUST_TARGET=${RUST_TARGET_STATIC} --workdir /nydus-rs -v ${current_dir}:/nydus-rs nydus-rs-static

docker-nydus-smoke:
docker build -t nydus-smoke --build-arg RUST_TARGET=${RUST_TARGET_STATIC} misc/nydus-smoke
docker run --rm --privileged ${CARGO_BUILD_GEARS} \
Expand All @@ -98,10 +109,9 @@ docker-nydus-smoke:
-v ${current_dir}:/nydus-rs \
nydus-smoke

NYDUSIFY_PATH = contrib/nydusify
# TODO: Nydusify smoke has to be time consuming for a while since it relies on musl nydusd and nydus-image.
# So musl compliation must be involved.
# And docker-in-docker deployment invovles image buiding?
# So musl compilation must be involved.
# And docker-in-docker deployment involves image building?
docker-nydusify-smoke: docker-static
$(call build_golang,$(NYDUSIFY_PATH),make build-smoke)
docker build -t nydusify-smoke misc/nydusify-smoke
Expand All @@ -118,56 +128,78 @@ docker-nydusify-image-test: docker-static
-e BACKEND_CONFIG=$(BACKEND_CONFIG) \
-v $(current_dir):/nydus-rs $(dind_cache_mount) nydusify-smoke TestDockerHubImage

# Run integration smoke test in docker-in-docker container. It requires some special settings,
# refer to `misc/example/README.md` for details.
docker-smoke: docker-nydus-smoke docker-nydusify-smoke

contrib-build: nydusify ctr-remote nydus-overlayfs docker-nydus-graphdriver

contrib-release: nydusify-release ctr-remote-release \
nydus-overlayfs-release docker-nydus-graphdriver-release

contrib-test: nydusify-test ctr-remote-test \
nydus-overlayfs-test docker-nydus-graphdriver-test

contrib-clean: nydusify-clean ctr-remote-clean \
nydus-overlayfs-clean docker-nydus-graphdriver-clean

contrib-install:
@sudo install -D -m 755 contrib/ctr-remote/bin/ctr-remote /usr/local/bin/ctr-remote
@sudo install -D -m 755 contrib/docker-nydus-graphdriver/bin/nydus-graphdriver /usr/local/bin/nydus-overlayfs
@sudo install -D -m 755 contrib/nydus-overlayfs/bin/nydus-overlayfs /usr/local/bin/nydus-overlayfs
@sudo install -D -m 755 contrib/nydusify/cmd/nydusify /usr/local/bin/nydusify

nydusify:
$(call build_golang,${NYDUSIFY_PATH},make)

nydusify-release:
$(call build_golang,${NYDUSIFY_PATH},make release)

nydusify-test:
$(call build_golang,${NYDUSIFY_PATH},make test)

nydusify-static:
$(call build_golang,${NYDUSIFY_PATH},make static-release)
nydusify-clean:
$(call build_golang,${NYDUSIFY_PATH},make clean)

CTR-REMOTE_PATH = contrib/ctr-remote
ctr-remote:
$(call build_golang,${CTR-REMOTE_PATH},make)

ctr-remote-release:
$(call build_golang,${CTR-REMOTE_PATH},make release)

ctr-remote-test:
$(call build_golang,${CTR-REMOTE_PATH},make test)

ctr-remote-static:
$(call build_golang,${CTR-REMOTE_PATH},make static-release)
ctr-remote-clean:
$(call build_golang,${CTR-REMOTE_PATH},make clean)

NYDUS-OVERLAYFS_PATH = contrib/nydus-overlayfs
nydus-overlayfs:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make)

nydus-overlayfs-release:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make release)

nydus-overlayfs-test:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make test)

nydus-overlayfs-static:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make static-release)
nydus-overlayfs-clean:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make clean)

DOCKER-GRAPHDRIVER_PATH = contrib/docker-nydus-graphdriver
docker-nydus-graphdriver:
$(call build_golang,${DOCKER-GRAPHDRIVER_PATH},make)

docker-nydus-graphdriver-release:
$(call build_golang,${DOCKER-GRAPHDRIVER_PATH},make release)

docker-nydus-graphdriver-test:
$(call build_golang,${DOCKER-GRAPHDRIVER_PATH},make test)

docker-nydus-graphdriver-static:
$(call build_golang,${DOCKER-GRAPHDRIVER_PATH},make static-release)

# Run integration smoke test in docker-in-docker container. It requires some special settings,
# refer to `misc/example/README.md` for details.
all-static-release: docker-static all-contrib-static-release

all-contrib-static-release: nydusify-static ctr-remote-static \
nydus-overlayfs-static docker-nydus-graphdriver-static
docker-nydus-graphdriver-clean:
$(call build_golang,${DOCKER-GRAPHDRIVER_PATH},make clean)

all-contrib-test: nydusify-test ctr-remote-test \
nydus-overlayfs-test docker-nydus-graphdriver-test
docker-static:
docker build -t nydus-rs-static --build-arg RUST_TARGET=${RUST_TARGET_STATIC} misc/musl-static
docker run --rm ${CARGO_BUILD_GEARS} -e RUST_TARGET=${RUST_TARGET_STATIC} --workdir /nydus-rs -v ${current_dir}:/nydus-rs nydus-rs-static

docker-example: all-static-release
cp ${current_dir}/target/${RUST_TARGET_STATIC}/release/nydusd misc/example
Expand Down
27 changes: 16 additions & 11 deletions contrib/ctr-remote/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
GIT_COMMIT := $(shell git rev-list -1 HEAD)
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M)
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOARCH ?= amd64
GOPROXY ?= https://goproxy.io

all:clear build
ifdef GOPROXY
PROXY := GOPROXY=${GOPROXY}
endif

.PHONY: build
build:
GOOS=linux GOARCH=${GOARCH} go build -v -o bin/ctr-remote ./cmd/main.go
.PHONY: all build release test clean

.PHONY: clear
clear:
rm -f bin/*
all: build

build:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -v -o bin/ctr-remote ./cmd/main.go

.PHONY: static-release
static-release:
GOOS=linux GOARCH=${GOARCH} go build -ldflags '-s -w -extldflags "-static"' -v -o bin/ctr-remote ./cmd/main.go
release:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags '-s -w -extldflags "-static"' -v -o bin/ctr-remote ./cmd/main.go

.PHONY: test
test: build
go vet $(PACKAGES)
golangci-lint run
go test -v -cover ${PACKAGES}

clean:
rm -f bin/*
27 changes: 16 additions & 11 deletions contrib/docker-nydus-graphdriver/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
GIT_COMMIT := $(shell git rev-list -1 HEAD)
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M)
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOARCH ?= amd64
GOPROXY ?= https://goproxy.io

all:clear build
ifdef GOPROXY
PROXY := GOPROXY=${GOPROXY}
endif

.PHONY: build
build:
GOOS=linux GOARCH=${GOARCH} go build -v -o bin/nydus_graphdriver .
.PHONY: all build release test clean

.PHONY: clear
clear:
rm -f bin/*
all: build

build:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -v -o bin/nydus_graphdriver .

.PHONY: static-release
static-release:
GOOS=linux GOARCH=${GOARCH} go build -ldflags '-s -w -extldflags "-static"' -v -o bin/nydus_graphdriver .
release:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags '-s -w -extldflags "-static"' -v -o bin/nydus_graphdriver .

.PHONY: test
test: build
go vet $(PACKAGES)
golangci-lint run
go test -v -cover ${PACKAGES}

clean:
rm -f bin/*
27 changes: 15 additions & 12 deletions contrib/nydus-overlayfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
all:clear build

GIT_COMMIT := $(shell git rev-parse --verify HEAD --short=7)
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M)
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOARCH ?= amd64
GOPROXY ?= https://goproxy.io

.PHONY: build
build:
GOOS=linux GOARCH=${GOARCH} go build -ldflags="-s -w -X 'main.Version=${GIT_COMMIT}' -X 'main.BuildTime=${BUILD_TIME}'" -v -o bin/nydus-overlayfs ./cmd/main.go
ifdef GOPROXY
PROXY := GOPROXY=${GOPROXY}
endif

.PHONY: clear
clear:
rm -f bin/*
.PHONY: all build release test clean

all: build

.PHONY: static-release
static-release:
GOOS=linux GOARCH=${GOARCH} go build -ldflags '-s -w -extldflags "-static"' -v -o bin/nydus-overlayfs ./cmd/main.go
build:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags="-s -w -X 'main.Version=${GIT_COMMIT}' -X 'main.BuildTime=${BUILD_TIME}'" -v -o bin/nydus-overlayfs ./cmd/main.go

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

.PHONY: test
test: build
go vet $(PACKAGES)
golangci-lint run
go test -v -cover ${PACKAGES}

clean:
rm -f bin/*
17 changes: 10 additions & 7 deletions contrib/nydusify/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
GIT_COMMIT := $(shell git rev-list -1 HEAD)
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M)
CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOARCH ?= amd64
#GOPROXY ?= https://goproxy.io
GOPROXY ?= https://goproxy.io

ifdef GOPROXY
PROXY := GOPROXY=${GOPROXY}
endif

.PHONY: build
.PHONY: all build release test clean build-smoke

all: build

build:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags '-X main.versionGitCommit=${GIT_COMMIT} -X main.versionBuildTime=${BUILD_TIME}' -gcflags=all="-N -l" -o ./cmd ./cmd/nydusify.go

.PHONY: static-release
static-release:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags '-X main.versionGitCommit=${GIT_COMMIT} -X main.versionBuildTime=${BUILD_TIME}' -o ./cmd ./cmd/nydusify.go
release:
@CGO_ENABLED=0 ${PROXY} GOOS=linux GOARCH=${GOARCH} go build -ldflags '-X main.versionGitCommit=${GIT_COMMIT} -X main.versionBuildTime=${BUILD_TIME} -s -w -extldflags "-static"' -o ./cmd ./cmd/nydusify.go

.PHONY: test
test: build build-smoke
@go vet $(PACKAGES)
golangci-lint run
@go test -count=1 -v -timeout 20m -race ./pkg/...

clean:
rm -f cmd/nydusify

build-smoke:
${PROXY} go test -race -v -c -o ./nydusify-smoke ./tests

0 comments on commit ab8ccd8

Please sign in to comment.