mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-06 17:32:26 +00:00
Split base/ into base/ and tools/
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
8
tools/go-compile/Dockerfile
Normal file
8
tools/go-compile/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM golang:1.7-alpine3.5
|
||||
RUN apk update && apk add --no-cache build-base git
|
||||
|
||||
RUN go get -u github.com/golang/lint/golint
|
||||
|
||||
COPY compile.sh /usr/bin/
|
||||
|
||||
ENTRYPOINT ["/usr/bin/compile.sh"]
|
29
tools/go-compile/Makefile
Normal file
29
tools/go-compile/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
.PHONY: tag push
|
||||
|
||||
BASE=golang:1.7-alpine3.5
|
||||
IMAGE=go-compile
|
||||
|
||||
default: push
|
||||
|
||||
hash: Dockerfile compile.sh
|
||||
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
|
||||
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
|
||||
docker run --rm --entrypoint=/bin/sh $(IMAGE):build -c 'cat /usr/local/go/bin/go /lib/apk/db/installed /go/bin/golint /usr/bin/compile.sh | sha1sum' | sed 's/ .*//' > hash
|
||||
|
||||
push: hash
|
||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
|
||||
docker push mobylinux/$(IMAGE):$(shell cat hash))
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
tag: hash
|
||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
clean:
|
||||
rm -f hash
|
||||
|
||||
.DELETE_ON_ERROR:
|
61
tools/go-compile/compile.sh
Executable file
61
tools/go-compile/compile.sh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is designed to compile a single package to a single binary
|
||||
# so it makes some assumptions about things to simplify config
|
||||
# to output a single binary (in a tarball) just use -o file
|
||||
# use --docker to output a tarball for input to docker build -
|
||||
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
echo "Usage: -o file"
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ $# = 0 ] && usage
|
||||
|
||||
while [ $# -gt 1 ]
|
||||
do
|
||||
flag="$1"
|
||||
case "$flag" in
|
||||
-o)
|
||||
out="$2"
|
||||
mkdir -p "$(dirname $2)"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ $# -gt 0 ] && usage
|
||||
[ -z "$out" ] && usage
|
||||
|
||||
package=$(basename "$out")
|
||||
|
||||
dir="$GOPATH/src/$package"
|
||||
|
||||
mkdir -p $dir
|
||||
|
||||
# untar input
|
||||
tar xf - -C $dir
|
||||
|
||||
cd $dir
|
||||
|
||||
# lint before building
|
||||
>&2 echo "gofmt..."
|
||||
test -z $(gofmt -s -l .| grep -v .pb. | grep -v */vendor/ | tee /dev/stderr)
|
||||
|
||||
>&2 echo "govet..."
|
||||
test -z $(go tool vet -printf=false . 2>&1 | grep -v */vendor/ | tee /dev/stderr)
|
||||
|
||||
>&2 echo "golint..."
|
||||
test -z $(find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr)
|
||||
|
||||
>&2 echo "go build..."
|
||||
|
||||
go build -o $out -buildmode pie --ldflags '-extldflags "-static"' "$package"
|
||||
|
||||
tar cf - $out
|
Reference in New Issue
Block a user