Amano123/test-web-application

dockerでのGoの開発環境について

Opened this issue · 2 comments

現在(2022/04/14)、git clone したあとdocekr-compose buildを行うとエラーが吐かれる。
少し長いけど、エラー情報を載せておく。

┌────── sample [ main]on 403ms
└─▶  docker-compose build
[+] Building 9.7s (24/25)
 => [sample_go-echo internal] load build definition from Dockerfile                                                       0.0s
 => => transferring dockerfile: 288B                                                                                      0.0s
 => [sample_elasticsearch internal] load build definition from dockerfile                                                 0.0s
 => => transferring dockerfile: 1.64kB                                                                                    0.0s
 => [sample_react internal] load build definition from dockerfile                                                         0.0s
 => => transferring dockerfile: 129B                                                                                      0.0s
 => [sample_nginx internal] load build definition from dockerfile                                                         0.0s
 => => transferring dockerfile: 61B                                                                                       0.0s
 => [sample_go-echo internal] load .dockerignore                                                                          0.0s
 => => transferring context: 2B                                                                                           0.0s
 => [sample_elasticsearch internal] load .dockerignore                                                                    0.0s
 => => transferring context: 2B                                                                                           0.0s
 => [sample_react internal] load .dockerignore                                                                            0.0s
 => => transferring context: 2B                                                                                           0.0s
 => [sample_nginx internal] load .dockerignore                                                                            0.0s
 => => transferring context: 2B                                                                                           0.0s
 => [sample_go-echo internal] load metadata for docker.io/library/golang:latest                                           0.9s
 => [sample_elasticsearch internal] load metadata for docker.elastic.co/elasticsearch/elasticsearch:7.8.0                 0.9s
 => [sample_react internal] load metadata for docker.io/library/node:10.23.2-alpine3.11                                   1.0s
 => [sample_nginx internal] load metadata for docker.io/library/nginx:1.20.0-alpine                                       1.0s
 => [sample_go-echo internal] load build context                                                                          0.0s
 => => transferring context: 3.92kB                                                                                       0.0s
 => [sample_go-echo 1/5] FROM docker.io/library/golang:latest@sha256:3f0168c019343d7cc07bf2481e7b6555fbf2ebadfb01f9e7787  0.0s
 => CACHED [sample_go-echo 2/5] WORKDIR /app                                                                              0.0s
 => CACHED [sample_go-echo 3/5] COPY ./app /app                                                                           0.0s
 => ERROR [sample_go-echo 4/5] RUN go mod init main   && go mod tidy   && go build                                        8.4s
 => CACHED [sample_elasticsearch 1/1] FROM docker.elastic.co/elasticsearch/elasticsearch:7.8.0@sha256:161bc8c7054c622b05  0.0s
 => [sample_nginx] exporting to image                                                                                     0.0s
 => => exporting layers                                                                                                   0.0s
 => => writing image sha256:cc9bd9c3b31264f7995d75cbce2488707bbec4db83577675f4f78289e8289e37                              0.0s
 => => naming to docker.io/library/sample_elasticsearch                                                                   0.0s
 => => writing image sha256:99c8005c172708c7d140bec8e19df61b20998542720e86c52a3b7f41a96642f4                              0.0s
 => => naming to docker.io/library/sample_react                                                                           0.0s
 => => writing image sha256:5ba3a011f8bcece25f904d6090d82a770397ddade38545c16cdfe6a4596534c8                              0.0s
 => => naming to docker.io/library/sample_nginx                                                                           0.0s
 => [sample_react 1/4] FROM docker.io/library/node:10.23.2-alpine3.11@sha256:7351c71024245bd1133674ce2a0869c80926712a9e0  0.0s
 => CACHED [sample_react 2/4] WORKDIR /usr/src/app                                                                        0.0s
 => CACHED [sample_react 3/4] RUN npm install d3                                                                          0.0s
 => CACHED [sample_react 4/4] RUN npm install axios                                                                       0.0s
 => CACHED [sample_nginx 1/1] FROM docker.io/library/nginx:1.20.0-alpine@sha256:e015192ec74937149dce3aa1feb8af016b7cce3a  0.0s
------
 > [sample_go-echo 4/5] RUN go mod init main   && go mod tidy   && go build:
#17 0.431 go: creating new go.mod: module main
#17 0.434 go: to add module requirements and sums:
#17 0.434       go mod tidy
#17 0.498 go: finding module for package github.com/labstack/echo/v4/middleware
#17 0.498 go: finding module for package github.com/elastic/go-elasticsearch/v7/esapi
#17 0.498 go: finding module for package github.com/elastic/go-elasticsearch/v7
#17 0.498 go: finding module for package github.com/labstack/echo/v4
#17 1.452 go: downloading github.com/elastic/go-elasticsearch v0.0.0
#17 1.462 go: downloading github.com/elastic/go-elasticsearch/v7 v7.17.1
#17 1.581 go: downloading github.com/labstack/echo v3.3.10+incompatible
#17 1.806 go: downloading github.com/labstack/echo/v4 v4.7.2
#17 1.947 go: found github.com/elastic/go-elasticsearch/v7 in github.com/elastic/go-elasticsearch/v7 v7.17.1
#17 1.947 go: found github.com/elastic/go-elasticsearch/v7/esapi in github.com/elastic/go-elasticsearch/v7 v7.17.1
#17 1.947 go: found github.com/labstack/echo/v4 in github.com/labstack/echo/v4 v4.7.2
#17 1.947 go: found github.com/labstack/echo/v4/middleware in github.com/labstack/echo/v4 v4.7.2
#17 1.970 go: downloading github.com/labstack/gommon v0.3.1
#17 1.971 go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
#17 1.975 go: downloading golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
#17 1.980 go: downloading github.com/stretchr/testify v1.7.0
#17 2.042 go: downloading github.com/golang-jwt/jwt v3.2.2+incompatible
#17 2.223 go: downloading github.com/valyala/fasttemplate v1.2.1
#17 2.223 go: downloading golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
#17 2.325 go: downloading github.com/mattn/go-colorable v0.1.11
#17 2.325 go: downloading github.com/mattn/go-isatty v0.0.14
#17 2.349 go: downloading github.com/davecgh/go-spew v1.1.1
#17 2.349 go: downloading github.com/pmezard/go-difflib v1.0.0
#17 2.354 go: downloading gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
#17 2.384 go: downloading github.com/valyala/bytebufferpool v1.0.0
#17 2.408 go: downloading golang.org/x/sys v0.0.0-20211103235746-7861aae1554b
#17 2.465 go: downloading golang.org/x/text v0.3.7
#17 8.183 # main
#17 8.183 ./main.go:69:3: undefined: res
#17 8.183 ./main.go:69:8: undefined: err
#17 8.183 ./main.go:69:47: undefined: es
#17 8.183 ./main.go:70:6: undefined: err
#17 8.183 ./main.go:71:46: undefined: err
#17 8.183 ./main.go:73:9: undefined: res
#17 8.183 ./main.go:75:6: undefined: res
#17 8.183 ./main.go:76:54: undefined: res
#17 8.183 ./main.go:81:31: undefined: res
#17 8.183 ./main.go:85:41: undefined: res
#17 8.183 ./main.go:85:41: too many errors
------
failed to solve: executor failed running [/bin/sh -c go mod init main   && go mod tidy   && go build]: exit code: 2

@Amano123 の知識不足でうまくgoの環境を構築できてないね、、、
少し修正を行う

#8 のissueと同じ様な課題
go のmain.go、go.modなどのファイル管理をどうするべきか