Skip to content

Commit

Permalink
Overhaul Makefile binary and release worflows
Browse files Browse the repository at this point in the history
* Incorporate changes from abandoned containers#9918: Use dedicated `bin`
  sub-directories for `windows` and `darwin` when building
  `podman-remote`.  The linux flavor remains under `bin` as before.

* Fix MacOS Documentation-generation for release-packaging.
  The `install-podman-remote-%-docs` target requires local execution
  of `podman-remote`, but it was assuming GOOS=linux.  Fix this
  by dynamically discovering the local OS/architecture type while
  still permitting cross-building of MacOS binaries under Linux.

* Unify temporary directory/file behavior to use a common template.
  In case of left-over temporary items left in the repository,
  update the `clean` target accordingly to remove them.

* Fix broken podman-remote-static and MacOS release archive targets
  mismatching the `podman-remote-%` target.  Disambiguate this target
  for all platforms by spelling each out in full, instead of using
  a wild-card recipe.

* Fix Windows-installer target to properly recognize existing
  output files and not constantly rebuild every time.

* Include the podman version number in the Windows-installer target
  in case a user downloads multiple releases.

* Include a subdirectory containing the podman version number for
  both `tar.gz` and `zip` targets.  This prevents users clobbering
  existing directories when un-archiving from releases.

Signed-off-by: Chris Evich <[email protected]>
  • Loading branch information
cevich committed Apr 12, 2021
1 parent a468688 commit b6b0b6e
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ osx_alt_build_task:
script:
- brew install go
- brew install go-md2man
- make podman-remote-darwin
- make install-podman-remote-darwin-docs
- make podman-remote-release-darwin.zip
always: *binary_artifacts


Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ coverprofile
*.o
*.orig
/_output/
/podman_tmp_*
/pause/pause.o
pkg/api/swagger.yaml
podman-remote*.zip
podman*.tar.gz
/podman-remote*.zip
/podman*.tar.gz
/podman-*.msi
__pycache__
release.txt
.ropeproject
Expand Down
149 changes: 111 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ CROSS_BUILD_TARGETS := \
# Dereference variable $(1), return value if non-empty, otherwise raise an error.
err_if_empty = $(if $(strip $($(1))),$(strip $($(1))),$(error Required variable $(1) value is undefined, whitespace, or empty))

# Podman does not work w/o CGO_ENABLED, except in some very specific cases
CGO_ENABLED ?= 1
# Default to the native OS type and archetecture unless otherwise specified
GOOS ?= $(shell $(GO) env GOOS)
ifeq ($(call err_if_empty,GOOS),windows)
BINSFX := .exe
SRCBINDIR := bin/windows
else ifeq ($(GOOS),darwin)
BINSFX :=
SRCBINDIR := bin/darwin
else
BINSFX := -remote
SRCBINDIR := bin
endif
# Necessary for nested-$(MAKE) calls and docs/remote-docs.sh
export GOOS CGO_ENABLED BINSFX SRCBINDIR

define go-get
env GO111MODULE=off \
$(GO) get -u ${1}
Expand All @@ -163,7 +180,7 @@ default: all
all: binaries docs

.PHONY: binaries
binaries: podman podman-remote ## Build podman
binaries: podman podman-remote ## Build podman and podman-remote binaries

# Extract text following double-# for targets, as their description for
# the `help` target. Otherwise These simple-substitutions are resolved
Expand Down Expand Up @@ -272,47 +289,95 @@ ifeq (,$(findstring systemd,$(BUILDTAGS)))
Install libsystemd on Ubuntu or systemd-devel on rpm based \
distro for journald support."
endif
$(GO) build \
CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build \
$(BUILDFLAGS) \
-gcflags '$(GCFLAGS)' \
-asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags "$(BUILDTAGS)" \
-o $@ ./cmd/podman

.PHONY: podman
podman: bin/podman
# Disambiguate Linux vs Darwin/Windows platform binaries under distinct "bin" dirs
$(SRCBINDIR):
mkdir -p $(SRCBINDIR)

.PHONY: podman-remote
podman-remote: bin/podman-remote
$(SRCBINDIR)/podman$(BINSFX): $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.sum
CGO_ENABLED=$(CGO_ENABLED) \
GOOS=$(GOOS) \
$(GO) build \
$(BUILDFLAGS) \
-gcflags '$(GCFLAGS)' \
-asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags "${REMOTETAGS}" \
-o $@ ./cmd/podman

