Skip to content

Commit

Permalink
Allow for the onbuild trigger or not
Browse files Browse the repository at this point in the history
Some builds would like to copy the source themselves.
  • Loading branch information
Russ Egan committed Apr 8, 2015
1 parent d10d92e commit 8518733
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Expand Up @@ -14,6 +14,4 @@ COPY build.sh /

ENTRYPOINT ["/build_environment.sh"]

ONBUILD COPY ./ /src

CMD ["/build.sh"]
6 changes: 6 additions & 0 deletions Dockerfile.builder
@@ -0,0 +1,6 @@
FROM safenetlabs/golang:1.4.2
MAINTAINER SafeNet Labs

ONBUILD COPY ./ /src
CMD ["/build.sh"]
6 changes: 3 additions & 3 deletions build.sh
Expand Up @@ -3,13 +3,13 @@
tagName=$1

# Compile statically linked version of package
echo "Building $pkgName"
`CGO_ENABLED=${CGO_ENABLED:-0} go build -a --installsuffix cgo --ldflags="${LDFLAGS:--s}" $pkgName`
echo "Building $PKG_NAME"
`CGO_ENABLED=${CGO_ENABLED:-0} go build -a --installsuffix cgo --ldflags="${LDFLAGS:--s}" $PKG_NAME`

if [ -e "/var/run/docker.sock" ] && [ -e "./Dockerfile" ];
then
# Grab the last segment from the package name
name=${pkgName##*/}
name=${PKG_NAME##*/}

# Default TAG_NAME to package name if not set explicitly
tagName=${tagName:-"$name":latest}
Expand Down
12 changes: 8 additions & 4 deletions build_environment.sh
Expand Up @@ -7,21 +7,21 @@ then
fi

# Grab Go package name
pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)"
PKG_NAME="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)"

if [ -z "$pkgName" ];
if [ -z "$PKG_NAME" ];
then
echo "Error: Must add canonical import path to root package"
exit 992
fi

export pkgName
export PKG_NAME

# Grab just first path listed in GOPATH
goPath="${GOPATH%%:*}"

# Construct Go package path
pkgPath="$goPath/src/$pkgName"
pkgPath="$goPath/src/$PKG_NAME"

# Set-up src directory tree in GOPATH
mkdir -p "$(dirname "$pkgPath")"
Expand All @@ -33,9 +33,13 @@ if [ -e "$pkgPath/Godeps/_workspace" ];
then
# Add local godeps dir to GOPATH
GOPATH=$pkgPath/Godeps/_workspace:$GOPATH
# Add godep bin to path
PATH=$PATH:$pkgPath/Godeps/_workspace/bin
else
# Get all package dependencies
go get -t -d -v ./...
fi

cd $pkgPath

exec "$@"

0 comments on commit 8518733

Please sign in to comment.