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}
|
FROM golang:${GO_VERSION}
|
||||||
|
|
||||||
COPY --from=0 /builder /builder
|
|
||||||
|
|
||||||
ENV GOPATH /usr
|
ENV GOPATH /usr
|
||||||
|
WORKDIR ${GOPATH}
|
||||||
|
|
||||||
|
COPY --from=0 /builder /builder
|
||||||
ADD build.sh /usr/local/bin/build
|
ADD build.sh /usr/local/bin/build
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
srcDir=${GOPATH}/src/$(basename ${SRC_PKG})
|
||||||
|
|
||||||
|
trap "rm -rf ${srcDir}" EXIT
|
||||||
|
|
||||||
if [ -d ${SRC_PKG} ]
|
if [ -d ${SRC_PKG} ]
|
||||||
then
|
then
|
||||||
echo "Building in directory ${SRC_PKG}"
|
echo "Building in directory ${srcDir}"
|
||||||
cd ${SRC_PKG}
|
ln -sf ${SRC_PKG} ${srcDir}
|
||||||
go build -buildmode=plugin -i -o ${DEPLOY_PKG} .
|
|
||||||
elif [ -f ${SRC_PKG} ]
|
elif [ -f ${SRC_PKG} ]
|
||||||
then
|
then
|
||||||
fn=$(basename ${SRC_PKG})
|
echo "Building file ${SRC_PKG} in ${srcDir}"
|
||||||
d=/tmp/$fn
|
mkdir -p ${srcDir}
|
||||||
mkdir $d
|
cp ${SRC_PKG} ${srcDir}/function.go
|
||||||
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} .
|
|
||||||
fi
|
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 \')
|
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"
|
timeout 90 bash -c "waitBuild $pkgName"
|
||||||
|
|
||||||
log "Creating pool manager & new deployment function for Golang"
|
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
|
fission route create --function hello-go-nd --url /hello-go-nd --method GET
|
||||||
|
|
||||||
log "Waiting for router & pools to catch up"
|
log "Waiting for router & pools to catch up"
|
||||||
sleep 15
|
sleep 5
|
||||||
|
|
||||||
log "Testing pool manager function"
|
log "Testing pool manager function"
|
||||||
timeout 60 bash -c "test_fn hello-go-poolmgr 'Hello'"
|
timeout 60 bash -c "test_fn hello-go-poolmgr 'Hello'"
|
||||||
|
|
||||||
log "Testing new deployment function"
|
log "Testing new deployment function"
|
||||||
timeout 60 bash -c "test_fn hello-go-nd 'Hello'"
|
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