Skip to content

Commit

Permalink
Add windows as a supported cross-compile platform.
Browse files Browse the repository at this point in the history
Add cross-compiling for supported platforms to our CircleCI builders.

Signed-off-by: Ying Li <ying.li@docker.com>
  • Loading branch information
cyli committed Sep 22, 2016
1 parent 210946e commit 41beaf8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif
CTIMEVAR=-X $(NOTARY_PKG)/version.GitCommit=$(GITCOMMIT) -X $(NOTARY_PKG)/version.NotaryVersion=$(NOTARY_VERSION)
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"
GOOSES = darwin linux
GOOSES = darwin linux windows
NOTARY_BUILDTAGS ?= pkcs11
NOTARYDIR := /go/src/github.com/docker/notary

Expand Down
1 change: 1 addition & 0 deletions buildscripts/circle_parallelism.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ case $CIRCLE_NODE_INDEX in
;;
2) SKIPENVCHECK=1 make TESTDB=mysql testdb
SKIPENVCHECK=1 make TESTDB=mysql integration
SKIPENVCHECK=1 make cross # just trying not to exceed 5 builders
;;
3) SKIPENVCHECK=1 make TESTDB=rethink testdb
SKIPENVCHECK=1 make TESTDB=rethink integration
Expand Down
20 changes: 12 additions & 8 deletions buildscripts/cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@

GOARCH="amd64"

if [[ "${NOTARY_BUILDTAGS}" == *pkcs11* ]]; then
export CGO_ENABLED=1
else
export CGO_ENABLED=0
fi


for os in "$@"; do
export GOOS="${os}"
BUILDTAGS="${NOTARY_BUILDTAGS}"

if [[ "${GOOS}" == "darwin" ]]; then
export CC="o64-clang"
Expand All @@ -24,18 +18,28 @@ for os in "$@"; do
# darwin binaries can't be compiled to be completely static with the -static flag
LDFLAGS="-s"
else
# no building with Cgo. Also no building with pkcs11
if [[ "${GOOS}" == "windows" ]]; then
BUILDTAGS=""
fi
unset CC
unset CXX
LDFLAGS="-extldflags -static"
fi

if [[ "${BUILDTAGS}" == *pkcs11* ]]; then
export CGO_ENABLED=1
else
export CGO_ENABLED=0
fi

mkdir -p "${NOTARYDIR}/cross/${GOOS}/${GOARCH}";

set -x;
go build \
-o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/notary" \
-a \
-tags "${NOTARY_BUILDTAGS}" \
-tags "${BUILDTAGS}" \
-ldflags "-w ${CTIMEVAR} ${LDFLAGS}" \
./cmd/notary;
set +x;
Expand Down
38 changes: 28 additions & 10 deletions buildscripts/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@
import os
from shutil import rmtree
from subprocess import CalledProcessError, PIPE, Popen, call
import sys
from tempfile import mkdtemp, mkstemp
from textwrap import dedent
from time import sleep, time
from uuid import uuid4


def reporoot():
"""
Get the root of the git repo
"""
return os.path.dirname(
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))


DEFAULT_BINARY = os.path.join(reporoot(), "bin", "notary")


# Returns the reponame and server name
def parse_args(args=None):
"""
Expand Down Expand Up @@ -58,9 +64,13 @@ def parse_args(args=None):
parser.add_argument(
'-u', '--username', dest="username", type=str,
help="Username to use to log into the Notary Server (you will be asked for the password")
parser.add_argument(
'-b', '--binary', dest="binary", type=str, default=DEFAULT_BINARY,
help="Absolute path to the notary binary to use")
parsed = parser.parse_args(args)

return parsed.reponame, parsed.server, parsed.username
return parsed.reponame, parsed.server, parsed.username, parsed.binary


def cleanup(*paths):
"""
Expand All @@ -79,15 +89,15 @@ def cleanup(*paths):
except OSError:
pass


class Client(object):
"""
Object that will run the notary client with the proper command lines
"""
def __init__(self, notary_server, username_passwd=()):
def __init__(self, notary_binary, notary_server, username_passwd=()):
self.notary_server = notary_server
self.username_passwd = username_passwd

binary = os.path.join(reporoot(), "bin", "notary")
self.env = os.environ.copy()
self.env.update({
"NOTARY_ROOT_PASSPHRASE": "root_ponies",
Expand All @@ -97,9 +107,9 @@ def __init__(self, notary_server, username_passwd=()):
})

if notary_server is None:
self.client = [binary, "-c", "cmd/notary/config.json"]
self.client = [notary_binary, "-c", "cmd/notary/config.json"]
else:
self.client = [binary, "-s", notary_server]
self.client = [notary_binary, "-s", notary_server]

def run(self, args, trust_dir, stdinput=None, username_passwd=None):
"""
Expand Down Expand Up @@ -140,6 +150,7 @@ def run(self, args, trust_dir, stdinput=None, username_passwd=None):
raise CalledProcessError(retcode, command, output=output)
return output


class Tester(object):
"""
Thing that runs the test
Expand Down Expand Up @@ -307,6 +318,7 @@ def run(self):

cleanup(self.dir)


def wait_for_server(server, timeout_in_seconds):
"""
Attempts to contact the server until it is up
Expand Down Expand Up @@ -334,11 +346,12 @@ def wait_for_server(server, timeout_in_seconds):
raise Exception(
"Could not connect to {0} after {1} seconds.".format(server, timeout_in_seconds))


def run():
"""
Run the client tests
"""
repo_name, server, username = parse_args()
repo_name, server, username, notary_binary = parse_args()
if not repo_name:
repo_name = uuid4().hex
if server is not None:
Expand All @@ -347,9 +360,14 @@ def run():
if server in ("https://notary-server:4443", "https://notaryserver:4443", ""):
server = None

print("building a new client binary")
call(['make', '-C', reporoot(), 'client'])
print('---')
if not os.path.isfile(notary_binary):
if notary_binary == DEFAULT_BINARY:
print("building a new client binary")
call(['make', '-C', reporoot(), 'client'])
print('---')
else:
print("no such notary client file: {}".format(notary_binary))
sys.exit(1)

username_passwd = ()
if username is not None and username.strip():
Expand All @@ -359,7 +377,7 @@ def run():

wait_for_server(server, 120)

Tester(repo_name, Client(server, username_passwd)).run()
Tester(repo_name, Client(notary_binary, server, username_passwd)).run()

try:
with open("/test_output/SUCCESS", 'wb') as successFile:
Expand Down

0 comments on commit 41beaf8

Please sign in to comment.