Skip to content

could not import C: failure with confluent-kafka-go in docker alpine #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
fabriziomoscon opened this issue Oct 21, 2020 · 3 comments
Closed
3 tasks done
Labels
area: cgo Related to CGO or line directives bug Something isn't working

Comments

@fabriziomoscon
Copy link

Thank you for maintaining this great tool @bombsimon !

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.31.0
Config file
$ cat .golangci.yml
# options for analysis running
run:
  # default concurrency is a available CPU number
  concurrency: 4

  # timeout for analysis, e.g. 30s, 5m, default is 1m
  deadline: 1m

  skip-files:
    - mock.go

  modules-download-mode: vendor

# all available settings of specific linters
linters-settings:
  errcheck:
    # report about not checking of errors in type assetions: `a := b.(MyStruct)`;
    check-type-assertions: true
    # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
    check-blank: true
  govet:
    # report about shadowed variables
    check-shadowing: true
  gocyclo:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    min-complexity: 15
  lll:
    # max line length, lines longer will be reported. Default is 120.
    # '\t' is counted as 1 character by default, and can be changed with the tab-width option
    line-length: 200
  unused:
    # treat code as a program (not a library) and report unused exported identifiers
    check-exported: false
  unparam:
    # Inspect exported functions, default is false. Set to true if no external program/library imports your code.
    check-exported: true
  nakedret:
    # make an issue if func has more lines of code than this setting and it has naked returns
    max-func-lines: 60
  prealloc:
    # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
    simple: true
    range-loops: true # Report preallocation suggestions on range loops
    for-loops: false # Report preallocation suggestions on for loops

linters:
  disable-all: true
  enable:
    - govet
    - errcheck
    - gocyclo
    - structcheck
    - varcheck
    - ineffassign
    - deadcode
    - golint
    - interfacer
    - unconvert
    - goconst
    - gocyclo
    - staticcheck
    - unused
    - gosimple
    - dupl
    - gofmt
    - gosec
    - lll
    - megacheck
    - gocritic
  fast: false

issues:
  # Independently from option `exclude` we use default exclude patterns,
  # it can be disabled by this option. To list all
  # excluded by default patterns execute `golangci-lint run --help`.
  # Default value for this option is true.
  exclude-use-default: true
  exclude:
    - "File is not `goimports`-ed"
    # TODO fix the following lint checks and remove them from exclude
    - "hugeParam"
    - "paramTypeCombine"
    - "importShadow"
Go environment
$ go version && go env
go 1.14
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build039915949=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
level=warning msg="[runner] Can't run linter goanalysis_metalinter: deadcode: analysis skipped: errors in package: [
    /src/kafka/cfg.go:4:17: could not import github.com/confluentinc/confluent-kafka-go/kafka
    (/src/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:48:8: could not import C (cgo preprocessing failed)) /src/kafka/consumer.go:17:2: 
    \"github.com/davecgh/go-spew/spew\" imported but not used /src/kafka/consumer.go:8:2: 
    \"strconv\" imported but not used /src/kafka/consumer_channel.go:10:2: 
    \"github.com/prometheus/client_golang/prometheus\" imported but not used /src/kafka/consumer_channel.go:6:2: 
    \"github.com/90poe/service-chassis/streaming/logs\" imported but not used
    ]"

level=warning msg="[runner] Can't run linter unused: buildir: failed to load package kafka: could not load export data: no export data for \"github.com/confluentinc/confluent-kafka-go/kafka\""

level=error msg="Running error: buildir: failed to load package kafka: could not load export data: no export data for \"github.com/confluentinc/confluent-kafka-go/kafka\""

I tried the suggestions for this issue #1176 without success.

In docker the lint fails when I run on an alpine (golang:1.14.10-alpine3.12) base image, but succeeds with a Debian base image (golang:1.14.10-buster).

To build the repo under alpine we use go build -tags musl ./..., so I strongly suspect that the error is around must-dev, but I can't work out which file/setting is present in the Debian base image, absent in the Alpine base image.

The repo uses

github.com/confluentinc/confluent-kafka-go v1.4.2

The Dockerfile I use is

##################
### base stage ###
##################
FROM golang:1.14.10-alpine3.12 as base

ARG ALPINE_VERSION=v3.12
ARG LIBRESSL_VERSION=3.1
ARG LIBRDKAFKA_VERSION=1.4.2-r0

ARG GOLANGCI_VERSION=v1.30.0
ARG PROTOC_GEN_GO_VERSION=v1.4.2

# those bad guys are required to build C with Golang. Some of them may be redundant
RUN apk add --no-cache git \
    zstd \
    perl \
    openssl \
    curl \
    upx \
    openssh \
    bash \
    gcc \
    make \
    pkgconfig \
    gcc \
    g++ \
    musl-dev \
    yajl-dev \
    zlib-dev \
    cyrus-sasl-dev \
    lz4-dev \
    openssl-dev \
    libc-dev \
    bsd-compat-headers \
    build-base \
    coreutils \
    docker-compose \
    imagemagick \
    imagemagick-dev \
    ca-certificates \
    libressl${LIBRESSL_VERSION}-libcrypto libressl${LIBRESSL_VERSION}-libssl --update-cache --repository http://nl.alpinelinux.org/alpine/${ALPINE_VERSION}/main \
    librdkafka=${LIBRDKAFKA_VERSION} --update-cache --repository http://nl.alpinelinux.org/alpine/${ALPINE_VERSION}/community \
    librdkafka-dev=${LIBRDKAFKA_VERSION} --update-cache --repository http://nl.alpinelinux.org/alpine/${ALPINE_VERSION}/community

WORKDIR /src

COPY . ./

#######################
### lint-base stage ###
#######################
FROM golangci/golangci-lint:v1.31-alpine AS lint-base

##################
### lint stage ###
##################
FROM base AS lint
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
RUN golangci-lint run --allow-parallel-runners -c .golangci.yml

Makefile

go mod download
go mod vendor
docker build --force-rm --target=lint
@fabriziomoscon fabriziomoscon added the bug Something isn't working label Oct 21, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 21, 2020

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@fabriziomoscon
Copy link
Author

this is fixed by using --build-tags

golangci-lint run --build-tags=musl -c .golangci.yml ./...

@jatinkapoor1313
Copy link

jatinkapoor1313 commented May 22, 2022

this is fixed by using --build-tags

golangci-lint run --build-tags=musl -c .golangci.yml ./...

this is not working - what this command is doing? I am not able to find .golangci.yml
getting err - ERRO Can't read config: can't read viper config: open .golangci.yml: no such file or directory

@ldez ldez added the area: cgo Related to CGO or line directives label May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cgo Related to CGO or line directives bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants