Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Infrastructure for reproducible builds #4262

Merged
merged 73 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
67486bf
Add Linux descriptor for Gitian builds
alessio May 2, 2019
50680c6
Use Ubuntu bionic
alessio May 2, 2019
fe6175c
Rename gitian build descriptor
alessio May 3, 2019
3ccf1f1
Build for multiple Linux archs, remove GOBIN as it prevents cross-com…
alessio May 3, 2019
7e3eb43
Pass commit, remove invalid archs
alessio May 3, 2019
5421ad9
Make gosum
alessio May 3, 2019
6172e34
Make sure gosum is available
alessio May 3, 2019
454e582
We can ignore go.sum hash, it was a temporary hack to mitigate the la…
alessio May 3, 2019
688d429
Clean before build
alessio May 3, 2019
b5428ad
Add gitian-keys directory
alessio May 3, 2019
639a9c9
Kill gosum
alessio May 3, 2019
bd46ee5
Replace $GOBIN with $GOPATH/bin
alessio May 3, 2019
9f28890
Remove unused anchor
alessio May 3, 2019
e245095
Set a different gopath
alessio May 3, 2019
4bce5c2
Build tools, set custom gopath
alessio May 3, 2019
907ee8c
Revert "Build tools, set custom gopath"
alessio May 3, 2019
9703514
Revert "Set a different gopath"
alessio May 3, 2019
06aaba9
Add /tmp/workspace/bin to PATH
alessio May 3, 2019
bda49a7
Customise DESTDIR for tools
alessio May 3, 2019
f48c9a9
Try to fix docker_image build
alessio May 3, 2019
3b14f09
Correct tar file order
alessio May 3, 2019
2cd2a55
Fix output filename
alessio May 3, 2019
056bf47
Add Mac OS X gitian descriptor file
alessio May 3, 2019
8f58060
Fix golang toolchain file
alessio May 3, 2019
42ce122
Fix descriptors name
alessio May 4, 2019
72ad985
Use static reference datetime
alessio May 4, 2019
580d9ac
Make env more reproducible
alessio May 4, 2019
a35aedc
Fix mac osx descriptor name
alessio May 4, 2019
911a86d
Use internal compiler
alessio May 4, 2019
19c5ae3
Build script
alessio May 4, 2019
b6857d5
Fix shebang
alessio May 4, 2019
9cfbe94
Take cosmos-sdk local clone path from the user
alessio May 4, 2019
af03a35
Repr builds for linux amd64
alessio May 5, 2019
9f468de
Update build script
alessio May 5, 2019
48d4deb
Tested with linux 386
alessio May 5, 2019
4a48964
YES!
alessio May 5, 2019
1e62519
OS X reproducible builds
alessio May 5, 2019
8004def
Add helpful comment at the end of the build process re: signing
alessio May 5, 2019
446e3c8
Fix final message
alessio May 5, 2019
3b8bd6c
Fix py3 compat
alessio May 6, 2019
270a0dd
Fix empty l_release_name
alessio May 6, 2019
e19c1bb
Merge branch 'master' into alessio/reproducible-builds
alessio May 6, 2019
21a31f0
Remove gaiareplay from the list of binaries
alessio May 6, 2019
f084d34
Merge branch 'master' into alessio/reproducible-builds
alessio May 6, 2019
60458ec
Add gitian descriptor for Windows builds
alessio May 6, 2019
161e2b0
Add signing feature
alessio May 7, 2019
079c327
Pass maj-min release pair via command line
alessio May 7, 2019
72293a4
Read SIGN_COMMAND from the environment
alessio May 7, 2019
4312736
Release is inferred from git describe
alessio May 7, 2019
5dc96f5
Rename osx to darwin to match Go arch name
alessio May 7, 2019
7999a5f
Implement verification
alessio May 7, 2019
a76582b
Merge branch 'master' into alessio/reproducible-builds
alessio May 7, 2019
0b91a19
Cleanup, improve robustness
alessio May 8, 2019
47eeec0
Habemus CGO support on Linux
alessio May 9, 2019
4b11351
Make darwin reproducible
alessio May 9, 2019
49a9b80
Pass tags as a command-separated list to the version command to overc…
alessio May 9, 2019
4c73704
Make windows builds reproducible with CGO
alessio May 9, 2019
3269581
Update tarball's name
alessio May 9, 2019
1e40f28
Cache Go src tarball, add distclean to Makefile
alessio May 9, 2019
34b6903
Test circleci
alessio May 9, 2019
aee3aab
Install ruby
alessio May 9, 2019
c60eb1b
Disable ci jobs for testing purpose
alessio May 9, 2019
3a70f4f
Revert "Disable ci jobs for testing purpose"
alessio May 9, 2019
526d1b0
Revert
alessio May 9, 2019
7764bde
Add extra envvars for testing with gitian forks
alessio May 9, 2019
c467324
Remove GOBIN from installation notes
alessio May 9, 2019
9481e01
Add pending entries
alessio May 9, 2019
9e190c8
Add docs
alessio May 9, 2019
3d1539c
Merge branch 'master' into alessio/reproducible-builds
alessio May 9, 2019
c7e21c8
Build with go 1.12.5
alessio May 10, 2019
3b0216a
Fix windows binary extension
alessio May 10, 2019
6d4aa09
Set git describe --abbrev flag to 9
alessio May 11, 2019
9210caf
Merge branch 'master' into alessio/reproducible-builds
alessio May 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 4 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defaults: &linux_defaults
working_directory: /go/src/github.com/cosmos/cosmos-sdk
docker:
- image: circleci/golang:1.12.4
environment:
GOBIN: /tmp/workspace/bin


