Skip to content

Commit 5c1740d

Browse files
jessfrazbradfitz
authored andcommitted
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 <bradfitz@golang.org>
1 parent d668f06 commit 5c1740d

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

cmd/buildlet/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ buildlet.linux-amd64: FORCE
2020
go install golang.org/x/build/cmd/upload
2121
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false go-builder-data/$@
2222

23+
buildlet.linux-amd64-static: FORCE
24+
go install golang.org/x/build/cmd/upload
25+
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false --static go-builder-data/$@
26+
2327
buildlet.netbsd-amd64: FORCE
2428
go install golang.org/x/build/cmd/upload
2529
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet --public --cacheable=false go-builder-data/$@

cmd/buildlet/stage0/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ buildlet-stage0.linux-amd64-kube: FORCE
3636
go install golang.org/x/build/cmd/upload
3737
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false go-builder-data/$@
3838

39+
buildlet-stage0.linux-amd64-static: FORCE
40+
go install golang.org/x/build/cmd/upload
41+
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false --static go-builder-data/$@
42+
3943
buildlet-stage0.linux-s390x: FORCE
4044
go install golang.org/x/build/cmd/upload
4145
upload --verbose --osarch=$@ --file=go:golang.org/x/build/cmd/buildlet/stage0 --public --cacheable=false go-builder-data/$@

cmd/upload/upload.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
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'")
4242
extraEnv = flag.String("extraenv", "", "comma-separated list of addition KEY=val environment pairs to include in build environment when building a target to upload")
4343
installSuffix = flag.String("installsuffix", "", "installsuffix for the go command")
44+
static = flag.Bool("static", false, "compile the binary statically, adds necessary ldflags")
4445
)
4546

4647
func main() {
@@ -203,12 +204,16 @@ func buildGoTarget() {
203204
}
204205

205206
version := os.Getenv("USER") + "-" + time.Now().Format(time.RFC3339)
207+
ldflags := "-X main.Version=" + version
208+
if *static {
209+
ldflags = "-linkmode=external -extldflags '-static -pthread' " + ldflags
210+
}
206211
cmd = exec.Command("go",
207212
"install",
208213
"--tags="+*tags,
209214
"--installsuffix="+*installSuffix,
210215
"-x",
211-
"--ldflags=-X main.Version="+version,
216+
"--ldflags="+ldflags,
212217
target)
213218
var stderr bytes.Buffer
214219
cmd.Stderr = &stderr

dashboard/builders.go

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ var Hosts = map[string]*HostConfig{
5353
buildletURLTmpl: "https://storage.googleapis.com/$BUCKET/buildlet.linux-amd64",
5454
env: []string{"GOROOT_BOOTSTRAP=/go1.4"},
5555
},
56+
"host-linux-x86-alpine": &HostConfig{
57+
Notes: "Kubernetes alpine container on GKE.",
58+
KubeImage: "linux-x86-alpine:latest",
59+
buildletURLTmpl: "http://storage.googleapis.com/$BUCKET/buildlet.linux-amd64-static",
60+
env: []string{"GOROOT_BOOTSTRAP=/usr/lib/go"},
61+
},
5662
"host-linux-clang": &HostConfig{
5763
Notes: "GCE VM with clang.",
5864
VMImage: "linux-buildlet-clang",

env/linux-x86-alpine/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2017 The Go Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
# Alpine Linux builder
6+
# Docker tag gcr.io/go-dashboard-dev/linux-x86-alpine (staging)
7+
# and gcr.io/symbolic-datum-552/linux-x86-alpine (prod)
8+
9+
FROM alpine:3.5
10+
MAINTAINER golang-dev <golang-dev@googlegroups.com>
11+
12+
RUN apk add --no-cache \
13+
bash \
14+
binutils \
15+
build-base \
16+
ca-certificates \
17+
curl \
18+
gcc \
19+
gdb \
20+
gfortran \
21+
git \
22+
go \
23+
libc-dev \
24+
lsof \
25+
procps \
26+
strace
27+
28+
RUN curl -o /usr/local/bin/stage0 https://storage.googleapis.com/go-builder-data/buildlet-stage0.linux-amd64-static
29+
RUN chmod +x /usr/local/bin/stage0
30+
31+
ENV GOROOT_BOOTSTRAP=/usr/lib/go

env/linux-x86-alpine/Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2017 The Go Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
IMAGE_NAME=$(shell basename $(CURDIR))
5+
STAGING_REPO=gcr.io/go-dashboard-dev
6+
PROD_REPO=gcr.io/symbolic-datum-552
7+
8+
usage:
9+
echo "Use staging, prod, or dev targets. For dev, specify your Docker repository with the REPO=foo argument." ; exit 1
10+
11+
staging: Dockerfile
12+
docker build -t $(STAGING_REPO)/$(IMAGE_NAME):latest .
13+
gcloud docker push $(STAGING_REPO)/$(IMAGE_NAME):latest
14+
15+
prod: Dockerfile
16+
docker build -t $(PROD_REPO)/$(IMAGE_NAME):latest .
17+
gcloud docker push $(PROD_REPO)/$(IMAGE_NAME):latest
18+
19+
# You must provide a REPO=your-repo-name arg when you make
20+
# this targarget. REPO is the name of the Docker repository
21+
# that will be prefixed to the name of the image being built.
22+
dev: Dockerfile
23+
docker build -t $(REPO)/$(IMAGE_NAME):latest .
24+
gcloud docker push $(REPO)/$(IMAGE_NAME):latest

0 commit comments

Comments
 (0)