Add nix derivation for static builds
Signed-off-by: Wong Hoi Sing Edison <hswong3i@gmail.com>
This commit is contained in:
parent
e5f71bf4f9
commit
3a122aa3c8
|
@ -157,7 +157,7 @@ gce_instance:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
matrix:
|
matrix:
|
||||||
CROSS_TARGET: darwin
|
CROSS_TARGET: bin/buildah.darwin
|
||||||
|
|
||||||
setup_script: '${SCRIPT_BASE}/setup.sh |& ${_TIMESTAMP}'
|
setup_script: '${SCRIPT_BASE}/setup.sh |& ${_TIMESTAMP}'
|
||||||
build_script: '${SCRIPT_BASE}/build.sh |& ${_TIMESTAMP}'
|
build_script: '${SCRIPT_BASE}/build.sh |& ${_TIMESTAMP}'
|
||||||
|
|
|
@ -6,3 +6,4 @@ tests/tools/build
|
||||||
Dockerfile*
|
Dockerfile*
|
||||||
!/tests/bud/*/Dockerfile*
|
!/tests/bud/*/Dockerfile*
|
||||||
*.swp
|
*.swp
|
||||||
|
result
|
||||||
|
|
35
Makefile
35
Makefile
|
@ -33,33 +33,36 @@ CNI_COMMIT := $(shell sed -n 's;\tgithub.com/containernetworking/cni \([^ \n]*\)
|
||||||
RUNC_COMMIT := v1.0.0-rc8
|
RUNC_COMMIT := v1.0.0-rc8
|
||||||
LIBSECCOMP_COMMIT := release-2.3
|
LIBSECCOMP_COMMIT := release-2.3
|
||||||
|
|
||||||
EXTRALDFLAGS :=
|
EXTRA_LDFLAGS ?=
|
||||||
LDFLAGS := -ldflags '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT)' $(EXTRALDFLAGS)
|
LDFLAGS := -ldflags '-X main.GitCommit=$(GIT_COMMIT) -X main.buildInfo=$(SOURCE_DATE_EPOCH) -X main.cniVersion=$(CNI_COMMIT) $(EXTRA_LDFLAGS)'
|
||||||
SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go cmd/buildah/*.go docker/*.go pkg/blobcache/*.go pkg/cli/*.go pkg/parse/*.go util/*.go
|
SOURCES=*.go imagebuildah/*.go bind/*.go chroot/*.go cmd/buildah/*.go docker/*.go pkg/blobcache/*.go pkg/cli/*.go pkg/parse/*.go util/*.go
|
||||||
|
|
||||||
LINTFLAGS ?=
|
LINTFLAGS ?=
|
||||||
|
|
||||||
all: buildah imgtype docs
|
all: bin/buildah bin/imgtype docs
|
||||||
|
|
||||||
.PHONY: static
|
nixpkgs:
|
||||||
static: $(SOURCES)
|
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
|
||||||
$(MAKE) SECURITYTAGS="$(SECURITYTAGS)" STORAGETAGS=$(STATIC_STORAGETAGS) EXTRALDFLAGS='-ldflags "-extldflags '-static'"' BUILDAH=buildah.static binary
|
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
|
||||||
|
|
||||||
.PHONY: binary
|
.PHONY: bin/buildah
|
||||||
binary: $(SOURCES)
|
bin/buildah: $(SOURCES)
|
||||||
$(GO_BUILD) $(LDFLAGS) -o $(BUILDAH) $(BUILDFLAGS) ./cmd/buildah
|
$(GO_BUILD) $(LDFLAGS) -o $@ $(BUILDFLAGS) ./cmd/buildah
|
||||||
|
|
||||||
buildah: binary
|
.PHONY: buildah
|
||||||
|
buildah: bin/buildah
|
||||||
|
|
||||||
darwin:
|
.PHONY: bin/buildah.darwin
|
||||||
GOOS=darwin $(GO_BUILD) $(LDFLAGS) -o buildah.darwin -tags "containers_image_openpgp" ./cmd/buildah
|
bin/buildah.darwin:
|
||||||
|
GOOS=darwin $(GO_BUILD) $(LDFLAGS) -o $@ -tags "containers_image_openpgp" ./cmd/buildah
|
||||||
|
|
||||||
imgtype: *.go docker/*.go util/*.go tests/imgtype/imgtype.go
|
.PHONY: bin/imgtype
|
||||||
$(GO_BUILD) $(LDFLAGS) -o imgtype $(BUILDFLAGS) ./tests/imgtype/imgtype.go
|
bin/imgtype: *.go docker/*.go util/*.go tests/imgtype/imgtype.go
|
||||||
|
$(GO_BUILD) $(LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/imgtype/imgtype.go
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
$(RM) -r buildah imgtype build buildah.static buildah.darwin tests/testreport/testreport
|
$(RM) -r bin tests/testreport/testreport
|
||||||
$(MAKE) -C docs clean
|
$(MAKE) -C docs clean
|
||||||
|
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
|
@ -105,7 +108,7 @@ install.cni.sudo: gopath
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
install -D -m0755 buildah $(DESTDIR)/$(BINDIR)/buildah
|
install -D -m0755 bin/buildah $(DESTDIR)/$(BINDIR)/buildah
|
||||||
$(MAKE) -C docs install
|
$(MAKE) -C docs install
|
||||||
|
|
||||||
.PHONY: uninstall
|
.PHONY: uninstall
|
||||||
|
|
|
@ -20,10 +20,9 @@ else
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
if [[ -z "$CROSS_TARGET" ]]
|
if [[ -z "$CROSS_TARGET" ]]
|
||||||
then
|
then
|
||||||
ln -v buildah bin/buildah
|
|
||||||
showrun make install PREFIX=/usr
|
showrun make install PREFIX=/usr
|
||||||
showrun ./bin/buildah info
|
showrun ./bin/buildah info
|
||||||
else
|
else
|
||||||
ln -v buildah.${CROSS_TARGET} bin/buildah
|
ln -v ${CROSS_TARGET} bin/buildah
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -17,8 +17,8 @@ case $1 in
|
||||||
df) showrun df -lhTx tmpfs ;;
|
df) showrun df -lhTx tmpfs ;;
|
||||||
journal) showrun journalctl -b ;;
|
journal) showrun journalctl -b ;;
|
||||||
podman) showrun podman system info ;;
|
podman) showrun podman system info ;;
|
||||||
buildah_version) showrun $GOSRC/buildah version;;
|
buildah_version) showrun $GOSRC/bin/buildah version;;
|
||||||
buildah_info) showrun $GOSRC/buildah info;;
|
buildah_info) showrun $GOSRC/bin/buildah info;;
|
||||||
packages)
|
packages)
|
||||||
# These names are common to Fedora and Ubuntu
|
# These names are common to Fedora and Ubuntu
|
||||||
PKG_NAMES=(\
|
PKG_NAMES=(\
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
{ system ? builtins.currentSystem }:
|
||||||
|
let
|
||||||
|
pkgs = (import ./nixpkgs.nix {
|
||||||
|
config = {
|
||||||
|
packageOverrides = pkg: {
|
||||||
|
gpgme = (static pkg.gpgme);
|
||||||
|
libassuan = (static pkg.libassuan);
|
||||||
|
libgpgerror = (static pkg.libgpgerror);
|
||||||
|
libseccomp = (static pkg.libseccomp);
|
||||||
|
glib = pkg.glib.overrideAttrs(x: {
|
||||||
|
outputs = [ "bin" "out" "dev" ];
|
||||||
|
mesonFlags = [
|
||||||
|
"-Ddefault_library=static"
|
||||||
|
"-Ddevbindir=${placeholder ''dev''}/bin"
|
||||||
|
"-Dgtk_doc=false"
|
||||||
|
"-Dnls=disabled"
|
||||||
|
];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
static = pkg: pkg.overrideAttrs(x: {
|
||||||
|
configureFlags = (x.configureFlags or []) ++
|
||||||
|
[ "--without-shared" "--disable-shared" ];
|
||||||
|
dontDisableStatic = true;
|
||||||
|
enableSharedExecutables = false;
|
||||||
|
enableStatic = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
self = with pkgs; buildGoPackage rec {
|
||||||
|
name = "buildah";
|
||||||
|
src = ./..;
|
||||||
|
goPackagePath = "github.com/containers/buildah";
|
||||||
|
doCheck = false;
|
||||||
|
enableParallelBuilding = true;
|
||||||
|
nativeBuildInputs = [ git installShellFiles pkg-config ];
|
||||||
|
buildInputs = [ glib glibc glibc.static gpgme libapparmor libassuan libgpgerror libseccomp libselinux ];
|
||||||
|
prePatch = ''
|
||||||
|
export LDFLAGS='-s -w -static-libgcc -static'
|
||||||
|
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
|
||||||
|
export BUILDTAGS='static netgo apparmor selinux seccomp exclude_graphdriver_btrfs exclude_graphdriver_devicemapper'
|
||||||
|
'';
|
||||||
|
buildPhase = ''
|
||||||
|
pushd go/src/${goPackagePath}
|
||||||
|
patchShebangs .
|
||||||
|
make bin/buildah
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
install -Dm755 bin/buildah $out/bin/buildah
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in self
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nixos/nixpkgs",
|
||||||
|
"rev": "78e324d2726127828a15f87a75b4d3199a8955ec",
|
||||||
|
"date": "2020-06-16T18:23:14-07:00",
|
||||||
|
"path": "/nix/store/bwhp0061k3fk00j8fskpfak261jdcjl6-nixpkgs",
|
||||||
|
"sha256": "1j58aa9ngdmvbnds4x4a497nynj390dzqyb5yrvmhjc7k9anq6jm",
|
||||||
|
"fetchSubmodules": false,
|
||||||
|
"deepClone": false,
|
||||||
|
"leaveDotGit": false
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
let
|
||||||
|
json = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
|
||||||
|
nixpkgs = import (builtins.fetchTarball {
|
||||||
|
name = "nixos-unstable";
|
||||||
|
url = "${json.url}/archive/${json.rev}.tar.gz";
|
||||||
|
inherit (json) sha256;
|
||||||
|
});
|
||||||
|
in nixpkgs
|
|
@ -95,7 +95,7 @@ func CreateTempDirInTempDir() (string, error) {
|
||||||
func BuildahCreate(tempDir string) BuildAhTest {
|
func BuildahCreate(tempDir string) BuildAhTest {
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
buildAhBinary := filepath.Join(cwd, "../../buildah")
|
buildAhBinary := filepath.Join(cwd, "../../bin/buildah")
|
||||||
if os.Getenv("BUILDAH_BINARY") != "" {
|
if os.Getenv("BUILDAH_BINARY") != "" {
|
||||||
buildAhBinary = os.Getenv("BUILDAH_BINARY")
|
buildAhBinary = os.Getenv("BUILDAH_BINARY")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
BUILDAH_BINARY=${BUILDAH_BINARY:-$(dirname ${BASH_SOURCE})/../buildah}
|
BUILDAH_BINARY=${BUILDAH_BINARY:-$(dirname ${BASH_SOURCE})/../bin/buildah}
|
||||||
IMGTYPE_BINARY=${IMGTYPE_BINARY:-$(dirname ${BASH_SOURCE})/../imgtype}
|
IMGTYPE_BINARY=${IMGTYPE_BINARY:-$(dirname ${BASH_SOURCE})/../bin/imgtype}
|
||||||
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
|
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
|
||||||
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
|
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
|
||||||
PATH=$(dirname ${BASH_SOURCE})/..:${PATH}
|
PATH=$(dirname ${BASH_SOURCE})/..:${PATH}
|
||||||
|
|
Loading…
Reference in New Issue