Guillaume Barré
Guillaume Barré

Reputation: 4218

Go build, with module, fails under an Alpine image but is fine under Windows

I was running a small test to connect to ETCD. This test imports go.etcd.io/etcd/clientv3 witch, by the magic of go modules, pulls github.com/coreos/go-systemd/journal.

I use go module to manage the dependencies.

First I ran my test under windows with go version go1.13.1 windows/amd64 and everything is fine and works well as expected.

After that because my etcd client project is intended to be deploy via a Docker image, based on alpine, I tried to compile it with the go 1.13 image golang:1.13-alpine

I used :

docker run --rm -v "/${PWD}":/go/src/ -w //go/src/ golang:1.13-alpine go build -o etcd

I have faced a first known issue telling me that git was not installed on golang:1.13-alpine

build github.com/nirekin/etcd: cannot load github.com/coreos/go-systemd/journal: git init --bare in /go/pkg/mod/cache/vcs/1f60ff15ab3093bffd86f4a985673d120db13dabca39c597aaa5016031c601a6: exec: "git": executable file not found in $PATH

Then I have built a new image, with the following docker file, in order to add git in golang:1.13-alpine

Dockerfile:

FROM golang:1.13-alpine

RUN apk --update add git less openssh && \
    rm -rf /var/lib/apt/lists/* && \
    rm /var/cache/apk/*

With my new image I have tried to compile again

docker run --rm -v "/${PWD}":/go/src/ -w //go/src/ my/image go build -o etcd

And I got this error:

build github.com/myuser/etcd: cannot load github.com/coreos/go-systemd/journal: no matching versions for query "latest"

I cannot figure why the same version 1.13 of acts differently under windows and alpine at the moment of resolving dependencies?

Am i doing something wrong or missing something?

File to eventually reproduce this strong text:

Go code:

package main

import (
    "log"
    "time"

    "go.etcd.io/etcd/clientv3"
)

func main() {
    c := clientv3.Config{
        Endpoints:   []string{"http://127.0.0.1:2379"},
        DialTimeout: 5 * time.Second,
    }
    log.Printf("%v", c)
}

go.mod:

module github.com/nirekin/etcd

go 1.13

require (
    github.com/coreos/etcd v3.3.17+incompatible // indirect
    github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
    github.com/gogo/protobuf v1.3.1 // indirect
    github.com/google/uuid v1.1.1 // indirect
    go.etcd.io/etcd v3.3.17+incompatible
    go.uber.org/zap v1.13.0 // indirect
    google.golang.org/grpc v1.25.1 // indirect
)

Upvotes: 3

Views: 3987

Answers (1)

leaf bebop
leaf bebop

Reputation: 8232

The problem is go.etcd.io/etcd depends on github.com/coreos/go-systemd/journal on linux, which is not using go modules correctly. There are two issues (#321 and #325) submitted to the project and the maintainer acknowledge the problem (but not solved it yet).

The solution suggested there is to add the following to go.mod:

replace (
  github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 latest
)

and then run go tidy. (inside container)

Upvotes: 4

Related Questions