From 5c1740d89a39354c32602ef07cfc0cf9b11c1616 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 2 Dec 2016 11:14:12 -0800 Subject: [PATCH] env: add alpine linux builder Adds flag to upload to build binary statically. Updates golang/go#17891 Change-Id: If19b2e2cf9a84fa2b4cc6fdf55d8add5b54abff7 Reviewed-on: https://go-review.googlesource.com/33890 Reviewed-by: Brad Fitzpatrick --- cmd/buildlet/Makefile | 4 ++++ cmd/buildlet/stage0/Makefile | 4 ++++ cmd/upload/upload.go | 7 ++++++- dashboard/builders.go | 6 ++++++ env/linux-x86-alpine/Dockerfile | 31 +++++++++++++++++++++++++++++++ env/linux-x86-alpine/Makefile | 24 ++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 env/linux-x86-alpine/Dockerfile create mode 100644 env/linux-x86-alpine/Makefile diff --git a/cmd/buildlet/Makefile b/cmd/buildlet/Makefile index a442e560bd..2080e92917 100644 --- a/cmd/buildlet/Makefile +++ b/cmd/buildlet/Makefile @@ -20,6 +20,10 @@ buildlet.linux-amd64: FORCE go install golang.org/x/build/cmd/upload upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false go-builder-data/$@ +buildlet.linux-amd64-static: FORCE + go install golang.org/x/build/cmd/upload + upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false --static go-builder-data/$@ + buildlet.netbsd-amd64: FORCE go install golang.org/x/build/cmd/upload upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false go-builder-data/$@ diff --git a/cmd/buildlet/stage0/Makefile b/cmd/buildlet/stage0/Makefile index d7554a5fa5..6ed226af09 100644 --- a/cmd/buildlet/stage0/Makefile +++ b/cmd/buildlet/stage0/Makefile @@ -36,6 +36,10 @@ buildlet-stage0.linux-amd64-kube: FORCE go install golang.org/x/build/cmd/upload upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false go-builder-data/$@ +buildlet-stage0.linux-amd64-static: FORCE + go install golang.org/x/build/cmd/upload + upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false --static go-builder-data/$@ + buildlet-stage0.linux-s390x: FORCE go install golang.org/x/build/cmd/upload upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false go-builder-data/$@ diff --git a/cmd/upload/upload.go b/cmd/upload/upload.go index ae5ce6d8b4..38d710599d 100644 --- a/cmd/upload/upload.go +++ b/cmd/upload/upload.go @@ -41,6 +41,7 @@ var ( doGzip = flag.Bool("gzip", false, "gzip the stored contents (not the upload's Content-Encoding); this forces the Content-Type to be application/octet-stream. To prevent misuse, the object name must also end in '.gz'") extraEnv = flag.String("extraenv", "", "comma-separated list of addition KEY=val environment pairs to include in build environment when building a target to upload") installSuffix = flag.String("installsuffix", "", "installsuffix for the go command") + static = flag.Bool("static", false, "compile the binary statically, adds necessary ldflags") ) func main() { @@ -203,12 +204,16 @@ func buildGoTarget() { } version := os.Getenv("USER") + "-" + time.Now().Format(time.RFC3339) + ldflags := "-X main.Version=" + version + if *static { + ldflags = "-linkmode=external -extldflags '-static -pthread' " + ldflags + } cmd = exec.Command("go", "install", "--tags="+*tags, "--installsuffix="+*installSuffix, "-x", - "--ldflags=-X main.Version="+version, + "--ldflags="+ldflags, target) var stderr bytes.Buffer cmd.Stderr = &stderr diff --git a/dashboard/builders.go b/dashboard/builders.go index 5e8e334bba..1d3ef9d7b7 100644 --- a/dashboard/builders.go +++ b/dashboard/builders.go @@ -53,6 +53,12 @@ var Hosts = map[string]*HostConfig{ buildletURLTmpl: "https://storage.googleapis.com/$BUCKET/buildlet.linux-amd64", env: []string{"GOROOT_BOOTSTRAP=/go1.4"}, }, + "host-linux-x86-alpine": &HostConfig{ + Notes: "Kubernetes alpine container on GKE.", + KubeImage: "linux-x86-alpine:latest", + buildletURLTmpl: "http://storage.googleapis.com/$BUCKET/buildlet.linux-amd64-static", + env: []string{"GOROOT_BOOTSTRAP=/usr/lib/go"}, + }, "host-linux-clang": &HostConfig{ Notes: "GCE VM with clang.", VMImage: "linux-buildlet-clang", diff --git a/env/linux-x86-alpine/Dockerfile b/env/linux-x86-alpine/Dockerfile new file mode 100644 index 0000000000..5f55ce30e0 --- /dev/null +++ b/env/linux-x86-alpine/Dockerfile @@ -0,0 +1,31 @@ +# Copyright 2017 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# Alpine Linux builder +# Docker tag gcr.io/go-dashboard-dev/linux-x86-alpine (staging) +# and gcr.io/symbolic-datum-552/linux-x86-alpine (prod) + +FROM alpine:3.5 +MAINTAINER golang-dev + +RUN apk add --no-cache \ + bash \ + binutils \ + build-base \ + ca-certificates \ + curl \ + gcc \ + gdb \ + gfortran \ + git \ + go \ + libc-dev \ + lsof \ + procps \ + strace + +RUN curl -o /usr/local/bin/stage0 https://storage.googleapis.com/go-builder-data/buildlet-stage0.linux-amd64-static +RUN chmod +x /usr/local/bin/stage0 + +ENV GOROOT_BOOTSTRAP=/usr/lib/go diff --git a/env/linux-x86-alpine/Makefile b/env/linux-x86-alpine/Makefile new file mode 100644 index 0000000000..a863928e19 --- /dev/null +++ b/env/linux-x86-alpine/Makefile @@ -0,0 +1,24 @@ +# Copyright 2017 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. +IMAGE_NAME=$(shell basename $(CURDIR)) +STAGING_REPO=gcr.io/go-dashboard-dev +PROD_REPO=gcr.io/symbolic-datum-552 + +usage: + echo "Use staging, prod, or dev targets. For dev, specify your Docker repository with the REPO=foo argument." ; exit 1 + +staging: Dockerfile + docker build -t $(STAGING_REPO)/$(IMAGE_NAME):latest . + gcloud docker push $(STAGING_REPO)/$(IMAGE_NAME):latest + +prod: Dockerfile + docker build -t $(PROD_REPO)/$(IMAGE_NAME):latest . + gcloud docker push $(PROD_REPO)/$(IMAGE_NAME):latest + +# You must provide a REPO=your-repo-name arg when you make +# this targarget. REPO is the name of the Docker repository +# that will be prefixed to the name of the image being built. +dev: Dockerfile + docker build -t $(REPO)/$(IMAGE_NAME):latest . + gcloud docker push $(REPO)/$(IMAGE_NAME):latest