############
Expand All @@ -25,8 +23,7 @@ set_macos_env: &macos_env
command: |
echo 'export PATH=$PATH:$HOME/go/bin' >> $BASH_ENV
echo 'export GOPATH=$HOME/project' >> $BASH_ENV
echo 'export GOBIN=$GOPATH/bin' >> $BASH_ENV
echo 'export PATH=$PATH:$HOME/go/bin:$GOBIN' >> $BASH_ENV
echo 'export PATH=$PATH:$HOME/go/bin:$GOPATH/bin' >> $BASH_ENV
echo 'export GO111MODULE=on'

############
Expand All @@ -40,12 +37,6 @@ docs_update: &docs_deploy
environment:
AWS_REGION: us-east-1

deps: &dependencies
run:
name: dependencies
command: |
export PATH="$GOBIN:$PATH"

jobs:
setup_dependencies:
<<: *linux_defaults
Expand All @@ -59,13 +50,11 @@ jobs:
- run:
name: tools
command: |
export PATH="$GOBIN:$PATH"
make tools
- *dependencies
make tools TOOLS_DESTDIR=/tmp/workspace/bin
- run:
name: binaries
command: |
export PATH="$GOBIN:$PATH"
export PATH=/tmp/workspace/bin:$PATH
make go-mod-cache
make install
- save_cache:
Expand All @@ -85,14 +74,13 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Lint source
command: |
export PATH="$GOBIN:$PATH"
export PATH=/tmp/workspace/bin:$PATH
make ci-lint

integration_tests:
Expand All @@ -102,14 +90,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test cli
command: |
export PATH="$GOBIN:$PATH"
make test_cli

test_sim_gaia_nondeterminism:
Expand All @@ -119,14 +105,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test individual module simulations
command: |
export PATH="$GOBIN:$PATH"
make test_sim_gaia_nondeterminism

test_sim_gaia_fast:
Expand All @@ -136,14 +120,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test full Gaia simulation
command: |
export PATH="$GOBIN:$PATH"
make test_sim_gaia_fast

test_sim_gaia_import_export:
Expand All @@ -153,14 +135,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test Gaia import/export simulation
command: |
export PATH="$GOBIN:$PATH"
make test_sim_gaia_import_export

