0

I am trying to deploy my Go 1.14 microservices application on to Google's Flexible environment. I read that there are issues with finding GOROOT, and how it is unable to obtain the correct dependencies.

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.

I followed the instruction from this link:

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

I tried option 3. This is my gitlab-ci.yaml configurations file.

# .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

runtime: go
env: flex

network:
  forwarded_ports:
    - 8081/tcp

When I deployed this using the Git CI pipeline. 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.

cruise_lab
  • 649
  • 8
  • 21
  • I had the same issue a long time ago and this [Stack overflow](https://stackoverflow.com/questions/7970390/what-should-be-the-values-of-gopath-and-goroot) post helped me to set correctly the GOPATH and GOROOT variables correctly. Maybe this post could help you :) – Andie Vanille Oct 12 '20 at 14:07

1 Answers1

0

Surprisingly, even using the latest Go runtime, runtime: go1.15, go modules appear to not be used. See 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?

runtime: custom
env: flex

Then you get to use e.g. Go 1.15 and go modules (without vendoring) and whatever else you'd like. For a simple main.go that uses modules e.g.:

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.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88