2019-08-30 18:03:41 +08:00
|
|
|
export GOPROXY=https://proxy.golang.org
|
|
|
|
|
2019-08-05 19:55:56 +08:00
|
|
|
APPARMORTAG := $(shell hack/apparmor_tag.sh)
|
2021-08-27 20:15:56 +08:00
|
|
|
STORAGETAGS := $(shell ./btrfs_tag.sh) $(shell ./btrfs_installed_tag.sh) $(shell ./libdm_tag.sh) $(shell ./hack/libsubid_tag.sh)
|
2020-12-22 04:21:39 +08:00
|
|
|
SECURITYTAGS ?= seccomp $(APPARMORTAG)
|
2022-02-14 17:05:35 +08:00
|
|
|
TAGS ?= $(SECURITYTAGS) $(STORAGETAGS) $(shell ./hack/systemd_tag.sh)
|
2018-12-07 22:55:55 +08:00
|
|
|
BUILDTAGS += $(TAGS)
|
2017-04-14 20:48:53 +08:00
|
|
|
PREFIX := /usr/local
|
2017-03-30 03:06:36 +08:00
|
|
|
BINDIR := $(PREFIX)/bin
|
2018-11-29 03:08:47 +08:00
|
|
|
BASHINSTALLDIR = $(PREFIX)/share/bash-completion/completions
|
2018-12-07 22:55:55 +08:00
|
|
|
BUILDFLAGS := -tags "$(BUILDTAGS)"
|
2018-10-27 03:35:04 +08:00
|
|
|
BUILDAH := buildah
|
2019-08-01 19:13:37 +08:00
|
|
|
|
2017-10-03 02:49:22 +08:00
|
|
|
GO := go
|
2021-09-25 01:45:40 +08:00
|
|
|
GO_LDFLAGS := $(shell if $(GO) version|grep -q gccgo; then echo "-gccgoflags"; else echo "-ldflags"; fi)
|
|
|
|
GO_GCFLAGS := $(shell if $(GO) version|grep -q gccgo; then echo "-gccgoflags"; else echo "-gcflags"; fi)
|
2018-10-18 22:47:37 +08:00
|
|
|
GO110 := 1.10
|
|
|
|
GOVERSION := $(findstring $(GO110),$(shell go version))
|
2019-08-01 19:13:37 +08:00
|
|
|
# test for go module support
|
|
|
|
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
|
|
|
|
export GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
|
2020-01-17 23:44:47 +08:00
|
|
|
export GO_TEST=GO111MODULE=on $(GO) test -mod=vendor
|
2019-08-01 19:13:37 +08:00
|
|
|
else
|
|
|
|
export GO_BUILD=$(GO) build
|
2020-01-17 23:44:47 +08:00
|
|
|
export GO_TEST=$(GO) test
|
2019-08-01 19:13:37 +08:00
|
|
|
endif
|
2021-09-24 01:32:55 +08:00
|
|
|
RACEFLAGS := $(shell $(GO_TEST) -race ./pkg/dummy > /dev/null 2>&1 && echo -race)
|
2019-08-01 19:13:37 +08:00
|
|
|
|
2018-12-07 23:13:01 +08:00
|
|
|
GIT_COMMIT ?= $(if $(shell git rev-parse --short HEAD),$(shell git rev-parse --short HEAD),$(error "git failed"))
|
2019-08-20 21:45:48 +08:00
|
|
|
SOURCE_DATE_EPOCH ?= $(if $(shell date +%s),$(shell date +%s),$(error "date failed"))
|
2019-10-30 17:48:28 +08:00
|
|
|
STATIC_STORAGETAGS = "containers_image_openpgp exclude_graphdriver_devicemapper $(STORAGE_TAGS)"
|
2017-06-22 23:47:20 +08:00
|
|
|
|
2019-07-18 16:30:42 +08:00
|
|
|
CNI_COMMIT := $(shell sed -n 's;\tgithub.com/containernetworking/cni \([^ \n]*\).*$\;\1;p' go.mod)
|
2019-09-07 03:07:18 +08:00
|
|
|
#RUNC_COMMIT := $(shell sed -n 's;\tgithub.com/opencontainers/runc \([^ \n]*\).*$\;\1;p' go.mod)
|
|
|
|
RUNC_COMMIT := v1.0.0-rc8
|
2017-07-22 05:42:10 +08:00
|
|
|
LIBSECCOMP_COMMIT := release-2.3
|
2017-07-21 01:41:51 +08:00
|
|
|
|
2020-05-28 12:10:04 +08:00
|
|
|
EXTRA_LDFLAGS ?=
|
2021-09-25 01:45:40 +08:00
|
|
|
BUILDAH_LDFLAGS := $(GO_LDFLAGS) '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT) $(EXTRA_LDFLAGS)'
|
2022-03-10 23:22:37 +08:00
|
|
|
SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go copier/*.go define/*.go docker/*.go internal/parse/*.go internal/source/*.go internal/util/*.go manifests/*.go pkg/chrootuser/*.go pkg/cli/*.go pkg/completion/*.go pkg/formats/*.go pkg/overlay/*.go pkg/parse/*.go pkg/rusage/*.go pkg/sshagent/*.go pkg/umask/*.go pkg/util/*.go util/*.go
|
2017-06-22 23:47:20 +08:00
|
|
|
|
2020-01-17 00:41:51 +08:00
|
|
|
LINTFLAGS ?=
|
|
|
|
|
2022-05-27 00:27:06 +08:00
|
|
|
ifeq ($(BUILDDEBUG), 1)
|
2020-11-24 16:47:22 +08:00
|
|
|
override GOGCFLAGS += -N -l
|
|
|
|
endif
|
|
|
|
|
2022-05-27 00:27:06 +08:00
|
|
|
# make all BUILDDEBUG=1
|
2020-11-24 16:47:22 +08:00
|
|
|
# Note: Uses the -N -l go compiler options to disable compiler optimizations
|
|
|
|
# and inlining. Using these build options allows you to subsequently
|
|
|
|
# use source debugging tools like delve.
|
2021-05-12 00:21:09 +08:00
|
|
|
all: bin/buildah bin/imgtype bin/copy docs
|
2017-01-27 23:55:04 +08:00
|
|
|
|
2020-06-29 10:40:58 +08:00
|
|
|
# Update nix/nixpkgs.json its latest stable commit
|
|
|
|
.PHONY: nixpkgs
|
2020-05-28 12:10:04 +08:00
|
|
|
nixpkgs:
|
2021-04-02 11:51:15 +08:00
|
|
|
@nix run \
|
|
|
|
-f channel:nixos-20.09 nix-prefetch-git \
|
|
|
|
-c nix-prefetch-git \
|
|
|
|
--no-deepClone \
|
2021-04-14 09:25:21 +08:00
|
|
|
https://github.com/nixos/nixpkgs refs/heads/nixos-20.09 > nix/nixpkgs.json
|
2018-10-27 03:35:04 +08:00
|
|
|
|
2020-06-29 10:40:58 +08:00
|
|
|
# Build statically linked binary
|
|
|
|
.PHONY: static
|
|
|
|
static:
|
|
|
|
@nix build -f nix/
|
|
|
|
mkdir -p ./bin
|
|
|
|
cp -rfp ./result/bin/* ./bin/
|
|
|
|
|
2021-05-12 00:21:09 +08:00
|
|
|
bin/buildah: $(SOURCES) cmd/buildah/*.go
|
2021-09-25 01:45:40 +08:00
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah
|
2018-10-27 03:35:04 +08:00
|
|
|
|
2020-05-28 12:10:04 +08:00
|
|
|
.PHONY: buildah
|
|
|
|
buildah: bin/buildah
|
2018-06-29 22:00:38 +08:00
|
|
|
|
2021-09-24 01:32:55 +08:00
|
|
|
ALL_CROSS_TARGETS := $(addprefix bin/buildah.,$(subst /,.,$(shell $(GO) tool dist list)))
|
|
|
|
LINUX_CROSS_TARGETS := $(filter bin/buildah.linux.%,$(ALL_CROSS_TARGETS))
|
|
|
|
DARWIN_CROSS_TARGETS := $(filter bin/buildah.darwin.%,$(ALL_CROSS_TARGETS))
|
|
|
|
WINDOWS_CROSS_TARGETS := $(addsuffix .exe,$(filter bin/buildah.windows.%,$(ALL_CROSS_TARGETS)))
|
2020-09-04 01:44:26 +08:00
|
|
|
.PHONY: cross
|
2021-09-10 02:11:50 +08:00
|
|
|
cross: $(LINUX_CROSS_TARGETS) $(DARWIN_CROSS_TARGETS) $(WINDOWS_CROSS_TARGETS)
|
2020-09-04 01:44:26 +08:00
|
|
|
|
|
|
|
bin/buildah.%:
|
|
|
|
mkdir -p ./bin
|
2020-11-06 17:51:20 +08:00
|
|
|
GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ -tags "containers_image_openpgp" ./cmd/buildah
|
2017-01-27 23:55:04 +08:00
|
|
|
|
2021-05-12 00:21:09 +08:00
|
|
|
bin/imgtype: $(SOURCES) tests/imgtype/imgtype.go
|
2020-11-06 17:51:20 +08:00
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/imgtype/imgtype.go
|
2017-06-29 02:34:41 +08:00
|
|
|
|
2021-05-12 00:21:09 +08:00
|
|
|
bin/copy: $(SOURCES) tests/copy/copy.go
|
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/copy/copy.go
|
|
|
|
|
2017-01-27 23:55:04 +08:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2020-05-28 12:10:04 +08:00
|
|
|
$(RM) -r bin tests/testreport/testreport
|
2018-11-29 03:08:47 +08:00
|
|
|
$(MAKE) -C docs clean
|
2017-01-27 23:55:04 +08:00
|
|
|
|
2017-03-29 03:37:24 +08:00
|
|
|
.PHONY: docs
|
2019-06-21 23:07:34 +08:00
|
|
|
docs: install.tools ## build the docs on the host
|
2017-04-12 03:34:36 +08:00
|
|
|
$(MAKE) -C docs
|
2017-03-29 03:37:24 +08:00
|
|
|
|
|
|
|
# For vendoring to work right, the checkout directory must be such that our top
|
2018-09-18 03:20:16 +08:00
|
|
|
# level is at $GOPATH/src/github.com/containers/buildah.
|
2017-01-27 23:55:04 +08:00
|
|
|
.PHONY: gopath
|
|
|
|
gopath:
|
2018-09-18 03:20:16 +08:00
|
|
|
test $(shell pwd) = $(shell cd ../../../../src/github.com/containers/buildah ; pwd)
|
2017-01-27 23:55:04 +08:00
|
|
|
|
2020-01-08 22:48:59 +08:00
|
|
|
codespell:
|
2021-08-11 22:15:40 +08:00
|
|
|
codespell -S Makefile,build,buildah,buildah.spec,imgtype,copy,AUTHORS,bin,vendor,.git,go.sum,CHANGELOG.md,changelog.txt,seccomp.json,.cirrus.yml,"*.xz,*.gz,*.tar,*.tgz,*ico,*.png,*.1,*.5,*.orig,*.rej" -L uint,iff,od,ERRO -w
|
2020-01-08 22:48:59 +08:00
|
|
|
|
2017-04-04 05:43:57 +08:00
|
|
|
.PHONY: validate
|
2019-06-21 23:07:34 +08:00
|
|
|
validate: install.tools
|
2021-02-08 23:20:36 +08:00
|
|
|
./tests/validate/whitespace.sh
|
|
|
|
./hack/xref-helpmsgs-manpages
|
|
|
|
./tests/validate/pr-should-include-tests
|
2021-07-27 03:26:32 +08:00
|
|
|
./tests/validate/buildahimages-are-sane
|
2017-04-04 05:43:57 +08:00
|
|
|
|
|
|
|
.PHONY: install.tools
|
|
|
|
install.tools:
|
2019-07-08 17:24:22 +08:00
|
|
|
make -C tests/tools
|
2017-04-04 05:43:57 +08:00
|
|
|
|
2017-07-21 01:41:51 +08:00
|
|
|
.PHONY: runc
|
|
|
|
runc: gopath
|
|
|
|
rm -rf ../../opencontainers/runc
|
|
|
|
git clone https://github.com/opencontainers/runc ../../opencontainers/runc
|
2018-10-27 03:35:04 +08:00
|
|
|
cd ../../opencontainers/runc && git checkout $(RUNC_COMMIT) && $(GO) build -tags "$(STORAGETAGS) $(SECURITYTAGS)"
|
2017-07-21 01:41:51 +08:00
|
|
|
ln -sf ../../opencontainers/runc/runc
|
|
|
|
|
2017-07-22 05:42:10 +08:00
|
|
|
.PHONY: install.libseccomp.sudo
|
|
|
|
install.libseccomp.sudo: gopath
|
|
|
|
rm -rf ../../seccomp/libseccomp
|
|
|
|
git clone https://github.com/seccomp/libseccomp ../../seccomp/libseccomp
|
|
|
|
cd ../../seccomp/libseccomp && git checkout $(LIBSECCOMP_COMMIT) && ./autogen.sh && ./configure --prefix=/usr && make all && sudo make install
|
|
|
|
|
2018-05-23 01:48:15 +08:00
|
|
|
.PHONY: install.cni.sudo
|
|
|
|
install.cni.sudo: gopath
|
|
|
|
rm -rf ../../containernetworking/plugins
|
|
|
|
git clone https://github.com/containernetworking/plugins ../../containernetworking/plugins
|
2020-02-11 01:36:06 +08:00
|
|
|
cd ../../containernetworking/plugins && ./build_linux.sh && sudo install -D -v -m755 -t /opt/cni/bin/ bin/*
|
2018-05-23 01:48:15 +08:00
|
|
|
|
2017-04-12 03:34:36 +08:00
|
|
|
.PHONY: install
|
2017-03-29 03:20:37 +08:00
|
|
|
install:
|
2020-05-28 12:10:04 +08:00
|
|
|
install -D -m0755 bin/buildah $(DESTDIR)/$(BINDIR)/buildah
|
2017-03-29 03:37:24 +08:00
|
|
|
$(MAKE) -C docs install
|
|
|
|
|
2018-06-19 14:08:55 +08:00
|
|
|
.PHONY: uninstall
|
|
|
|
uninstall:
|
|
|
|
rm -f $(DESTDIR)/$(BINDIR)/buildah
|
|
|
|
rm -f $(PREFIX)/share/man/man1/buildah*.1
|
2018-11-29 03:08:47 +08:00
|
|
|
rm -f $(DESTDIR)/$(BASHINSTALLDIR)/buildah
|
2018-06-19 14:08:55 +08:00
|
|
|
|
2017-03-29 03:20:37 +08:00
|
|
|
.PHONY: install.completions
|
|
|
|
install.completions:
|
2018-11-29 03:08:47 +08:00
|
|
|
install -m 644 -D contrib/completions/bash/buildah $(DESTDIR)/$(BASHINSTALLDIR)/buildah
|
2017-10-06 01:48:22 +08:00
|
|
|
|
2017-12-12 02:25:42 +08:00
|
|
|
.PHONY: install.runc
|
|
|
|
install.runc:
|
|
|
|
install -m 755 ../../opencontainers/runc/runc $(DESTDIR)/$(BINDIR)/
|
|
|
|
|
2020-06-19 06:03:43 +08:00
|
|
|
.PHONY: test-conformance
|
|
|
|
test-conformance:
|
2021-04-02 01:28:14 +08:00
|
|
|
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -timeout 20m ./tests/conformance
|
2020-06-19 06:03:43 +08:00
|
|
|
|
2017-10-06 01:48:22 +08:00
|
|
|
.PHONY: test-integration
|
2019-06-21 23:07:34 +08:00
|
|
|
test-integration: install.tools
|
2019-08-15 03:23:36 +08:00
|
|
|
./tests/tools/build/ginkgo $(BUILDFLAGS) -v tests/e2e/.
|
2017-10-06 01:48:22 +08:00
|
|
|
cd tests; ./test_runner.sh
|
|
|
|
|
2018-05-12 01:08:18 +08:00
|
|
|
tests/testreport/testreport: tests/testreport/testreport.go
|
2021-09-25 01:45:40 +08:00
|
|
|
$(GO_BUILD) $(GO_LDFLAGS) "-linkmode external -extldflags -static" -tags "$(STORAGETAGS) $(SECURITYTAGS)" -o tests/testreport/testreport ./tests/testreport/testreport.go
|
2018-05-12 01:08:18 +08:00
|
|
|
|
2017-10-06 01:48:22 +08:00
|
|
|
.PHONY: test-unit
|
2018-05-12 01:08:18 +08:00
|
|
|
test-unit: tests/testreport/testreport
|
2021-09-14 21:43:42 +08:00
|
|
|
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover $(RACEFLAGS) $(shell $(GO) list ./... | grep -v vendor | grep -v tests | grep -v cmd) -timeout 45m
|
2017-10-06 01:48:22 +08:00
|
|
|
tmp=$(shell mktemp -d) ; \
|
|
|
|
mkdir -p $$tmp/root $$tmp/runroot; \
|
2021-09-14 21:43:42 +08:00
|
|
|
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover $(RACEFLAGS) ./cmd/buildah -args --root $$tmp/root --runroot $$tmp/runroot --storage-driver vfs --signature-policy $(shell pwd)/tests/policy.json --registries-conf $(shell pwd)/tests/registries.conf
|
2019-01-31 01:14:47 +08:00
|
|
|
|
2019-10-29 04:56:48 +08:00
|
|
|
vendor-in-container:
|
2021-08-12 08:19:33 +08:00
|
|
|
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src docker.io/library/golang:1.16 make vendor
|
2019-10-29 04:56:48 +08:00
|
|
|
|
2019-01-31 01:14:47 +08:00
|
|
|
.PHONY: vendor
|
2019-06-21 23:23:28 +08:00
|
|
|
vendor:
|
2020-04-09 02:24:18 +08:00
|
|
|
GO111MODULE=on $(GO) mod tidy
|
2020-04-09 02:25:37 +08:00
|
|
|
GO111MODULE=on $(GO) mod vendor
|
2020-04-09 02:24:18 +08:00
|
|
|
GO111MODULE=on $(GO) mod verify
|
2019-07-04 20:36:46 +08:00
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint: install.tools
|
2020-01-17 00:41:51 +08:00
|
|
|
./tests/tools/build/golangci-lint run $(LINTFLAGS)
|