diff --git a/Dockerfile b/Dockerfile index 9e469220..1863705d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ FROM golang:1.17.5 AS BACK WORKDIR /go/src/casdoor COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct go build -ldflags="-w -s" -o server . \ - && apt update && apt install wait-for-it && chmod +x /usr/bin/wait-for-it +RUN ./build.sh && apt update && apt install wait-for-it && chmod +x /usr/bin/wait-for-it FROM node:16.13.0 AS FRONT WORKDIR /web diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..f960167c --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +#try to connect to google to determine whether user need to use proxy +curl www.google.com -o /dev/null --connect-timeout 5 +if [ $? == 0 ] +then + echo "connect to google.com successed" + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o server . +else + echo "connect to google.com failed" + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct go build -ldflags="-w -s" -o server . +fi \ No newline at end of file