Add go environment vendor directory support (#781)
* Add go environment vendor directory support * Use symbolink instead of copying files to gopath * Add go vendor example package & test
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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} .
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
func Test() string {
|
||||
return "vendor hello world"
|
||||
}
|
||||
@@ -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'"
|
||||
|
||||
Reference in New Issue
Block a user