【问题标题】:local build successful while CircleCI build failing本地构建成功,而 CircleCI 构建失败
【发布时间】:2019-08-18 14:44:51
【问题描述】:

我正在尝试对导入进行一些试验,但现在卡在 CircleCI 中简单导入包失败的站点而它可以在本地成功构建。任何人都可以分享什么是错的或我做错了什么,是不是让代码在 CircleCI 中构建?

回购结构:

    - project
    --- main.go
    --- graphic
    ----- graphics.go

main.go 导入定义:

    package main

    import (
        "bufio"
        "flag"
        "fmt"
        "io/ioutil"
        "log"
        "os"
        "strings"

        graphic "../project/graphic"
    )

graphics.go 导入定义:

    package graphic

    import (
        "fmt"
        "io/ioutil"
        "log"

        "github.com/fogleman/gg"
    )

CircleCI config.yml:

version: 2
jobs:
  build:
    docker:
      - image: circleci/golang:1.9

    working_directory: /go/src/github.com/<my-account>/project
    steps:
      - checkout

      # specify any bash command here prefixed with `run: `
      # - run: go get -v -t -d ./...

      - run: 
          name: run filesystem path configuration
          command: |
            pwd
            pwd -P
            echo $GOROOT
            echo $GOPATH
            export GOBIN=$GOPATH/bin
            echo $GOBIN
            export PATH=$PATH:$GOBIN
            ls -latr $GOROOT
            ls -latr $GOPATH
            ls -latr $GOBIN
            go env
      - run:
          name: run dependecy managament
          command: |
            go get -v -u github.com/golang/dep/cmd/dep
            go get -v -u github.com/fogleman/gg
            go get -v -u github.com/aws/aws-sdk-go/aws
            go get -v -u github.com/aws/aws-sdk-go/aws/session
            go get -v -u github.com/aws/aws-sdk-go/service/cloudwatch
      - run:
          name: run documentation
          command: |
            godoc -v -index -timestamps main
      - run:
          name: run tests
          command: |
            go vet -v ./...
      - run:
          name: run build and deploy
          command: |
            dep init
            mkdir build
            dep ensure
            go build -v -o build/main.exe main.go
      - run:
          name: run qa
          command: go test -v main.go

      - store_artifacts:
          path: ./build

失败的错误信息:

    #!/bin/bash -eo pipefail
    dep init
    mkdir build
    dep ensure
    go build -v -o build/main.exe main.go
      Using ^1.3.0 as constraint for direct dep github.com/fogleman/gg
      Locking in v1.3.0 (0403632) for direct dep github.com/fogleman/gg
      Locking in master (cff245a) for transitive dep golang.org/x/image
      Using ^1.23.3 as constraint for direct dep github.com/aws/aws-sdk-go
      Locking in v1.23.3 (fbdf1bd) for direct dep github.com/aws/aws-sdk-go
      Locking in master (e2365df) for transitive dep github.com/golang/freetype
      Locking in  (c2b33e84) for transitive dep github.com/jmespath/go-jmespath
    graphic/graphics.go:8:2: cannot find package "_/go/src/github.com/<my-account>/project/vendor/github.com/fogleman/gg" in any of:
        /usr/local/go/src/_/go/src/github.com/<my-account>/project/vendor/github.com/fogleman/gg (from $GOROOT)
        /go/src/_/go/src/github.com/<my-account>/project/vendor/github.com/fogleman/gg (from $GOPATH)
    Exited with code 1

【问题讨论】:

  • 您的主文件导入看起来很奇怪。它应该类似于“github.com/username/graphic”吗?
  • 嗯。我认为不,因为它在我正在导入的仓库中使用 .go 文件导入本地目录。你的意思是我不需要导入本地 .go 包文件或做不同的事情?
  • 刚刚看到您使用 DEP。据我记得对于 dep,您必须遵循 Golang 文件夹结构和 GOPATH (github.com/golang/go/wiki/GOPATH) 环境变量集。确保您已将其设置在您在 CircleCI 中运行的 docker 容器中。另外,请确保您不使用绝对路径来导入包。您可以使用 GOPATH 作为 root 导入或使用 go 模块。
  • 嗯。所以。我有来自“go env”的输出:GOBIN="/go/bin" GOPATH="/go" GOROOT="/usr/local/go" 我在 CircleCI config.yml 中使用“working_directory”属性,如下所示:working_directory: /go/src/github.com/&lt;my-account&gt;/project 基于此,这里的工作路径是什么?谢谢。
  • @ArkadyB,有什么想法吗,伙计?

标签: go circleci-2.0 circleci-workflows


【解决方案1】:

我认为如果您使用包管理器(如 DEP 或其他),您的情况会解决。

【讨论】:

  • 感谢 Kavin 提出的解决方案,但如果您检查在 cmets 中链接的聊天,您会发现它没有。问题在于 CircleCI 构建图像/容器的方式。我希望他们能回复我的错误报告/支持请求并解释那里发生了什么......
  • 我明白了,所以这是一个循环 ci 错误。但有时如果我们不使用任何包管理器来管理我们的包,就会发生这种情况。谢谢老兄..
猜你喜欢
  • 1970-01-01
  • 2019-01-27
  • 1970-01-01
  • 2018-03-11
  • 1970-01-01
  • 2019-04-06
  • 1970-01-01
  • 1970-01-01
  • 2019-02-21
相关资源
最近更新 更多