test_sim_gaia_simulation_after_import:
Expand All @@ -170,14 +150,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test Gaia import/export simulation
command: |
export PATH="$GOBIN:$PATH"
make test_sim_gaia_simulation_after_import

test_sim_gaia_multi_seed_long:
Expand All @@ -187,14 +165,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test multi-seed Gaia simulation long
command: |
export PATH="$GOBIN:$PATH"
export GO111MODULE=on
make runsim
runsim 500 50 TestFullGaiaSimulation
Expand All @@ -206,14 +182,12 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Test multi-seed Gaia simulation short
command: |
export PATH="$GOBIN:$PATH"
export GO111MODULE=on
make runsim
runsim 50 10 TestFullGaiaSimulation
Expand All @@ -225,15 +199,13 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- run: mkdir -p /tmp/logs
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Run tests
command: |
export PATH="$GOBIN:$PATH"
export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')"
export GO111MODULE=on
for pkg in $(go list ./... | grep -v github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test | grep -v '/simulation' | circleci tests split --split-by=timings); do
Expand All @@ -254,7 +226,6 @@ jobs:
- attach_workspace:
at: /tmp/workspace
- checkout
- *dependencies
- run:
name: gather
command: |
Expand Down Expand Up @@ -283,7 +254,6 @@ jobs:
machine:
image: circleci/classic:latest
environment:
GOBIN: /home/circleci/.go_workspace/bin
GOPATH: /home/circleci/.go_workspace/
GOOS: linux
GOARCH: amd64
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
FROM golang:alpine AS build-env

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python

# Set working directory for the build
WORKDIR /go/src/github.com/cosmos/cosmos-sdk
Expand Down
19 changes: 7 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
GOBIN ?= $(GOPATH)/bin
GOSUM := $(shell which gosum)
BINDIR ?= $(GOPATH)/bin

export GO111MODULE = on

Expand Down Expand Up @@ -49,10 +48,6 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=gaia \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)"

ifneq ($(GOSUM),)
ldflags += -X github.com/cosmos/cosmos-sdk/version.GoSumHash=$(shell $(GOSUM) go.sum)
endif

ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
Expand Down Expand Up @@ -166,20 +161,20 @@ test_sim_gaia_fast:

test_sim_gaia_import_export: runsim
@echo "Running Gaia import/export simulation. This may take several minutes..."
$(GOBIN)/runsim 50 5 TestGaiaImportExport
$(BINDIR)/runsim 50 5 TestGaiaImportExport

test_sim_gaia_simulation_after_import: runsim
@echo "Running Gaia simulation-after-import. This may take several minutes..."
$(GOBIN)/runsim 50 5 TestGaiaSimulationAfterImport
$(BINDIR)/runsim 50 5 TestGaiaSimulationAfterImport

test_sim_gaia_custom_genesis_multi_seed: runsim
@echo "Running multi-seed custom genesis simulation..."
@echo "By default, ${HOME}/.gaiad/config/genesis.json will be used."
$(GOBIN)/runsim -g ${HOME}/.gaiad/config/genesis.json 400 5 TestFullGaiaSimulation
$(BINDIR)/runsim -g ${HOME}/.gaiad/config/genesis.json 400 5 TestFullGaiaSimulation

test_sim_gaia_multi_seed: runsim
@echo "Running multi-seed Gaia simulation. This may take awhile!"
$(GOBIN)/runsim 400 5 TestFullGaiaSimulation
$(BINDIR)/runsim 400 5 TestFullGaiaSimulation

test_sim_benchmark_invariants:
@echo "Running simulation invariant benchmarks..."
Expand All @@ -188,8 +183,8 @@ test_sim_benchmark_invariants:
-SimulationCommit=true -SimulationSeed=57 -v -timeout 24h

# Don't move it into tools - this will be gone once gaia has moved into the new repo
runsim: $(GOBIN)/runsim
$(GOBIN)/runsim: cmd/gaia/contrib/runsim/main.go
runsim: $(BINDIR)/runsim
$(BINDIR)/runsim: cmd/gaia/contrib/runsim/main.go
go install github.com/cosmos/cosmos-sdk/cmd/gaia/contrib/runsim

