简体   繁体   English

Google App Engine Flex 容器部署问题

[英]Google App Engine Flex Container Deployment Issues

I am trying to deploy my Go 1.14 microservices application on to Google's Flexible environment.我正在尝试将我的 Go 1.14 微服务应用程序部署到 Google 的灵活环境中。 I read that there are issues with finding GOROOT, and how it is unable to obtain the correct dependencies.我读到查找 GOROOT 存在问题,以及它如何无法获得正确的依赖项。

I wanted to use the flexible environment because I needed to do port forwarding.我想使用灵活的环境,因为我需要做端口转发。 Since my domain name was used to run the actual application, I wanted port 8081 to run my microservices.由于我的域名用于运行实际应用程序,因此我希望端口 8081 来运行我的微服务。

I followed the instruction from this link:我按照此链接中的说明进行操作:

https://blog.cubieserver.de/2019/go-modules-with-app-engine-flexible/ https://blog.cubieserver.de/2019/go-modules-with-app-engine-flexible/

I tried option 3. This is my gitlab-ci.yaml configurations file.我尝试了选项 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

This my app.yaml configuration file这是我的 app.yaml 配置文件

runtime: go
env: flex

network:
  forwarded_ports:
    - 8081/tcp

When I deployed this using the Git CI pipeline.当我使用 Git CI 管道部署它时。 Build stage passes, but the Deploy stage failed.构建阶段通过,但部署阶段失败。

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

This was the error.这是错误。 Honestly I am not really sure what this error is and how to fix it.老实说,我不太确定这个错误是什么以及如何修复它。

Surprisingly, even using the latest Go runtime, runtime: go1.15 , go modules appear to not be used.令人惊讶的是,即使使用最新的 Go 运行时runtime: go1.15 ,似乎也没有使用 go 模块。 See golang-docker .请参阅golang-docker

However, Flex builds your app into a container regardless of runtime and so, in this case, it may be better to use a custom runtime and build your own Dockerfile?但是,Flex 将您的应用程序构建到容器中而不考虑runtime ,因此,在这种情况下,使用自定义运行时并构建您自己的 Dockerfile 可能更好?

runtime: custom
env: flex

Then you get to use eg Go 1.15 and go modules (without vendoring) and whatever else you'd like.然后你可以使用例如Go 1.15和 go 模块(没有vendoring)以及任何你想要的。 For a simple main.go that uses modules eg:对于使用模块的简单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"]

This ought to be possible with Google's recently announced support for buildpacks but I've not tried it. Google 最近宣布支持 buildpack,这应该是可能的,但我还没有尝试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM