Skip to content

Commit d473e6e

Browse files
Merge pull request #5566 from openSUSE/static-binary
Add podman static build
2 parents 01f747f + c21258b commit d473e6e

File tree

12 files changed

+147
-1
lines changed

12 files changed

+147
-1
lines changed

.cirrus.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ success_task:
820820
- "test_build_cache_images"
821821
- "verify_test_built_images"
822822
- "docs"
823+
- "static_build"
823824
# FIXME remove when all v2 tests pass
824825
- "integration_test_temporary"
825826

@@ -835,3 +836,18 @@ success_task:
835836
memory: 1
836837

837838
success_script: '/usr/local/bin/entrypoint.sh ./$SCRIPT_BASE/success.sh |& ${TIMESTAMP}'
839+
840+
static_build_task:
841+
container:
842+
image: quay.io/podman/nix-podman:1.0.0
843+
cpu: 8
844+
memory: 12
845+
timeout_in: 20m
846+
depends_on:
847+
- "gating"
848+
build_script:
849+
- nix build -f nix
850+
binaries_artifacts:
851+
path: "result-bin/bin/podman"
852+
on_failure:
853+
failed_branch_script: '$CIRRUS_WORKING_DIR/$SCRIPT_BASE/notice_branch_failure.sh |& ${TIMESTAMP}'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ release.txt
3131
/test/copyimg/copyimg
3232
/test/goecho/goecho
3333
.vscode*
34+
result-bin

Containerfile-nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# vim: set syntax=dockerfile:
2+
FROM nixos/nix:latest
3+
4+
RUN apk add --no-cache bash git
5+
6+
COPY . /work
7+
WORKDIR work/nix
8+
RUN nix-build
9+
WORKDIR /
10+
RUN rm -rf work

Makefile

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ LDFLAGS_PODMAN ?= \
7474
-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO) \
7575
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \
7676
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
77-
-extldflags "$(LDFLAGS)"
77+
$(EXTRA_LDFLAGS)
7878
#Update to LIBSECCOMP_COMMIT should reflect in Dockerfile too.
7979
LIBSECCOMP_COMMIT := v2.3.3
8080
# Rarely if ever should integration tests take more than 50min,
@@ -217,6 +217,30 @@ bin/podman.cross.%: .gopathok
217217
GOARCH="$${TARGET##*.}" \
218218
$(GO_BUILD) -gcflags '$(GCFLAGS)' -asmflags '$(ASMFLAGS)' -ldflags '$(LDFLAGS_PODMAN)' -tags '$(BUILDTAGS_CROSS)' -o "$@" $(PROJECT)/cmd/podman
219219

