Skip to content

Commit

Permalink
Reference go-ethereum pull request #17247
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe3b0c4 committed Aug 8, 2022
1 parent 6ec8a39 commit cfbeb69
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.17-alpine as builder
FROM golang:1.17-alpine3.16 as builder

RUN apk add --no-cache make gcc musl-dev libc6-compat linux-headers git bash
RUN apk add --no-cache make gcc musl-dev linux-headers git bash

ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
RUN cd /go-ethereum && make geth-static

# Pull Geth into a second stage deploy alpine container
FROM alpine:3.16
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.alltools
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.17-alpine as builder
FROM golang:1.17-alpine3.16 as builder

RUN apk add --no-cache gcc musl-dev libc6-compat linux-headers git bash
RUN apk add --no-cache make gcc musl-dev linux-headers git bash

ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static
RUN cd /go-ethereum && make all-static

# Pull all binaries into a second stage deploy alpine container
FROM alpine:3.16
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ geth:
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

geth-static:
$(GORUN) build/ci.go install -static ./cmd/geth
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

all:
$(GORUN) build/ci.go install

all-static:
$(GORUN) build/ci.go install -static

android:
$(GORUN) build/ci.go aar --local
@echo "Done building."
Expand Down
32 changes: 17 additions & 15 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ Usage: go run build/ci.go <command> <command flags/arguments>
Available commands are:
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
archive [ -arch architecture ] [ -type zip|tar ] [ -signer key-envvar ] [ -signify key-envvar ] [ -upload dest ] -- archives build artifacts
importkeys -- imports signing keys from env
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
archive [ -arch architecture ] [ -type zip|tar ] [ -signer key-envvar ] [ -signify key-envvar ] [ -upload dest ] -- archives build artifacts
importkeys -- imports signing keys from env
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
nsis -- creates a Windows NSIS installer
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
For all commands, -n prevents execution of external programs (dry run mode).
*/
package main

Expand Down Expand Up @@ -214,7 +213,10 @@ func doInstall(cmdline []string) {

// Configure the build.
env := build.Env()
gobuild := tc.Go("build", buildFlags(env, *staticlink)...)
if *staticlink {
env.StaticLink = true
}
gobuild := tc.Go("build", buildFlags(env)...)

// arm64 CI builders are memory-constrained and can't handle concurrent builds,
// better disable it. This check isn't the best, it should probably
Expand Down Expand Up @@ -247,7 +249,7 @@ func doInstall(cmdline []string) {
}

// buildFlags returns the go tool flags for building.
func buildFlags(env build.Environment, staticlink bool) (flags []string) {
func buildFlags(env build.Environment) (flags []string) {
var ld []string
if env.Commit != "" {
ld = append(ld, "-X", "main.gitCommit="+env.Commit)
Expand All @@ -262,7 +264,7 @@ func buildFlags(env build.Environment, staticlink bool) (flags []string) {
// alpine Linux.
if runtime.GOOS == "linux" {
staticlinkflag := ""
if staticlink {
if env.StaticLink {
staticlinkflag = "-static"
}
ld = append(ld, "-extldflags", fmt.Sprintf("' -Wl,-z,stack-size=0x800000 %s'", staticlinkflag))
Expand Down Expand Up @@ -344,7 +346,7 @@ func doLint(cmdline []string) {

// downloadLinter downloads and unpacks golangci-lint.
func downloadLinter(cachedir string) string {
const version = "1.42.0"
const version = "1.48.0"

csdb := build.MustLoadChecksums("build/checksums.txt")
arch := runtime.GOARCH
Expand Down
11 changes: 9 additions & 2 deletions internal/build/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
BuildnumFlag = flag.String("buildnum", "", `Overrides CI build number`)
PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`)
CronJobFlag = flag.Bool("cron-job", false, `Overrides cron job status of the build`)
StaticLink = flag.Bool("static-link", false, `Overrides static link status of the build`)
)

// Environment contains metadata provided by the build environment.
Expand All @@ -45,11 +46,12 @@ type Environment struct {
Buildnum string
IsPullRequest bool
IsCronJob bool
StaticLink bool
}

func (env Environment) String() string {
return fmt.Sprintf("%s env (commit:%s date:%s branch:%s tag:%s buildnum:%s pr:%t)",
env.Name, env.Commit, env.Date, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest)
return fmt.Sprintf("%s env (commit:%s date:%s branch:%s tag:%s buildnum:%s pr:%t static:%t)",
env.Name, env.Commit, env.Date, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest, env.StaticLink)
}

// Env returns metadata about the current CI environment, falling back to LocalEnv
Expand All @@ -72,6 +74,7 @@ func Env() Environment {
Buildnum: os.Getenv("TRAVIS_BUILD_NUMBER"),
IsPullRequest: os.Getenv("TRAVIS_PULL_REQUEST") != "false",
IsCronJob: os.Getenv("TRAVIS_EVENT_TYPE") == "cron",
StaticLink: false,
}
case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True":
commit := os.Getenv("APPVEYOR_PULL_REQUEST_HEAD_COMMIT")
Expand All @@ -89,6 +92,7 @@ func Env() Environment {
Buildnum: os.Getenv("APPVEYOR_BUILD_NUMBER"),
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
StaticLink: false,
}
default:
return LocalEnv()
Expand Down Expand Up @@ -168,5 +172,8 @@ func applyEnvFlags(env Environment) Environment {
if *CronJobFlag {
env.IsCronJob = true
}
if *StaticLink {
env.StaticLink = true
}
return env
}

0 comments on commit cfbeb69

Please sign in to comment.