bin/podman-remote: .gopathok $(SOURCES) go.mod go.sum ## Build with podman on remote environment
$(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o $@ ./cmd/podman
$(SRCBINDIR)/podman-remote-static: $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.sum
CGO_ENABLED=$(CGO_ENABLED) \
GOOS=$(GOOS) \
$(GO) build \
$(BUILDFLAGS) \
-gcflags '$(GCFLAGS)' \
-asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN_STATIC)' \
-tags "${REMOTETAGS}" \
-o $@ ./cmd/podman

.PHONY: bin/podman-remote-static
podman-remote-static: bin/podman-remote-static
CGO_ENABLED=0 $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN_STATIC)' -tags "${REMOTETAGS}" -o bin/podman-remote-static ./cmd/podman
.PHONY: podman
podman: bin/podman

# Most-specific, first-match wins: must appear _after_ podman-remote-static
podman-remote-%: .gopathok ## Build podman for a specific GOOS
$(eval BINSFX := $(shell test "$*" != "windows" || echo ".exe"))
CGO_ENABLED=0 GOOS=$* $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags "${REMOTETAGS}" -o bin/$@$(BINSFX) ./cmd/podman
.PHONY: podman-remote
podman-remote: $(SRCBINDIR) $(SRCBINDIR)/podman$(BINSFX) ## Build podman-remote binary

# A wildcard podman-remote-% target incorrectly sets GOOS for release targets
.PHONY: podman-remote-linux
podman-remote-linux: ## Build podman-remote for Linux
$(MAKE) \
CGO_ENABLED=0 \
GOOS=linux \
bin/podman-remote

PHONY: podman-remote-static
podman-remote-static: $(SRCBINDIR)/podman-remote-static

.PHONY: podman-remote-windows
podman-remote-windows: ## Build podman-remote for Windows
$(MAKE) \
CGO_ENABLED=0 \
GOOS=windows \
bin/windows/podman.exe

.PHONY: podman-remote-darwin
podman-remote-darwin: ## Build podman-remote for MacOS
$(MAKE) \
CGO_ENABLED=0 \
GOOS=darwin \
bin/darwin/podman

###
### Secondary binary-build targets
###

.PHONY: generate-bindings
generate-bindings:
ifneq ($(shell uname -s), Darwin)
ifneq ($(GOOS),darwin)
GO111MODULE=off $(GO) generate ./pkg/bindings/... ;
endif

# DO NOT USE: use local-cross instead
bin/podman.cross.%: .gopathok
TARGET="$*"; \
GOOS="$${TARGET%%.*}" \
GOARCH="$${TARGET##*.}" \
CGO_ENABLED=0 $(GO) build $(BUILDFLAGS) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags '$(BUILDTAGS_CROSS)' -o "$@" ./cmd/podman
GOOS="$${TARGET%%.*}"; \
GOARCH="$${TARGET##*.}"; \
CGO_ENABLED=0 \
$(GO) build \
$(BUILDFLAGS) \
-gcflags '$(GCFLAGS)' \
-asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags '$(BUILDTAGS_CROSS)' \
-o "$@" ./cmd/podman

.PHONY: local-cross
local-cross: $(CROSS_BUILD_TARGETS) ## Cross compile podman binary for multiple architectures
Expand Down Expand Up @@ -371,7 +436,9 @@ docdir:
.PHONY: docs
docs: $(MANPAGES) ## Generate documentation

