dongwu4834 2018-12-12 19:46
浏览 123
已采纳

使用lint命令构建docker go应用

I've created the following docker container , all works except on thing which is the make lint

In the project root I've Makefile with the current entry

lint:
    gometalinter --config=gometalinter.json ./...

when I use it locally in my machine (macbook) and if for example file is not formatted go fmt I get error when executing above code.

The problem is that when I create the docker image via docker build command

I got different linting issues which is not related to my project. in the gometalinter.json I've the following entry to bypass the vendor directory

{
  "vendor": true
}

This is the docker content

FROM golang:1.11.1-alpine3.7 

RUN apk add --update --no-cache git make curl bash

ADD https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep

WORKDIR /go/src/my-proj

COPY . ./

COPY Gopkg.toml Gopkg.lock ./

RUN dep ensure 
# From the error it seems that this is related to cgo but even adding the next line doesnt helps, same error occurred 
RUN CGO_ENABLED=0
# this command download gometalinter which is running OK
RUN make download 

RUN make lint

when I run the lint this is what I got which is not related to my project

../../../usr/local/go/src/net/lookup_unix.go:80:24:warning: error return value not checked (undeclared name: cgoLookupHost) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:95:24:warning: error return value not checked (undeclared name: cgoLookupIP) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:107:23:warning: error return value not checked (undeclared name: cgoLookupPort) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:123:24:warning: error return value not checked (undeclared name: cgoLookupCNAME) (errcheck)
../../../usr/local/go/src/net/lookup_unix.go:323:23:warning: error return value not checked (undeclared name: cgoLookupPTR) (errcheck)
  • 写回答

1条回答 默认 最新

  • douyou8266 2018-12-12 23:36
    关注

    You are not correctly setting the environment variable in your Dockerfile.

    RUN CGO_ENABLED=0

    should be

    ENV CGO_ENABLED=0

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!