3

My golang project depends on librd kafka

When I try to run go vet ./... or go test ./... from my jenkin, I get the following error. I beleive that is due to the fact that I am running ./... but even if I have to ignore the vendor I am not sure what should it be I tried go test $(go list ./... | grep -v /vendor/librdkafka) but it didnt help.

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_member_add':

(.text+0x8e5): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_get':

(.text+0xd1e): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xd46): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mcgrp_rebalance_timer_cb':

(.text+0x13dd): undefined reference to `__strndup'

I would like to know how can I get around that gcc error while test my project

my Dockerfile :

FROM golang:1.14-alpine AS builder

WORKDIR /src
ENV CGO_ENABLED=0
RUN apk add --no-cache git make
RUN go get \
        github.com/AlekSi/gocov-xml \
        github.com/axw/gocov \
        github.com/tebeka/go2xunit \
        github.com/wadey/gocovmerge



COPY go.mod go.sum ./
RUN  go get -d -v ./...
RUN  go mod download

COPY . .

FROM test AS builder
ENV CGO_ENABLED=1
#this config is for lib rd kafka setup
RUN set -ex &&\
    apk add --no-progress --no-cache \
      gcc \
      musl-dev

WORKDIR /src

RUN go install -tags musl ./...

My jenkinsfile snippet

    stage("Test") {
        agent {
            dockerfile {
                label 'docker'
                additionalBuildArgs '--target test'
                args '-v test:/src/test'
                reuseNode true
            }
        }

        steps {
            parallel(
                    'Unit Test': {
                        sh "make ${makeArgs} test/unit-test"
                    },
                    Coverage: {
                        sh "make ${makeArgs} test/coverage"
                    },
                    Vet: {
                        sh "make ${makeArgs} test/vet"
                    }
            )
        }
        post {
            always {
                junit 'test/*xml'
                publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'test', reportFiles: 'coverage.html', reportName: 'Code Coverage Report'])
                sh "make ${makeArgs} clean"
            }
        }
    }
OneCricketeer
  • 126,858
  • 14
  • 92
  • 185
Gayatri
  • 193
  • 1
  • 2
  • 15
  • use -run flag and specify regex pattern to skip the given vendor. look at [this](https://stackoverflow.com/a/31808316/6932198), it may help. – Hossein Aug 25 '20 at 17:45
  • my project has multiple tests and when I am running form the jenkins pipeleine I want to run all the tests within my project and ignore the dependent libradkafka / gcc test. `-run`will help me only it there is a single test I want to run, right.... but I have more than one – Gayatri Aug 25 '20 at 18:41
  • Also for the option ` -run regex` I would have to introduce a unique naming for all my tests so that the regex can pick it up. This is somehting I'd like to avoid. – Gayatri Aug 25 '20 at 18:53
  • Why not write a bash script that goes to the desired directories and calls `go test`? – shmsr Aug 28 '20 at 17:36

1 Answers1

3

I just had to run it -tags musl

go vet -tags musl ./...

Gayatri
  • 193
  • 1
  • 2
  • 15