install-podman-remote-%-docs: podman-remote docs $(MANPAGES)
# docs/remote-docs.sh requires a locally executable 'podman-remote' binary
# in addition to the target-archetecture binary (if any).
install-podman-remote-%-docs: podman-remote-$(shell env -i HOME=$$HOME PATH=$$PATH go env GOOS) docs $(MANPAGES)
rm -rf docs/build/remote
mkdir -p docs/build/remote
ln -sf $(CURDIR)/docs/source/markdown/links docs/build/man/
Expand Down Expand Up @@ -399,7 +466,7 @@ docker-docs: docs
.PHONY: changelog
changelog: ## Generate updated changelog.txt from git logs
@echo "Creating changelog from $(CHANGELOG_BASE) to $(CHANGELOG_TARGET)"
$(eval TMPFILE := $(shell mktemp))
$(eval TMPFILE := $(shell mktemp podman_tmp_XXXX))
$(shell cat changelog.txt > $(TMPFILE))
$(shell echo "- Changelog for $(CHANGELOG_TARGET) ($(ISODATE)):" > changelog.txt)
$(shell git log --no-merges --format=" * %s" $(CHANGELOG_BASE)..$(CHANGELOG_TARGET) >> changelog.txt)
Expand All @@ -423,7 +490,7 @@ validate.completions:

.PHONY: run-docker-py-tests
run-docker-py-tests:
$(eval testLogs=$(shell mktemp))
$(eval testLogs=$(shell mktemp podman_tmp_XXXX))
./bin/podman run --rm --security-opt label=disable --privileged -v $(testLogs):/testLogs --net=host -e DOCKER_HOST=tcp://localhost:8080 $(DOCKERPY_IMAGE) sh -c "pytest $(DOCKERPY_TEST) "

.PHONY: localunit
Expand Down Expand Up @@ -480,7 +547,7 @@ remotesystem:
# podman server spews copious unhelpful output; ignore it.
rc=0;\
if timeout -v 1 true; then \
SOCK_FILE=$(shell mktemp --dry-run --tmpdir podman.XXXXXX);\
SOCK_FILE=$(shell mktemp --dry-run --tmpdir podman_tmp_XXXX);\
export PODMAN_SOCKET=unix:$$SOCK_FILE; \
./bin/podman system service --timeout=0 $$PODMAN_SOCKET > $(if $(PODMAN_SERVER_LOG),$(PODMAN_SERVER_LOG),/dev/null) 2>&1 & \
retry=5;\
Expand Down Expand Up @@ -529,32 +596,33 @@ tests-included:
###

podman-release.tar.gz: binaries docs ## Build all binaries, docs., and installation tree, into a tarball.
$(eval TMPDIR := $(shell mktemp -d -p '' podman_XXXX))
$(eval TMPDIR := $(shell mktemp -d podman_tmp_XXXX))
$(eval SUBDIR := podman-v$(RELEASE_NUMBER))
mkdir -p "$(TMPDIR)/$(SUBDIR)"
$(MAKE) install.bin install.man install.cni \
install.systemd "DESTDIR=$(TMPDIR)/$(SUBDIR)" "PREFIX=/usr"
tar -czvf $@ --xattrs -C "$(TMPDIR)" "./$(SUBDIR)"
-rm -rf "$(TMPDIR)"

# Must call make in-line: Dependency-spec. w/ wild-card.
podman-remote-release-%.zip:
$(MAKE) podman-remote-$* install-podman-remote-$*-docs \
RELEASE_BASENAME=$(shell hack/get_release_info.sh REMOTENAME) \
RELEASE_DIST=$* RELEASE_DIST_VER="-"
$(eval TMPDIR := $(shell mktemp -d -p '' $podman_remote_XXXX))
$(eval SUBDIR := podman-$(RELEASE_VERSION))
$(eval BINSFX := $(shell test "$*" != "windows" || echo ".exe"))
podman-remote-release-%.zip: podman-remote-% install-podman-remote-%-docs ## Build podman-remote for GOOS=%, docs., and installation zip.
$(eval TMPDIR := $(shell mktemp -d podman_tmp_XXXX))
$(eval SUBDIR := podman-$(RELEASE_NUMBER))
mkdir -p "$(TMPDIR)/$(SUBDIR)"
cp ./bin/podman-remote-$*$(BINSFX) "$(TMPDIR)/$(SUBDIR)/podman$(BINSFX)"
$(MAKE) \
GOOS=$* \
DESTDIR=$(TMPDIR)/ \
BINDIR=$(SUBDIR) \
SELINUXOPT="" \
install.remote-nobuild
cp -r ./docs/build/remote/$* "$(TMPDIR)/$(SUBDIR)/docs/"
cp ./contrib/remote/containers.conf "$(TMPDIR)/$(SUBDIR)/"
cd "$(TMPDIR)/$(SUBDIR)" && \
cd "$(TMPDIR)" && \
zip --recurse-paths "$(CURDIR)/$@" "./"
-rm -rf "$(TMPDIR)"

