2022.10.10  

【Docker】newrelic-fluent-bit-output(1.14.0)がビルドできない

NewRelic,  Docker    

newrelic-fluent-bit-outputのソースv1.14.0をダウンロードして、docker image buildした際、エラーとなってしまったため解決方法をメモ書きします。newrelic-fluent-bit-outputリポジトリ

結論

ソースコードのDokcerfileを下記のように修正したところ上手くビルドできました。

# Dokcerfile
### 中略 ###
ENV SOURCE docker
RUN go get github.com/fluent/fluent-bit-go/output
RUN apt update && apt install ca-certificates libgnutls30 -y  # 追加
ENV GO111MODULE on                  # 追加 
RUN go get github.com/sirupsen/logrus
###  後略 ###

ビルドコマンドの実行

# docker image build -t <イメージ名> <Dockerfileのあるディレクトリ>

$ docker image build -t logging-firelens-fluentbit .
[+] Building 57.5s (21/21) FINISHED 

エラー内容とその解決

newrelic-fluent-bit-output v1.14.0をダウンロードしてそのままビルドすると下記のようなエラーがでる。

ビルドコマンドの実行

# docker image build -t <イメージ名> <Dockerfileのあるディレクトリ>

$ docker image build -t logging-firelens-fluentbit .
 => ERROR [builder  9/11] RUN go get github.com/sirupsen/logrus                                                                     7.3s 
------                                                                                                                                   
 > [builder  9/11] RUN go get github.com/sirupsen/logrus:                                                                                
#15 0.277 go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;                                                           
#15 0.277   ignoring go.mod;
#15 0.277   see 'go help modules'
#15 7.223 # golang.org/x/sys/unix
#15 7.223 /go/src/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
#15 7.223 /go/src/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
#15 7.223 /go/src/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
#15 7.223 /go/src/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
------
executor failed running [/bin/sh -c go get github.com/sirupsen/logrus]: exit code: 2

GO111MODULEの設定に問題があるようです。

GO111MODULEとは、Go 1.11から設定出来るようになった環境変数のことで、on/off/autoの3種類の値を設定することができます。 これを設定することでModuleを使うのか、今まで通り$GOPATHを用いて依存関係を管理するのか設定することができます。参考サイト

こちらのサイトを参考に解決しました。

修正内容としてはDokcerfileにENV GO111MODULE onを追加します。

# Dokcerfile
### 中略 ###
ENV SOURCE docker
RUN go get github.com/fluent/fluent-bit-go/output
ENV GO111MODULE on                  # 追加 
RUN go get github.com/sirupsen/logrus
###  後略 ###

そしてビルドコマンドを再実行します。すると別のエラーが発生します。
https://gopkg.in/tomb.v1/にアクセスできず失敗しています。

# docker image build -t <イメージ名> <Dockerfileのあるディレクトリ>

$ docker image build -t logging-firelens-fluentbit .
 => ERROR [builder  9/11] RUN go get github.com/sirupsen/logrus                                                                    11.1s
------                                                                                                                                   
 > [builder  9/11] RUN go get github.com/sirupsen/logrus:                                                                                
#15 0.283 go: finding github.com/onsi/ginkgo v1.8.0                                                                                      
#15 0.284 go: finding github.com/onsi/gomega v1.5.0                                                                                      
#15 0.285 go: finding github.com/fluent/fluent-bit-go v0.0.0-20200729034236-b9c0d6a20853                                                 
#15 0.286 go: finding github.com/sirupsen/logrus v1.8.1                                                                                  
#15 1.363 go: finding github.com/ugorji/go/codec v1.1.7
#15 1.483 go: finding github.com/onsi/ginkgo v1.6.0
#15 1.497 go: finding github.com/fsnotify/fsnotify v1.4.7
#15 1.594 go: finding github.com/pmezard/go-difflib v1.0.0
#15 1.824 go: finding golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
#15 1.826 go: finding golang.org/x/text v0.3.0
#15 1.828 go: finding golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
#15 2.452 go: finding github.com/stretchr/testify v1.2.2
#15 2.544 go: finding gopkg.in/yaml.v2 v2.2.1
#15 2.552 go: finding gopkg.in/fsnotify.v1 v1.4.7
#15 2.702 go: finding github.com/hpcloud/tail v1.0.0
#15 2.868 go: finding gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
#15 2.873 go: finding github.com/ugorji/go v1.1.7
#15 2.879 go: finding golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e
#15 2.891 go: finding github.com/golang/protobuf v1.2.0
#15 3.269 go: finding github.com/davecgh/go-spew v1.1.1
#15 3.273 go: gopkg.in/yaml.v2@v2.2.1: unknown revision v2.2.1
#15 3.274 go: finding golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
#15 3.279 go: gopkg.in/fsnotify.v1@v1.4.7: unknown revision v1.4.7
#15 5.994 go: gopkg.in/tomb.v1@v1.0.0-20141024135613-dd632973f1e7: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/95acae1f863cd3698780e83ddc42f6ad6cd0ab1cb79143808a7de7300ae4df93: exit status 128:
#15 5.994   fatal: unable to access 'https://gopkg.in/tomb.v1/': server certificate verification failed. CAfile: none CRLfile: none
#15 11.08 go: error loading module requirements
------
executor failed running [/bin/sh -c go get github.com/sirupsen/logrus]: exit code: 1

こちらを参考にDockerfileを修正します。

# Dokcerfile
### 中略 ###
ENV SOURCE docker
RUN go get github.com/fluent/fluent-bit-go/output
RUN apt update && apt install ca-certificates libgnutls30 -y  # 今回追加
ENV GO111MODULE on                  # 先程追加 
RUN go get github.com/sirupsen/logrus
###  後略 ###

するとビルドコマンドが成功します。

# docker image build -t <イメージ名> <Dockerfileのあるディレクトリ>

$ docker image build -t logging-firelens-fluentbit .
[+] Building 57.5s (21/21) FINISHED 
コメント
現在コメントはありません。
コメントする
コメント入力

名前 (※ 必須)

メールアドレス (※ 必須 画面には表示されません)

送信