podman
232 строки · 9.4 Кб
1export GOPROXY=https://proxy.golang.org2
3APPARMORTAG := $(shell hack/apparmor_tag.sh)4STORAGETAGS := exclude_graphdriver_devicemapper $(shell ./btrfs_tag.sh) $(shell ./btrfs_installed_tag.sh) $(shell ./hack/libsubid_tag.sh)5SECURITYTAGS ?= seccomp $(APPARMORTAG)6TAGS ?= $(SECURITYTAGS) $(STORAGETAGS) $(shell ./hack/systemd_tag.sh)7ifeq ($(shell uname -s),FreeBSD)8# FreeBSD needs CNI until netavark is supported
9TAGS += cni10endif
11BUILDTAGS += $(TAGS)12PREFIX := /usr/local13BINDIR := $(PREFIX)/bin14BASHINSTALLDIR = $(PREFIX)/share/bash-completion/completions15BUILDFLAGS := -tags "$(BUILDTAGS)"16BUILDAH := buildah17SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)18SELINUXTYPE=container_runtime_exec_t19AS ?= as20STRIP ?= strip21
22GO := go23GO_LDFLAGS := $(shell if $(GO) version|grep -q gccgo; then echo "-gccgoflags"; else echo "-ldflags"; fi)24GO_GCFLAGS := $(shell if $(GO) version|grep -q gccgo; then echo "-gccgoflags"; else echo "-gcflags"; fi)25# test for go module support
26ifeq ($(shell $(GO) help mod >/dev/null 2>&1 && echo true), true)27export GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor28export GO_TEST=GO111MODULE=on $(GO) test -mod=vendor29else
30export GO_BUILD=$(GO) build31export GO_TEST=$(GO) test32endif
33RACEFLAGS := $(shell $(GO_TEST) -race ./pkg/dummy > /dev/null 2>&1 && echo -race)34
35COMMIT_NO ?= $(shell git rev-parse HEAD 2> /dev/null || true)36GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})37SOURCE_DATE_EPOCH ?= $(if $(shell date +%s),$(shell date +%s),$(error "date failed"))38STATIC_STORAGETAGS = "containers_image_openpgp $(STORAGE_TAGS)"39
40# we get GNU make 3.x in MacOS build envs, which wants # to be escaped in
41# strings, while the 4.x we have on Linux doesn't. this is the documented
42# workaround
43COMMENT := \#44CNI_COMMIT := $(shell sed -n 's;^$(COMMENT) github.com/containernetworking/cni \([^ \n]*\).*$$;\1;p' vendor/modules.txt)45RUNC_COMMIT := $(shell sed -n 's;^$(COMMENT) github.com/opencontainers/runc \([^ \n]*\).*$$;\1;p' vendor/modules.txt)46LIBSECCOMP_COMMIT := release-2.347
48EXTRA_LDFLAGS ?=49BUILDAH_LDFLAGS := $(GO_LDFLAGS) '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT) $(EXTRA_LDFLAGS)'50SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go copier/*.go define/*.go docker/*.go internal/config/*.go internal/mkcw/*.go internal/mkcw/types/*.go internal/parse/*.go internal/sbom/*.go internal/source/*.go internal/tmpdir/*.go internal/util/*.go internal/volumes/*.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/*.go51
52LINTFLAGS ?=53
54ifeq ($(BUILDDEBUG), 1)55override GOGCFLAGS += -N -l56endif
57
58# make all BUILDDEBUG=1
59# Note: Uses the -N -l go compiler options to disable compiler optimizations
60# and inlining. Using these build options allows you to subsequently
61# use source debugging tools like delve.
62all: bin/buildah bin/imgtype bin/copy bin/tutorial docs63
64# Update nix/nixpkgs.json its latest stable commit
65.PHONY: nixpkgs66nixpkgs:67@nix run \68-f channel:nixos-20.09 nix-prefetch-git \69-c nix-prefetch-git \
70--no-deepClone \
71https://github.com/nixos/nixpkgs refs/heads/nixos-20.09 > nix/nixpkgs.json72
73# Build statically linked binary
74.PHONY: static75static:76@nix build -f nix/77mkdir -p ./bin
78cp -rfp ./result/bin/* ./bin/
79
80bin/buildah: $(SOURCES) cmd/buildah/*.go internal/mkcw/embed/entrypoint_amd64.gz81$(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah82test -z "${SELINUXOPT}" || chcon --verbose -t $(SELINUXTYPE) $@83
84ifneq ($(shell $(AS) --version | grep x86_64),)85internal/mkcw/embed/entrypoint_amd64.gz: internal/mkcw/embed/entrypoint_amd6486gzip -k9nf $^87
88internal/mkcw/embed/entrypoint_amd64: internal/mkcw/embed/entrypoint_amd64.s89$(AS) -o $(patsubst %.s,%.o,$^) $^90$(LD) -o $@ $(patsubst %.s,%.o,$^)91$(STRIP) $@92endif
93
94
95.PHONY: buildah96buildah: bin/buildah97
98ALL_CROSS_TARGETS := $(addprefix bin/buildah.,$(subst /,.,$(shell $(GO) tool dist list)))99LINUX_CROSS_TARGETS := $(filter-out %.loong64,$(filter bin/buildah.linux.%,$(ALL_CROSS_TARGETS)))100DARWIN_CROSS_TARGETS := $(filter bin/buildah.darwin.%,$(ALL_CROSS_TARGETS))101WINDOWS_CROSS_TARGETS := $(addsuffix .exe,$(filter bin/buildah.windows.%,$(ALL_CROSS_TARGETS)))102FREEBSD_CROSS_TARGETS := $(filter bin/buildah.freebsd.%,$(ALL_CROSS_TARGETS))103.PHONY: cross104cross: $(LINUX_CROSS_TARGETS) $(DARWIN_CROSS_TARGETS) $(WINDOWS_CROSS_TARGETS) $(FREEBSD_CROSS_TARGETS)105
106bin/buildah.%:107mkdir -p ./bin
108GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ -tags "containers_image_openpgp" ./cmd/buildah109
110bin/imgtype: $(SOURCES) tests/imgtype/imgtype.go111$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/imgtype/imgtype.go112
113bin/copy: $(SOURCES) tests/copy/copy.go114$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/copy/copy.go115
116bin/tutorial: $(SOURCES) tests/tutorial/tutorial.go117$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/tutorial/tutorial.go118
119.PHONY: clean120clean:121$(RM) -r bin tests/testreport/testreport122$(MAKE) -C docs clean123
124.PHONY: docs125docs: install.tools ## build the docs on the host126$(MAKE) -C docs127
128# For vendoring to work right, the checkout directory must be such that our top
129# level is at $GOPATH/src/github.com/containers/buildah.
130.PHONY: gopath131gopath:132test $(shell pwd) = $(shell cd ../../../../src/github.com/containers/buildah ; pwd)133
134codespell:135codespell -S Makefile,buildah.spec.rpkg,AUTHORS,bin,vendor,.git,go.mod,go.sum,CHANGELOG.md,changelog.txt,seccomp.json,.cirrus.yml,"*.xz,*.gz,*.tar,*.tgz,*ico,*.png,*.1,*.5,*.orig,*.rej" -L secon,passt,bu,uint,iff,od,erro -w136
137.PHONY: validate138validate: install.tools139./tests/validate/whitespace.sh
140./hack/xref-helpmsgs-manpages
141./tests/validate/pr-should-include-tests142
143.PHONY: install.tools144install.tools:145$(MAKE) -C tests/tools146
147.PHONY: runc148runc: gopath149rm -rf ../../opencontainers/runc
150git clone https://github.com/opencontainers/runc ../../opencontainers/runc151cd ../../opencontainers/runc && git checkout $(RUNC_COMMIT) && $(GO) build -tags "$(STORAGETAGS) $(SECURITYTAGS)"152ln -sf ../../opencontainers/runc/runc
153
154.PHONY: install.libseccomp.sudo155install.libseccomp.sudo: gopath156rm -rf ../../seccomp/libseccomp
157git clone https://github.com/seccomp/libseccomp ../../seccomp/libseccomp158cd ../../seccomp/libseccomp && git checkout $(LIBSECCOMP_COMMIT) && ./autogen.sh && ./configure --prefix=/usr && make all && sudo make install159
160.PHONY: install.cni.sudo161install.cni.sudo: gopath162rm -rf ../../containernetworking/plugins
163git clone https://github.com/containernetworking/plugins ../../containernetworking/plugins164cd ../../containernetworking/plugins && ./build_linux.sh && sudo install -D -v -m755 -t /opt/cni/bin/ bin/*
165
166.PHONY: install167install:168install -d -m 755 $(DESTDIR)/$(BINDIR)169install -m 755 bin/buildah $(DESTDIR)/$(BINDIR)/buildah170$(MAKE) -C docs install171
172.PHONY: uninstall173uninstall:174rm -f $(DESTDIR)/$(BINDIR)/buildah175rm -f $(PREFIX)/share/man/man1/buildah*.1176rm -f $(DESTDIR)/$(BASHINSTALLDIR)/buildah177
178.PHONY: install.completions179install.completions:180install -m 755 -d $(DESTDIR)/$(BASHINSTALLDIR)181install -m 644 contrib/completions/bash/buildah $(DESTDIR)/$(BASHINSTALLDIR)/buildah182
183.PHONY: install.runc184install.runc:185install -m 755 ../../opencontainers/runc/runc $(DESTDIR)/$(BINDIR)/186
187.PHONY: test-conformance188test-conformance:189$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -timeout 60m ./tests/conformance190
191.PHONY: test-integration192test-integration: install.tools193./tests/tools/build/ginkgo $(BUILDFLAGS) -v tests/e2e/.194cd tests; ./test_runner.sh195
196tests/testreport/testreport: tests/testreport/testreport.go197$(GO_BUILD) $(GO_LDFLAGS) "-linkmode external -extldflags -static" -tags "$(STORAGETAGS) $(SECURITYTAGS)" -o tests/testreport/testreport ./tests/testreport/testreport.go198
199.PHONY: test-unit200test-unit: tests/testreport/testreport201$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover $(RACEFLAGS) $(shell $(GO) list ./... | grep -v vendor | grep -v tests | grep -v cmd | grep -v chroot | grep -v copier) -timeout 45m202$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" $(RACEFLAGS) ./chroot ./copier -timeout 60m203tmp=$(shell mktemp -d) ; \204mkdir -p $$tmp/root $$tmp/runroot; \205$(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.conf206
207vendor-in-container:208podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src docker.io/library/golang:1.21 make vendor209
210.PHONY: vendor211vendor:212GO111MODULE=on $(GO) mod tidy213GO111MODULE=on $(GO) mod vendor214GO111MODULE=on $(GO) mod verify215
216.PHONY: lint217lint: install.tools218./tests/tools/build/golangci-lint run $(LINTFLAGS)219
220# CAUTION: This is not a replacement for RPMs provided by your distro.
221# Only intended to build and test the latest unreleased changes.
222.PHONY: rpm223rpm: ## Build rpm packages224$(MAKE) -C rpm225
226# Remember that rpms install exec to /usr/bin/buildah while a `make install`
227# installs them to /usr/local/bin/buildah which is likely before. Always use
228# a full path to test installed buildah or you risk to call another executable.
229.PHONY: rpm-install230rpm-install: package ## Install rpm packages231$(call err_if_empty,PKG_MANAGER) -y install rpm/RPMS/*/*.rpm232/usr/bin/buildah version
233