.PHONY: podman.msi
podman.msi: podman-remote podman-remote-windows install-podman-remote-windows-docs ## Will always rebuild exe as there is no podman-remote-windows.exe target to verify timestamp
podman.msi: podman-v$(RELEASE_NUMBER).msi ## Build podman-remote, package for installation on Windows
podman-v$(RELEASE_NUMBER).msi: podman-remote-windows install-podman-remote-windows-docs
$(eval DOCFILE := docs/build/remote/windows)
find $(DOCFILE) -print | \
wixl-heat --var var.ManSourceDir --component-group ManFiles \
Expand Down Expand Up @@ -593,8 +661,11 @@ install.catatonit:
.PHONY: install.remote-nobuild
install.remote-nobuild:
install ${SELINUXOPT} -d -m 755 $(DESTDIR)$(BINDIR)
install ${SELINUXOPT} -m 755 bin/podman-remote $(DESTDIR)$(BINDIR)/podman-remote
test -z "${SELINUXOPT}" || chcon --verbose --reference=$(DESTDIR)$(BINDIR)/podman-remote bin/podman-remote
install ${SELINUXOPT} -m 755 $(SRCBINDIR)/podman$(BINSFX) \
$(DESTDIR)$(BINDIR)/podman$(BINSFX)
test -z "${SELINUXOPT}" || \
chcon --verbose --reference=$(DESTDIR)$(BINDIR)/podman-remote \
bin/podman-remote

.PHONY: install.remote
install.remote: podman-remote install.remote-nobuild
Expand Down Expand Up @@ -746,11 +817,13 @@ uninstall:
rm -f ${DESTDIR}${USERSYSTEMDDIR}/podman.service

.PHONY: clean
clean: ## Clean artifacts
clean: ## Clean all make artifacts
rm -rf \
.gopathok \
_output \
$(wildcard podman-*.msi) \
$(wildcard podman-remote*.zip) \
$(wildcard podman_tmp_*) \
$(wildcard podman*.tar.gz) \
bin \
build \
Expand Down
5 changes: 2 additions & 3 deletions contrib/cirrus/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ function _run_build() {
# Ensure always start from clean-slate with all vendor modules downloaded
make clean
make vendor
make podman-release
make podman-remote-linux-release
make podman-release.tar.gz # includes podman, podman-remote, and docs
}
function _run_altbuild() {
Expand All @@ -219,7 +218,7 @@ function _run_altbuild() {
make build-all-new-commits GIT_BASE_BRANCH=origin/$DEST_BRANCH
;;
*Windows*)
make podman-remote-windows-release
make podman-remote-release-windows.zip
make podman.msi
;;
*Without*)
Expand Down
2 changes: 1 addition & 1 deletion contrib/msi/podman.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<CreateFolder/>
</Component>
<Component Id="MainExecutable" Guid="73752F94-6589-4C7B-ABED-39D655A19714">
<File Id="520C6E17-77A2-4F41-9611-30FA763A0702" Name="podman.exe" Source="bin/podman-remote-windows.exe" KeyPath="yes"/>
<File Id="520C6E17-77A2-4F41-9611-30FA763A0702" Name="podman.exe" Source="bin/windows/podman.exe" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
Expand Down
12 changes: 11 additions & 1 deletion docs/remote-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ PLATFORM=$1 ## linux, windows or darwin
TARGET=${2} ## where to output files
SOURCES=${@:3} ## directories to find markdown files

PODMAN=${PODMAN:-bin/podman-remote} ## location overridden for testing
# Overriden for testing. Native podman-remote binary expected filepaths
if [[ -z "$PODMAN" ]]; then
case $(env -i HOME=$HOME PATH=$PATH go env GOOS) in
windows)
PODMAN=bin/windows/podman.exe ;;
darwin)
PODMAN=bin/darwin/podman ;;
*) # Assume "linux"
PODMAN=bin/podman-remote ;;
esac
fi

function usage() {
echo >&2 "$0 PLATFORM TARGET SOURCES..."
Expand Down

0 comments on commit b6b0b6e

Please sign in to comment.