我正在尝试将Go 1.14微服务应用程序部署到Google的灵活环境中。我读到,查找GOROOT存在问题,以及它如何无法获得正确的依赖关系。
我想使用灵活的环境,因为我需要进行端口转发。因为我的域名被用来运行实际的应用程序,所以我想要端口8081来运行我的微服务。
我遵循了这个链接中的指示:
https://blog.cubieserver.de/2019/go-modules-with-app-engine-flexible/
我尝试了选项3,这是我的gitlab-ci.yaml配置文件。
# .gitlab-ci.yaml
stages:
- build
- deploy
build_server:
stage: build
image: golang:1.14
script:
- go mod vendor
- go install farmcycle.us/user/farmcycle
artifacts:
paths:
- vendor/
deploy_app_engine:
stage: deploy
image: google/cloud-sdk:270.0.0
script:
- echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
- gcloud --quiet --project $PROJECT_ID app deploy app.yaml
after_script:
- rm /tmp/$CI_PIPELINE_ID.json这是我的app.yaml配置文件
runtime: go
env: flex
network:
forwarded_ports:
- 8081/tcp当我使用Git管道部署它时。构建阶段通过,但部署阶段失败。
Running with gitlab-runner 13.4.1 (e95f89a0)
on docker-auto-scale 72989761
Preparing the "docker+machine" executor
Preparing environment
00:03
Getting source from Git repository
00:04
Downloading artifacts
00:02
Executing "step_script" stage of the job script
00:03
$ echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
$ gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
Activated service account credentials for: [farmcycle-hk1996@appspot.gserviceaccount.com]
$ gcloud --quiet --project $PROJECT_ID app deploy app.yaml
ERROR: (gcloud.app.deploy) Staging command [/usr/lib/google-cloud-sdk/platform/google_appengine/go-app-stager /builds/JLiu1272/farmcycle-backend/app.yaml /builds/JLiu1272/farmcycle-backend /tmp/tmprH6xQd/tmpSIeACq] failed with return code [1].
------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2020/10/10 20:48:27 staging for go1.11
2020/10/10 20:48:27 Staging Flex app: failed analyzing /builds/JLiu1272/farmcycle-backend: cannot find package "farmcycle.us/user/farmcycle/api" in any of:
($GOROOT not set)
/root/go/src/farmcycle.us/user/farmcycle/api (from $GOPATH)
GOPATH: /root/go
--------------------------------------------------------------------------------
Running after_script
00:01
Running after script...
$ rm /tmp/$CI_PIPELINE_ID.json
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1这就是错误。老实说,我不太清楚这个错误是什么,以及如何修复它。
发布于 2020-10-15 17:29:50
令人惊讶的是,即使使用最新的Go运行时,runtime: go1.15、go模块似乎也没有被使用。见高朗码头。
但是,Flex将应用程序构建到容器中,而不考虑runtime,因此,在本例中,最好使用自定义运行时并构建自己的Dockerfile?
runtime: custom
env: flex然后,您就可以使用例如Go 1.15和go模块(而不使用任何您想要的东西)。对于使用模块的简单main.go,例如:
FROM golang:1.15 as build
ARG PROJECT="flex"
WORKDIR /${PROJECT}
COPY go.mod .
RUN go mod download
COPY main.go .
RUN GOOS=linux \
go build -a -installsuffix cgo \
-o /bin/server \
.
FROM gcr.io/distroless/base-debian10
COPY --from=build /bin/server /
USER 999
ENV PORT=8080
EXPOSE ${PORT}
ENTRYPOINT ["/server"]谷歌最近宣布的对构建包的支持应该能够做到这一点,但我还没有试过。
https://stackoverflow.com/questions/64298412
复制相似问题