Skip to content

Commit

Permalink
env: add alpine linux builder
Browse files Browse the repository at this point in the history
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 <bradfitz@golang.org>
  • Loading branch information
jessfraz authored and bradfitz committed Apr 11, 2017
1 parent d668f06 commit 5c1740d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/buildlet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/$@
Expand Down
4 changes: 4 additions & 0 deletions cmd/buildlet/stage0/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/$@
7 changes: 6 additions & 1 deletion cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions dashboard/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions env/linux-x86-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <golang-dev@googlegroups.com>

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
24 changes: 24 additions & 0 deletions env/linux-x86-alpine/Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5c1740d

Please sign in to comment.