forked from mystiq/dex
Merge pull request #356 from ericchiang/fix_cross_compilation
Fix cross compilation
This commit is contained in:
commit
09069a51a7
7 changed files with 79 additions and 26 deletions
17
build
17
build
|
@ -2,9 +2,18 @@
|
|||
|
||||
source ./env
|
||||
|
||||
go install -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dex-worker
|
||||
go install -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dexctl
|
||||
go install -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dex-overlord
|
||||
CMDS=( "dex-worker" "dexctl" "dex-overlord" "gendoc")
|
||||
FORMAT='{{ range $i, $dep := .Deps }}{{ $dep }} {{ end }}'
|
||||
|
||||
for CMD in ${CMDS[@]}; do
|
||||
TARGET="github.com/coreos/dex/cmd/$CMD"
|
||||
# Install command dependencies. This caches package builds and speeds
|
||||
# up successive builds a lot.
|
||||
go list -f="$FORMAT" $TARGET | xargs go install -ldflags="$LD_FLAGS"
|
||||
|
||||
# Build the actual command.
|
||||
go build -o="bin/$CMD" -ldflags="$LD_FLAGS" $TARGET
|
||||
done
|
||||
|
||||
go build -o bin/example-app github.com/coreos/dex/examples/app
|
||||
go build -o bin/example-cli github.com/coreos/dex/examples/cli
|
||||
go install github.com/coreos/dex/cmd/gendoc
|
||||
|
|
33
db/client.go
33
db/client.go
|
@ -10,8 +10,6 @@ import (
|
|||
|
||||
"github.com/coreos/go-oidc/oidc"
|
||||
"github.com/go-gorp/gorp"
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"github.com/coreos/dex/client"
|
||||
|
@ -217,6 +215,25 @@ func (r *clientIdentityRepo) Authenticate(creds oidc.ClientCredentials) (bool, e
|
|||
return ok, nil
|
||||
}
|
||||
|
||||
var alreadyExistsCheckers []func(err error) bool
|
||||
|
||||
func registerAlreadyExistsChecker(f func(err error) bool) {
|
||||
alreadyExistsCheckers = append(alreadyExistsCheckers, f)
|
||||
}
|
||||
|
||||
// isAlreadyExistsErr detects database error codes for failing a unique constraint.
|
||||
//
|
||||
// Because database drivers are optionally compiled, use registerAlreadyExistsChecker to
|
||||
// register driver specific implementations.
|
||||
func isAlreadyExistsErr(err error) bool {
|
||||
for _, checker := range alreadyExistsCheckers {
|
||||
if checker(err) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *clientIdentityRepo) New(id string, meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
|
||||
secret, err := pcrypto.RandBytes(maxSecretLength)
|
||||
if err != nil {
|
||||
|
@ -229,17 +246,9 @@ func (r *clientIdentityRepo) New(id string, meta oidc.ClientMetadata) (*oidc.Cli
|
|||
}
|
||||
|
||||
if err := r.executor(nil).Insert(cim); err != nil {
|
||||
switch sqlErr := err.(type) {
|
||||
case *pq.Error:
|
||||
if sqlErr.Code == pgErrorCodeUniqueViolation {
|
||||
err = errors.New("client ID already exists")
|
||||
}
|
||||
case *sqlite3.Error:
|
||||
if sqlErr.ExtendedCode == sqlite3.ErrConstraintUnique {
|
||||
err = errors.New("client ID already exists")
|
||||
}
|
||||
if isAlreadyExistsErr(err) {
|
||||
err = errors.New("client ID already exists")
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,6 @@ import (
|
|||
"github.com/go-gorp/gorp"
|
||||
|
||||
"github.com/coreos/dex/repo"
|
||||
|
||||
// Import database drivers
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type table struct {
|
||||
|
|
15
db/conn_postgres.go
Normal file
15
db/conn_postgres.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package db
|
||||
|
||||
// Register the postgres driver.
|
||||
|
||||
import "github.com/lib/pq"
|
||||
|
||||
func init() {
|
||||
registerAlreadyExistsChecker(func(err error) bool {
|
||||
sqlErr, ok := err.(*pq.Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return sqlErr.Code == pgErrorCodeUniqueViolation
|
||||
})
|
||||
}
|
17
db/conn_sqlite3.go
Normal file
17
db/conn_sqlite3.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
// +build cgo
|
||||
|
||||
package db
|
||||
|
||||
// Register the sqlite3 driver.
|
||||
|
||||
import "github.com/mattn/go-sqlite3"
|
||||
|
||||
func init() {
|
||||
registerAlreadyExistsChecker(func(err error) bool {
|
||||
sqlErr, ok := err.(*sqlite3.Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return sqlErr.ExtendedCode == sqlite3.ErrConstraintUnique
|
||||
})
|
||||
}
|
5
env
5
env
|
@ -1,5 +1,4 @@
|
|||
export GOPATH=${PWD}/Godeps/_workspace
|
||||
export GOBIN=${PWD}/bin
|
||||
|
||||
rm -rf $GOPATH/src/github.com/coreos/dex
|
||||
mkdir -p $GOPATH/src/github.com/coreos/
|
||||
|
@ -7,4 +6,6 @@ mkdir -p $GOPATH/src/github.com/coreos/
|
|||
# Only attempt to link dex into godeps if it isn't already there
|
||||
[ -d $GOPATH/src/github.com/coreos/dex ] || ln -s ${PWD} $GOPATH/src/github.com/coreos/dex
|
||||
|
||||
LD_FLAGS="-X main.version=$(./git-version)"
|
||||
export VERSION=$(./git-version)
|
||||
|
||||
LD_FLAGS="-X main.version=${VERSION}"
|
||||
|
|
14
release
14
release
|
@ -1,18 +1,24 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
VERSION=$(./git-version)
|
||||
|
||||
GOARCH=amd64
|
||||
OSS=( "darwin" "linux" )
|
||||
|
||||
|
||||
source ./env
|
||||
|
||||
# cannot cross compile when GOBIN is set.
|
||||
# See:
|
||||
# https://golang.org/issue/9769
|
||||
# https://golang.org/issue/11778
|
||||
unset GOBIN
|
||||
|
||||
for GOOS in ${OSS[@]}; do
|
||||
name=dex-$VERSION-$GOOS-$GOARCH
|
||||
|
||||
rm -fr $name.tar.gz $name/
|
||||
mkdir $name
|
||||
|
||||
GOOS=$GOOS GOARCH=$GOARCH ./build
|
||||
cp bin/dexctl $name/
|
||||
GOOS=$GOOS GOARCH=$GOARCH go build -o $name/dexctl -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dexctl
|
||||
|
||||
tar -czf $name.tar.gz $name/
|
||||
echo "Created ${name}.tar.gz"
|
||||
|
|
Loading…
Reference in a new issue