Skip to content

Commit a6a1259

Browse files
committed
Add nix derivation for static builds
1 parent 091f924 commit a6a1259

File tree

11 files changed

+82
-18
lines changed

11 files changed

+82
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.1
22
/layers-*
33
/skopeo
4+
result
45

56
# ignore JetBrains IDEs (GoLand) config folder
6-
.idea
7+
.idea

Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ CONTAINER_RUN := $(CONTAINER_CMD) "$(IMAGE)"
6262

6363
GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
6464

65+
EXTRA_LDFLAGS ?=
66+
LDFLAGS := -ldflags '-X main.gitCommit=${GIT_COMMIT} $(EXTRA_LDFLAGS)'
67+
6568
MANPAGES_MD = $(wildcard docs/*.md)
6669
MANPAGES ?= $(MANPAGES_MD:%.md=%)
6770

@@ -85,7 +88,7 @@ help:
8588
@echo
8689
@echo " * 'install' - Install binaries and documents to system locations"
8790
@echo " * 'binary' - Build skopeo with a container"
88-
@echo " * 'binary-local' - Build skopeo locally"
91+
@echo " * 'bin/skopeo' - Build skopeo locally"
8992
@echo " * 'test-unit' - Execute unit tests"
9093
@echo " * 'test-integration' - Execute integration tests"
9194
@echo " * 'validate' - Verify whether there is no conflict and all Go source files have been formatted, linted and vetted"
@@ -98,19 +101,18 @@ help:
98101
binary: cmd/skopeo
99102
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f Dockerfile.build -t skopeobuildimage .
100103
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
101-
skopeobuildimage make binary-local $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
104+
skopeobuildimage make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
102105

103-
binary-static: cmd/skopeo
104-
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f Dockerfile.build -t skopeobuildimage .
105-
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
106-
skopeobuildimage make binary-local-static $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
106+
# Update nix/nixpkgs.json its latest master commit
107+
.PHONY: nixpkgs
108+
nixpkgs:
109+
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
110+
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
107111

108112
# Build w/o using containers
109-
binary-local:
110-
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo
111-
112-
binary-local-static:
113-
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo
113+
.PHONY: bin/skopeo
114+
bin/skopeo:
115+
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} ${LDFLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $@ ./cmd/skopeo
114116

115117
build-container:
116118
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .

contrib/skopeoimage/upstream/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mkdir /root/skopeo; \
2929
git clone https://github.com/containers/skopeo /root/skopeo/src/github.com/containers/skopeo; \
3030
export GOPATH=/root/skopeo; \
3131
cd /root/skopeo/src/github.com/containers/skopeo; \
32-
make binary-local;\
32+
make bin/skopeo;\
3333
make install;\
3434
rm -rf /root/skopeo/*; \
3535
yum -y remove git golang go-md2man make; \

hack/make/test-integration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bundle_test_integration() {
88

99
# subshell so that we can export PATH without breaking other things
1010
(
11-
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
11+
make bin/skopeo ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
1212
make install
1313
bundle_test_integration
1414
) 2>&1

hack/make/test-system

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sed -i \
1111
/etc/containers/storage.conf
1212

1313
# Build skopeo, install into /usr/bin
14-
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
14+
make bin/skopeo ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
1515
make install
1616

1717
# Run tests

hack/travis_osx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ go version
1212
GO111MODULE=off go get -u github.com/cpuguy83/go-md2man golang.org/x/lint/golint
1313

1414
cd ${_containers}/skopeo
15-
make validate-local test-unit-local binary-local
15+
make validate-local test-unit-local bin/skopeo
1616
sudo make install
1717
skopeo -v

install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Make sure to clone this repository in your `GOPATH` - otherwise compilation fail
114114

115115
```bash
116116
$ git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo
117-
$ cd $GOPATH/src/github.com/containers/skopeo && make binary-local
117+
$ cd $GOPATH/src/github.com/containers/skopeo && make bin/skopeo
118118
```
119119

120120
### Building in a container

integration/openshift_shell_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ to start a container, then within the container:
1919
SKOPEO_CONTAINER_TESTS=1 PS1='nested> ' go test -tags openshift_shell -timeout=24h ./integration -v -check.v -check.vv -check.f='CopySuite.TestRunShell'
2020
2121
An example of what can be done within the container:
22-
cd ..; make binary-local install
22+
cd ..; make bin/skopeo install
2323
./skopeo --tls-verify=false copy --sign-by=personal@example.com docker://busybox:latest atomic:localhost:5000/myns/personal:personal
2424
oc get istag personal:personal -o json
2525
curl -L -v 'http://localhost:5000/v2/'

nix/default.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ system ? builtins.currentSystem }:
2+
let
3+
pkgs = (import ./nixpkgs.nix {
4+
config = {
5+
packageOverrides = pkg: {
6+
gpgme = (static pkg.gpgme);
7+
libassuan = (static pkg.libassuan);
8+
libgpgerror = (static pkg.libgpgerror);
9+
};
10+
};
11+
});
12+
13+
static = pkg: pkg.overrideAttrs(x: {
14+
configureFlags = (x.configureFlags or []) ++
15+
[ "--without-shared" "--disable-shared" ];
16+
dontDisableStatic = true;
17+
enableSharedExecutables = false;
18+
enableStatic = true;
19+
});
20+
21+
self = with pkgs; buildGoPackage rec {
22+
name = "skopeo";
23+
src = ./..;
24+
goPackagePath = "github.com/containers/skopeo";
25+
doCheck = false;
26+
enableParallelBuilding = true;
27+
nativeBuildInputs = [ git go-md2man installShellFiles makeWrapper pkg-config ];
28+
buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror ];
29+
prePatch = ''
30+
export LDFLAGS='-s -w -static-libgcc -static'
31+
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
32+
export BUILDTAGS='static netgo exclude_graphdriver_btrfs exclude_graphdriver_devicemapper'
33+
'';
34+
buildPhase = ''
35+
pushd go/src/${goPackagePath}
36+
patchShebangs .
37+
make bin/skopeo
38+
'';
39+
installPhase = ''
40+
install -Dm755 bin/skopeo $out/bin/skopeo
41+
'';
42+
};
43+
in self

nix/nixpkgs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"url": "https://github.com/nixos/nixpkgs",
3+
"rev": "78e324d2726127828a15f87a75b4d3199a8955ec",
4+
"date": "2020-06-16T18:23:14-07:00",
5+
"path": "/nix/store/bwhp0061k3fk00j8fskpfak261jdcjl6-nixpkgs",
6+
"sha256": "1j58aa9ngdmvbnds4x4a497nynj390dzqyb5yrvmhjc7k9anq6jm",
7+
"fetchSubmodules": false,
8+
"deepClone": false,
9+
"leaveDotGit": false
10+
}

0 commit comments

Comments
 (0)