SIM_NUM_BLOCKS ?= 500
Expand Down
5 changes: 0 additions & 5 deletions cmd/gaia/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
GOBIN ?= $(GOPATH)/bin
GOSUM := $(shell which gosum)
alessio marked this conversation as resolved.
Show resolved Hide resolved

export GO111MODULE = on

Expand Down Expand Up @@ -48,10 +47,6 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=gaia \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)"

ifneq ($(GOSUM),)
ldflags += -X github.com/cosmos/cosmos-sdk/version.GoSumHash=$(shell $(GOSUM) ../../go.sum)
endif

ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
Expand Down
105 changes: 105 additions & 0 deletions cmd/gaia/contrib/gitian-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

set -euo pipefail

g_default_dirname="gitian-build-$(date +%Y-%m-%d-%H%M%S)"
g_dirname=''

f_main() {
local l_dirname \
l_workdir \
l_sdk \
l_commit \
l_platform \
l_result \
l_descriptor \
l_release_name

l_dirname=$1
l_platform=$2
l_sdk=$3
pushd ${l_sdk}
l_commit=$(git rev-parse HEAD)
popd

l_descriptor=$l_sdk/cmd/gaia/contrib/gitian-descriptors/gitian-${l_platform}.yml
[ -f ${l_descriptor} ]

l_workdir="$(pwd)/${l_dirname}"
mkdir ${l_workdir}/
echo "Download gitian" >&2
git clone https://github.com/devrandom/gitian-builder ${l_workdir}

echo "Prepare gitian-target docker image" >&2
f_prep_docker_image "${l_workdir}"

echo "Download Go" >&2
f_download_go "${l_workdir}"

echo "Start the build" >&2
f_build "${l_workdir}" "${l_sdk}" "${l_commit}" "${l_platform}"
echo "You may find the result in $(echo ${l_workdir}/result/*.yml))" >&2

l_release_name="$(sed -n 's/^name: \"\(.\+\)\"$/\1/p' ${l_descriptor})"
[ -n ${l_release_name} ]
echo "You can now sign the build with the following command:" >&2
echo "cd ${l_workdir} ; bin/gsign -p 'gpg --detach-sign --armor' -s GPG_IDENTITY --release=${l_release_name} ${l_descriptor}" >&2
alessio marked this conversation as resolved.
Show resolved Hide resolved
return 0
}

f_prep_docker_image() {
local l_dir=$1

pushd ${l_dir}
bin/make-base-vm --docker --suite bionic --arch amd64
popd
}

f_download_go() {
local l_dir l_gopkg

l_dir=$1

mkdir -p ${l_dir}/inputs
l_gopkg=go1.12.4.linux-amd64.tar.gz
curl -L https://dl.google.com/go/${l_gopkg} > ${l_dir}/inputs/${l_gopkg}
}

f_build() {
local l_gitian l_sdk l_platform l_descriptor

l_gitian=$1
l_sdk=$2
l_commit=$3
l_platform=$4
l_descriptor=$l_sdk/cmd/gaia/contrib/gitian-descriptors/gitian-${l_platform}.yml

[ -f ${l_descriptor} ]

cd ${l_gitian}
export USE_DOCKER=1
bin/gbuild $l_descriptor --commit cosmos-sdk=$l_commit
libexec/stop-target || echo "warning: couldn't stop target" >&2
}

f_help() {
cat >&2 <<EOF
Usage: $(basename $0) [-h] GOOS GIT_REPO
Launch a gitian build from the local clone of cosmos-sdk available at GIT_REPO.

Options:
-h Display this help and exit
-d DIRNAME Set working directory name
EOF
}

while getopts ":d:h" opt; do
case "${opt}" in
h) f_help ; exit 0 ;;
d) g_dirname="${OPTARG}"
esac
done

shift "$((OPTIND-1))"

f_main "${g_dirname:-${g_default_dirname}}" $1 $2
Loading