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)
|
2024-11-09 07:50:06 +08:00
|
|
|
STORAGETAGS := $(shell ./btrfs_tag.sh) $(shell ./btrfs_installed_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)
|
2024-02-15 16:26:42 +08:00
|
|
|
ifeq ($(shell uname -s),FreeBSD)
|
|
|
|
# FreeBSD needs CNI until netavark is supported
|
|
|
|
TAGS += cni
|
|
|
|
endif
|
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
|
2024-03-01 17:55:43 +08:00
|
|
|
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
|
|
|
|
SELINUXTYPE=container_runtime_exec_t
|
2024-03-27 16:57:09 +08:00
|
|
|
AS ?= as
|
2024-04-01 11:55:21 +08:00
|
|
|
STRIP ?= strip
|
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)
|
2019-08-01 19:13:37 +08:00
|
|
|
export GO_BUILD=$(GO) build
|
2020-01-17 23:44:47 +08:00
|
|
|
export GO_TEST=$(GO) test
|
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
|
|
|
|
2021-01-25 21:55:06 +08:00
|
|
|
COMMIT_NO ?= $(shell git rev-parse HEAD 2> /dev/null || true)
|
|
|
|
GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
|
2019-08-20 21:45:48 +08:00
|
|
|
SOURCE_DATE_EPOCH ?= $(if $(shell date +%s),$(shell date +%s),$(error "date failed"))
|
2017-06-22 23:47:20 +08:00
|
|
|
|
2022-08-22 20:26:10 +08:00
|
|
|
# we get GNU make 3.x in MacOS build envs, which wants # to be escaped in
|
|
|
|
# strings, while the 4.x we have on Linux doesn't. this is the documented
|
|
|
|
# workaround
|
|
|
|
COMMENT := \#
|
|
|
|
CNI_COMMIT := $(shell sed -n 's;^$(COMMENT) github.com/containernetworking/cni \([^ \n]*\).*$$;\1;p' vendor/modules.txt)
|
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)'
|
2024-10-31 09:42:25 +08:00
|
|
|
|
|
|
|
# This isn't what we actually build; it's a superset, used for target
|
|
|
|
# dependencies. Basically: all *.go and *.c files, except *_test.go,
|
|
|
|
# and except anything in a dot subdirectory. If any of these files is
|
|
|
|
# newer than our target (bin/buildah), a rebuild is triggered.
|
|
|
|
SOURCES=$(shell find . -path './.*' -prune -o \( \( -name '*.go' -o -name '*.c' \) -a ! -name '*_test.go' \) -print)
|
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.
|
2024-10-16 06:04:53 +08:00
|
|
|
all: bin/buildah bin/imgtype bin/copy bin/inet bin/tutorial 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/
|
|
|
|
|
2024-10-31 09:42:25 +08:00
|
|
|
bin/buildah: $(SOURCES) internal/mkcw/embed/entrypoint_amd64.gz
|
2021-09-25 01:45:40 +08:00
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah
|
2024-03-01 17:55:43 +08:00
|
|
|
test -z "${SELINUXOPT}" || chcon --verbose -t $(SELINUXTYPE) $@
|
2018-10-27 03:35:04 +08:00
|
|
|
|
2024-03-27 16:57:09 +08:00
|
|
|
ifneq ($(shell $(AS) --version | grep x86_64),)
|
2023-11-28 04:22:52 +08:00
|
|
|
internal/mkcw/embed/entrypoint_amd64.gz: internal/mkcw/embed/entrypoint_amd64
|
2023-11-28 22:27:36 +08:00
|
|
|
gzip -k9nf $^
|
2023-11-20 16:28:06 +08:00
|
|
|
|
2023-11-28 04:22:52 +08:00
|
|
|
internal/mkcw/embed/entrypoint_amd64: internal/mkcw/embed/entrypoint_amd64.s
|
2023-07-18 04:27:19 +08:00
|
|
|
$(AS) -o $(patsubst %.s,%.o,$^) $^
|
|
|
|
$(LD) -o $@ $(patsubst %.s,%.o,$^)
|
2024-04-01 11:55:21 +08:00
|
|
|
$(STRIP) $@
|
2023-07-18 04:27:19 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2020-05-28 12:10:04 +08:00
|
|
|
.PHONY: buildah
|
|
|
|
buildah: bin/buildah
|
2018-06-29 22:00:38 +08:00
|
|
|
|
2023-08-15 10:32:26 +08:00
|
|
|
ALL_CROSS_TARGETS := $(addprefix bin/buildah.,$(subst /,.,$(shell $(GO) tool dist list)))
|
2024-02-01 04:33:34 +08:00
|
|
|
LINUX_CROSS_TARGETS := $(filter-out %.loong64,$(filter bin/buildah.linux.%,$(ALL_CROSS_TARGETS)))
|
2021-09-24 01:32:55 +08:00
|
|
|
DARWIN_CROSS_TARGETS := $(filter bin/buildah.darwin.%,$(ALL_CROSS_TARGETS))
|
|
|
|
WINDOWS_CROSS_TARGETS := $(addsuffix .exe,$(filter bin/buildah.windows.%,$(ALL_CROSS_TARGETS)))
|
2022-06-14 23:10:11 +08:00
|
|
|
FREEBSD_CROSS_TARGETS := $(filter bin/buildah.freebsd.%,$(ALL_CROSS_TARGETS))
|
2020-09-04 01:44:26 +08:00
|
|
|
.PHONY: cross
|
2022-06-14 23:10:11 +08:00
|
|
|
cross: $(LINUX_CROSS_TARGETS) $(DARWIN_CROSS_TARGETS) $(WINDOWS_CROSS_TARGETS) $(FREEBSD_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
|
|
|
|
2024-10-31 09:42:25 +08:00
|
|
|
bin/imgtype: $(SOURCES)
|
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
|
|
|
|
2024-10-31 09:42:25 +08:00
|
|
|
bin/copy: $(SOURCES)
|
2021-05-12 00:21:09 +08:00
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/copy/copy.go
|
|
|
|
|
2024-10-31 09:42:25 +08:00
|
|
|
bin/tutorial: $(SOURCES)
|
2022-07-22 05:21:43 +08:00
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/tutorial/tutorial.go
|
|
|
|
|
2024-10-16 06:04:53 +08:00
|
|
|
bin/inet: tests/inet/inet.go
|
|
|
|
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/inet/inet.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
|
|
|
|
2020-01-08 22:48:59 +08:00
|
|
|
codespell:
|
2024-11-09 09:02:20 +08:00
|
|
|
codespell -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
|
2017-04-04 05:43:57 +08:00
|
|
|
|
|
|
|
.PHONY: install.tools
|
|
|
|
install.tools:
|
2022-10-23 18:26:51 +08:00
|
|
|
$(MAKE) -C tests/tools
|
2017-04-04 05:43:57 +08:00
|
|
|
|
2017-04-12 03:34:36 +08:00
|
|
|
.PHONY: install
|
2017-03-29 03:20:37 +08:00
|
|
|
install:
|
2022-10-21 01:11:22 +08:00
|
|
|
install -d -m 755 $(DESTDIR)/$(BINDIR)
|
|
|
|
install -m 755 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:
|
2022-10-21 01:11:22 +08:00
|
|
|
install -m 755 -d $(DESTDIR)/$(BASHINSTALLDIR)
|
|
|
|
install -m 644 contrib/completions/bash/buildah $(DESTDIR)/$(BASHINSTALLDIR)/buildah
|
2017-10-06 01:48:22 +08:00
|
|
|
|
2020-06-19 06:03:43 +08:00
|
|
|
.PHONY: test-conformance
|
|
|
|
test-conformance:
|
2023-04-26 20:21:34 +08:00
|
|
|
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -timeout 60m ./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
|
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
|
2023-06-29 22:24:45 +08:00
|
|
|
$(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 45m
|
2023-11-10 05:37:32 +08:00
|
|
|
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" $(RACEFLAGS) ./chroot ./copier -timeout 60m
|
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:
|
2024-11-09 05:57:04 +08:00
|
|
|
goversion=$(shell sed -e '/^go /!d' -e '/^go /s,.* ,,g' go.mod) ; \
|
2024-08-06 05:13:06 +08:00
|
|
|
if test -d `go env GOCACHE` && test -w `go env GOCACHE` ; then \
|
2024-11-09 05:57:04 +08:00
|
|
|
podman run --privileged --rm --env HOME=/root -v `go env GOCACHE`:/root/.cache/go-build --env GOCACHE=/root/.cache/go-build -v `pwd`:/src -w /src docker.io/library/golang:$$goversion make vendor ; \
|
2024-08-06 05:13:06 +08:00
|
|
|
else \
|
2024-11-09 05:57:04 +08:00
|
|
|
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src docker.io/library/golang:$$goversion make vendor ; \
|
2024-08-06 05:13:06 +08:00
|
|
|
fi
|
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:
|
2024-04-18 02:17:44 +08:00
|
|
|
$(GO) mod tidy
|
|
|
|
$(GO) mod vendor
|
|
|
|
$(GO) mod verify
|
|
|
|
if test -n "$(strip $(shell go env GOTOOLCHAIN))"; then go mod edit -toolchain none ; fi
|
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)
|
2022-03-15 01:34:39 +08:00
|
|
|
|
|
|
|
# CAUTION: This is not a replacement for RPMs provided by your distro.
|
|
|
|
# Only intended to build and test the latest unreleased changes.
|
|
|
|
.PHONY: rpm
|
2024-03-13 22:06:45 +08:00
|
|
|
rpm: ## Build rpm packages
|
|
|
|
$(MAKE) -C rpm
|
|
|
|
|
|
|
|
# Remember that rpms install exec to /usr/bin/buildah while a `make install`
|
|
|
|
# installs them to /usr/local/bin/buildah which is likely before. Always use
|
|
|
|
# a full path to test installed buildah or you risk to call another executable.
|
|
|
|
.PHONY: rpm-install
|
|
|
|
rpm-install: package ## Install rpm packages
|
|
|
|
$(call err_if_empty,PKG_MANAGER) -y install rpm/RPMS/*/*.rpm
|
|
|
|
/usr/bin/buildah version
|