mirror of
https://github.com/containers/skopeo.git
synced 2025-08-18 14:37:16 +00:00
Add nix derivation for static builds
Signed-off-by: Wong Hoi Sing Edison <hswong3i@gmail.com>
This commit is contained in:
parent
091f9248dc
commit
0f458eec76
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
*.1
|
*.1
|
||||||
/layers-*
|
/layers-*
|
||||||
/skopeo
|
/skopeo
|
||||||
|
result
|
||||||
|
|
||||||
# ignore JetBrains IDEs (GoLand) config folder
|
# ignore JetBrains IDEs (GoLand) config folder
|
||||||
.idea
|
.idea
|
30
Makefile
30
Makefile
@ -62,6 +62,9 @@ CONTAINER_RUN := $(CONTAINER_CMD) "$(IMAGE)"
|
|||||||
|
|
||||||
GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
|
GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
|
||||||
|
|
||||||
|
EXTRA_LDFLAGS ?=
|
||||||
|
LDFLAGS := -ldflags '-X main.gitCommit=${GIT_COMMIT} $(EXTRA_LDFLAGS)'
|
||||||
|
|
||||||
MANPAGES_MD = $(wildcard docs/*.md)
|
MANPAGES_MD = $(wildcard docs/*.md)
|
||||||
MANPAGES ?= $(MANPAGES_MD:%.md=%)
|
MANPAGES ?= $(MANPAGES_MD:%.md=%)
|
||||||
|
|
||||||
@ -85,7 +88,7 @@ help:
|
|||||||
@echo
|
@echo
|
||||||
@echo " * 'install' - Install binaries and documents to system locations"
|
@echo " * 'install' - Install binaries and documents to system locations"
|
||||||
@echo " * 'binary' - Build skopeo with a container"
|
@echo " * 'binary' - Build skopeo with a container"
|
||||||
@echo " * 'binary-local' - Build skopeo locally"
|
@echo " * 'bin/skopeo' - Build skopeo locally"
|
||||||
@echo " * 'test-unit' - Execute unit tests"
|
@echo " * 'test-unit' - Execute unit tests"
|
||||||
@echo " * 'test-integration' - Execute integration tests"
|
@echo " * 'test-integration' - Execute integration tests"
|
||||||
@echo " * 'validate' - Verify whether there is no conflict and all Go source files have been formatted, linted and vetted"
|
@echo " * 'validate' - Verify whether there is no conflict and all Go source files have been formatted, linted and vetted"
|
||||||
@ -98,19 +101,18 @@ help:
|
|||||||
binary: cmd/skopeo
|
binary: cmd/skopeo
|
||||||
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f Dockerfile.build -t skopeobuildimage .
|
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f Dockerfile.build -t skopeobuildimage .
|
||||||
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
|
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
|
||||||
skopeobuildimage make binary-local $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
|
skopeobuildimage make bin/skopeo $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
|
||||||
|
|
||||||
binary-static: cmd/skopeo
|
# Update nix/nixpkgs.json its latest master commit
|
||||||
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f Dockerfile.build -t skopeobuildimage .
|
.PHONY: nixpkgs
|
||||||
${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/src/github.com/containers/skopeo \
|
nixpkgs:
|
||||||
skopeobuildimage make binary-local-static $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
|
@nix run -f channel:nixpkgs-unstable nix-prefetch-git -c nix-prefetch-git \
|
||||||
|
--no-deepClone https://github.com/nixos/nixpkgs > nix/nixpkgs.json
|
||||||
|
|
||||||
# Build w/o using containers
|
# Build w/o using containers
|
||||||
binary-local:
|
.PHONY: bin/skopeo
|
||||||
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo
|
bin/skopeo:
|
||||||
|
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) ${GO_DYN_FLAGS} ${LDFLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $@ ./cmd/skopeo
|
||||||
binary-local-static:
|
|
||||||
$(GPGME_ENV) $(GO) build $(MOD_VENDOR) -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo
|
|
||||||
|
|
||||||
build-container:
|
build-container:
|
||||||
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .
|
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .
|
||||||
@ -126,7 +128,7 @@ docs-in-container:
|
|||||||
skopeobuildimage make docs $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
|
skopeobuildimage make docs $(if $(DEBUG),DEBUG=$(DEBUG)) BUILDTAGS='$(BUILDTAGS)'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f skopeo docs/*.1
|
rm -f bin docs/*.1
|
||||||
|
|
||||||
install: install-binary install-docs install-completions
|
install: install-binary install-docs install-completions
|
||||||
install -d -m 755 ${SIGSTOREDIR}
|
install -d -m 755 ${SIGSTOREDIR}
|
||||||
@ -135,9 +137,9 @@ install: install-binary install-docs install-completions
|
|||||||
install -d -m 755 ${REGISTRIESDDIR}
|
install -d -m 755 ${REGISTRIESDDIR}
|
||||||
install -m 644 default.yaml ${REGISTRIESDDIR}/default.yaml
|
install -m 644 default.yaml ${REGISTRIESDDIR}/default.yaml
|
||||||
|
|
||||||
install-binary: ./skopeo
|
install-binary: bin/skopeo
|
||||||
install -d -m 755 ${INSTALLDIR}
|
install -d -m 755 ${INSTALLDIR}
|
||||||
install -m 755 skopeo ${INSTALLDIR}/skopeo
|
install -m 755 bin/skopeo ${INSTALLDIR}/skopeo
|
||||||
|
|
||||||
install-docs: docs
|
install-docs: docs
|
||||||
install -d -m 755 ${MANINSTALLDIR}/man1
|
install -d -m 755 ${MANINSTALLDIR}/man1
|
||||||
|
@ -29,7 +29,7 @@ mkdir /root/skopeo; \
|
|||||||
git clone https://github.com/containers/skopeo /root/skopeo/src/github.com/containers/skopeo; \
|
git clone https://github.com/containers/skopeo /root/skopeo/src/github.com/containers/skopeo; \
|
||||||
export GOPATH=/root/skopeo; \
|
export GOPATH=/root/skopeo; \
|
||||||
cd /root/skopeo/src/github.com/containers/skopeo; \
|
cd /root/skopeo/src/github.com/containers/skopeo; \
|
||||||
make binary-local;\
|
make bin/skopeo;\
|
||||||
make install;\
|
make install;\
|
||||||
rm -rf /root/skopeo/*; \
|
rm -rf /root/skopeo/*; \
|
||||||
yum -y remove git golang go-md2man make; \
|
yum -y remove git golang go-md2man make; \
|
||||||
|
@ -8,7 +8,7 @@ bundle_test_integration() {
|
|||||||
|
|
||||||
# subshell so that we can export PATH without breaking other things
|
# subshell so that we can export PATH without breaking other things
|
||||||
(
|
(
|
||||||
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
|
make bin/skopeo ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
|
||||||
make install
|
make install
|
||||||
bundle_test_integration
|
bundle_test_integration
|
||||||
) 2>&1
|
) 2>&1
|
||||||
|
@ -11,7 +11,7 @@ sed -i \
|
|||||||
/etc/containers/storage.conf
|
/etc/containers/storage.conf
|
||||||
|
|
||||||
# Build skopeo, install into /usr/bin
|
# Build skopeo, install into /usr/bin
|
||||||
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
|
make bin/skopeo ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
|
||||||
make install
|
make install
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
|
@ -12,6 +12,6 @@ go version
|
|||||||
GO111MODULE=off go get -u github.com/cpuguy83/go-md2man golang.org/x/lint/golint
|
GO111MODULE=off go get -u github.com/cpuguy83/go-md2man golang.org/x/lint/golint
|
||||||
|
|
||||||
cd ${_containers}/skopeo
|
cd ${_containers}/skopeo
|
||||||
make validate-local test-unit-local binary-local
|
make validate-local test-unit-local bin/skopeo
|
||||||
sudo make install
|
sudo make install
|
||||||
skopeo -v
|
skopeo -v
|
||||||
|
@ -114,7 +114,7 @@ Make sure to clone this repository in your `GOPATH` - otherwise compilation fail
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo
|
$ git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo
|
||||||
$ cd $GOPATH/src/github.com/containers/skopeo && make binary-local
|
$ cd $GOPATH/src/github.com/containers/skopeo && make bin/skopeo
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building in a container
|
### Building in a container
|
||||||
|
@ -19,7 +19,7 @@ to start a container, then within the container:
|
|||||||
SKOPEO_CONTAINER_TESTS=1 PS1='nested> ' go test -tags openshift_shell -timeout=24h ./integration -v -check.v -check.vv -check.f='CopySuite.TestRunShell'
|
SKOPEO_CONTAINER_TESTS=1 PS1='nested> ' go test -tags openshift_shell -timeout=24h ./integration -v -check.v -check.vv -check.f='CopySuite.TestRunShell'
|
||||||
|
|
||||||
An example of what can be done within the container:
|
An example of what can be done within the container:
|
||||||
cd ..; make binary-local install
|
cd ..; make bin/skopeo install
|
||||||
./skopeo --tls-verify=false copy --sign-by=personal@example.com docker://busybox:latest atomic:localhost:5000/myns/personal:personal
|
./skopeo --tls-verify=false copy --sign-by=personal@example.com docker://busybox:latest atomic:localhost:5000/myns/personal:personal
|
||||||
oc get istag personal:personal -o json
|
oc get istag personal:personal -o json
|
||||||
curl -L -v 'http://localhost:5000/v2/'
|
curl -L -v 'http://localhost:5000/v2/'
|
||||||
|
43
nix/default.nix
Normal file
43
nix/default.nix
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{ system ? builtins.currentSystem }:
|
||||||
|
let
|
||||||
|
pkgs = (import ./nixpkgs.nix {
|
||||||
|
config = {
|
||||||
|
packageOverrides = pkg: {
|
||||||
|
gpgme = (static pkg.gpgme);
|
||||||
|
libassuan = (static pkg.libassuan);
|
||||||
|
libgpgerror = (static pkg.libgpgerror);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
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 = "skopeo";
|
||||||
|
src = ./..;
|
||||||
|
goPackagePath = "github.com/containers/skopeo";
|
||||||
|
doCheck = false;
|
||||||
|
enableParallelBuilding = true;
|
||||||
|
nativeBuildInputs = [ git go-md2man installShellFiles makeWrapper pkg-config ];
|
||||||
|
buildInputs = [ glibc glibc.static gpgme libassuan libgpgerror ];
|
||||||
|
prePatch = ''
|
||||||
|
export LDFLAGS='-s -w -static-libgcc -static'
|
||||||
|
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
|
||||||
|
export BUILDTAGS='static netgo exclude_graphdriver_btrfs exclude_graphdriver_devicemapper'
|
||||||
|
'';
|
||||||
|
buildPhase = ''
|
||||||
|
pushd go/src/${goPackagePath}
|
||||||
|
patchShebangs .
|
||||||
|
make bin/skopeo
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
install -Dm755 bin/skopeo $out/bin/skopeo
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in self
|
10
nix/nixpkgs.json
Normal file
10
nix/nixpkgs.json
Normal file
@ -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
|
||||||
|
}
|
8
nix/nixpkgs.nix
Normal file
8
nix/nixpkgs.nix
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user