diff --git a/environments/go/builder/Dockerfile b/environments/go/builder/Dockerfile index 0b87e99d..178ae671 100644 --- a/environments/go/builder/Dockerfile +++ b/environments/go/builder/Dockerfile @@ -5,9 +5,9 @@ FROM ${BUILDER_IMAGE} FROM golang:${GO_VERSION} -COPY --from=0 /builder /builder - ENV GOPATH /usr +WORKDIR ${GOPATH} +COPY --from=0 /builder /builder ADD build.sh /usr/local/bin/build diff --git a/environments/go/builder/build.sh b/environments/go/builder/build.sh index 3ece7d94..7758a3c8 100755 --- a/environments/go/builder/build.sh +++ b/environments/go/builder/build.sh @@ -1,19 +1,21 @@ #!/bin/sh +set -eux + +srcDir=${GOPATH}/src/$(basename ${SRC_PKG}) + +trap "rm -rf ${srcDir}" EXIT + if [ -d ${SRC_PKG} ] then - echo "Building in directory ${SRC_PKG}" - cd ${SRC_PKG} - go build -buildmode=plugin -i -o ${DEPLOY_PKG} . + echo "Building in directory ${srcDir}" + ln -sf ${SRC_PKG} ${srcDir} elif [ -f ${SRC_PKG} ] then - fn=$(basename ${SRC_PKG}) - d=/tmp/$fn - mkdir $d - trap "rm -rf /tmp/$fn" EXIT - echo "Building file ${SRC_PKG} in $d" - - cd $d - cp ${SRC_PKG} ./function.go - go build -buildmode=plugin -i -o ${DEPLOY_PKG} . + echo "Building file ${SRC_PKG} in ${srcDir}" + mkdir -p ${srcDir} + cp ${SRC_PKG} ${srcDir}/function.go fi + +cd ${srcDir} +go build -buildmode=plugin -i -o ${DEPLOY_PKG} . diff --git a/examples/go/vendor-example/main.go b/examples/go/vendor-example/main.go new file mode 100644 index 00000000..234d7ee9 --- /dev/null +++ b/examples/go/vendor-example/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "go/vendordir/test" + "net/http" +) + +// Handler is the entry point for this fission function +func Handler(w http.ResponseWriter, r *http.Request) { + msg := test.Test() + w.Write([]byte(msg)) +} diff --git a/examples/go/vendor-example/vendor/go/vendordir/test/test.go b/examples/go/vendor-example/vendor/go/vendordir/test/test.go new file mode 100644 index 00000000..d826fe4f --- /dev/null +++ b/examples/go/vendor-example/vendor/go/vendordir/test/test.go @@ -0,0 +1,5 @@ +package test + +func Test() string { + return "vendor hello world" +} diff --git a/test/tests/test_environments/test_go_env.sh b/test/tests/test_environments/test_go_env.sh index 863207a4..a85a3138 100755 --- a/test/tests/test_environments/test_go_env.sh +++ b/test/tests/test_environments/test_go_env.sh @@ -62,7 +62,7 @@ timeout 90 bash -c "wait_for_builder" pkgName=$(fission package create --src hello.go --env go| cut -f2 -d' '| tr -d \') -# wait for build to finish at most 60s +# wait for build to finish at most 90s timeout 90 bash -c "waitBuild $pkgName" log "Creating pool manager & new deployment function for Golang" @@ -74,10 +74,31 @@ fission route create --function hello-go-poolmgr --url /hello-go-poolmgr --metho fission route create --function hello-go-nd --url /hello-go-nd --method GET log "Waiting for router & pools to catch up" -sleep 15 +sleep 5 log "Testing pool manager function" timeout 60 bash -c "test_fn hello-go-poolmgr 'Hello'" log "Testing new deployment function" timeout 60 bash -c "test_fn hello-go-nd 'Hello'" + +# Create zip file without top level directory (vendor-example) +cd vendor-example && zip -r vendor.zip * + +pkgName=$(fission package create --src vendor.zip --env go| cut -f2 -d' '| tr -d \') + +# wait for build to finish at most 90s +timeout 90 bash -c "waitBuild $pkgName" + +log "Update function package" +fission fn update --name hello-go-poolmgr --pkg $pkgName +fission fn update --name hello-go-nd --pkg $pkgName + +log "Waiting for router & pools to catch up" +sleep 5 + +log "Testing pool manager function with new package" +timeout 60 bash -c "test_fn hello-go-poolmgr 'vendor'" + +log "Testing new deployment function with new package" +timeout 60 bash -c "test_fn hello-go-nd 'vendor'"