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

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

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错