220+
# Update nix/nixpkgs.json its latest master commit
221+
.PHONY: nixpkgs
222+
nixpkgs:
223+
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
224+
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
225+
226+
NIX_IMAGE ?= quay.io/podman/nix-podman:1.0.0
227+
228+
# Build the nix image as base for static builds
229+
.PHONY: nix-image
230+
nix-image:
231+
$(CONTAINER_RUNTIME) build -t $(NIX_IMAGE) -f Containerfile-nix .
232+
233+
# Build podman statically linked based on the default nix container image
234+
.PHONY: build-static
235+
build-static:
236+
$(CONTAINER_RUNTIME) run \
237+
--rm -it \
238+
-v $(shell pwd):/work \
239+
-w /work $(NIX_IMAGE) \
240+
sh -c "nix build -f nix && \
241+
mkdir -p bin && \
242+
cp result-*bin/bin/podman bin/podman-static"
243+
220244
.PHONY: run-docker-py-tests
221245
run-docker-py-tests:
222246
$(eval testLogs=$(shell mktemp))

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,9 @@ Podman offers a Varlink-based API for remote management of containers.
180180
However, this API has been deprecated by the REST API.
181181
Varlink support is in maintenance mode, and will be removed in a future release.
182182
For more details, you can see [this blog](https://podman.io/blogs/2020/01/17/podman-new-api.html).
183+
184+
## Static Binary Builds
185+
The Cirrus CI integration within this repository contains a `static_build` job
186+
which produces a static Podman binary for testing purposes. Please note that
187+
this binary is not officially supported with respect to feature-completeness
188+
and functionality and should be only used for testing.

libpod/define/info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type HostInfo struct {
3333
SwapFree int64 `json:"swapFree"`
3434
SwapTotal int64 `json:"swapTotal"`
3535
Uptime string `json:"uptime"`
36+
Linkmode string `json:"linkmode"`
3637
}
3738

3839
// SlirpInfo describes the slirp exectuable that

libpod/info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/containers/buildah"
1616
"github.com/containers/libpod/libpod/define"
17+
"github.com/containers/libpod/libpod/linkmode"
1718
"github.com/containers/libpod/pkg/cgroups"
1819
registries2 "github.com/containers/libpod/pkg/registries"
1920
"github.com/containers/libpod/pkg/rootless"
@@ -86,6 +87,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
8687
info := define.HostInfo{
8788
Arch: runtime.GOARCH,
8889
BuildahVersion: buildah.Version,
90+
Linkmode: linkmode.Linkmode(),
8991
CPUs: runtime.NumCPU(),
9092
Distribution: hostDistributionInfo,
9193
EventLogger: r.eventer.String(),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// +build !static
2+
3+
package linkmode
4+
5+
// Linkmode returns the linking mode (static/dynamic) for the build.
6+
func Linkmode() string {
7+
return "dynamic"
8+
}

libpod/linkmode/linkmode_static.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// +build static
2+
3+
package linkmode
4+
5+
// Linkmode returns the linking mode (static/dynamic) for the build.
6+
func Linkmode() string {
7+
return "static"
8+
}

nix/default.nix

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
let
2+
pkgs = import ./nixpkgs.nix {
3+
config = {
4+
packageOverrides = pkg: {
5+
go_1_12 = pkg.go_1_14;
6+
};
7+
};
8+
};
9+
10+
static = pkg: pkg.overrideAttrs(old: {
11+
configureFlags = (old.configureFlags or []) ++
12+
[ "--without-shared" "--disable-shared" ];
13+
dontDisableStatic = true;
14+
enableSharedExecutables = false;
15+
enableStatic = true;
16+
});
17+
18+
patchLvm2 = pkg: pkg.overrideAttrs(old: {
19+
configureFlags = [
20+
"--disable-cmdlib" "--disable-readline" "--disable-udev_rules"
21+
"--disable-udev_sync" "--enable-pkgconfig" "--enable-static_link"
22+
];
23+
preConfigure = old.preConfigure + ''
24+
substituteInPlace libdm/Makefile.in --replace \
25+
SUBDIRS=dm-tools SUBDIRS=
26+
substituteInPlace tools/Makefile.in --replace \
27+
"TARGETS += lvm.static" ""
28+
substituteInPlace tools/Makefile.in --replace \
29+
"INSTALL_LVM_TARGETS += install_tools_static" ""
30+
'';
31+
postInstall = "";
32+
});
33+
34+
self = {
35+
podman-static = (pkgs.podman.overrideAttrs(old: {
36+
name = "podman-static";
37+
buildInputs = old.buildInputs ++ (with pkgs; [
38+
(static pkgs.libassuan)
39+
(static pkgs.libgpgerror)
40+
git
41+
glibc
42+
glibc.static
43+
]);
44+
src = ./..;
45+
EXTRA_LDFLAGS = ''-linkmode external -extldflags "-static -lm"'';
46+
BUILDTAGS = ''static apparmor selinux seccomp systemd varlink containers_image_ostree_stub'';
47+
})).override {
48+
gpgme = (static pkgs.gpgme);
49+
libseccomp = (static pkgs.libseccomp);
50+
lvm2 = (patchLvm2 (static pkgs.lvm2));
51+
};
52+
};
53+
in self

0 commit comments

Comments
 (0)