Enable go module support for go environment (#1152)

This commit is contained in:
Ta-Ching Chen
2019-07-10 14:00:29 +08:00
committed by GitHub
parent 9e7dd5aa27
commit 58722f849a
46 changed files with 130 additions and 6538 deletions
+24
View File
@@ -0,0 +1,24 @@
ARG GO_VERSION=1.12.7
FROM ubuntu:18.04 AS base
WORKDIR /
RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/*
FROM golang:${GO_VERSION} AS builder
ENV GOPATH /usr
ENV APP ${GOPATH}/src/github.com/fission/fission/environments/go
WORKDIR ${APP}
ADD context ${APP}/context
ADD server.go ${APP}
RUN go get
RUN go build -a -o /server server.go
FROM base
COPY --from=builder /server /
ENTRYPOINT ["/server"]
EXPOSE 8888
+14
View File
@@ -0,0 +1,14 @@
ARG BUILDER_IMAGE=fission/builder
ARG GO_VERSION=1.12.7
FROM ${BUILDER_IMAGE}
FROM golang:${GO_VERSION}
ENV GOPATH /usr
ENV GO111MODULE on
WORKDIR ${GOPATH}
COPY --from=0 /builder /builder
ADD build.sh /usr/local/bin/build
+17 -1
View File
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -eux
@@ -6,6 +6,9 @@ srcDir=${GOPATH}/src/$(basename ${SRC_PKG})
trap "rm -rf ${srcDir}" EXIT
# http://ask.xmodulo.com/compare-two-version-numbers.html
version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
if [ -d ${SRC_PKG} ]
then
echo "Building in directory ${srcDir}"
@@ -18,4 +21,17 @@ then
fi
cd ${srcDir}
if [ -f "go.mod" ]; then
if [ ! -z ${GOLANG_VERSION} ] && version_ge ${GOLANG_VERSION} "1.12"; then
go mod download
else
echo "Please update fission/go-builder and fission/go-env image to the latest version to support go module"
exit 1
fi
else
# still need to do this; otherwise, go will complain "cannot find main module".
go mod init
fi
go build -buildmode=plugin -i -o ${DEPLOY_PKG} .