Friday, December 13, 2024
HomeGolangWhen deploy to server challenge with "no required module offers package deal"...

When deploy to server challenge with “no required module offers package deal” – Getting Assist


I acquired challenge when i construct docker in my server however i don’t know why i haven’t localy, right here is the stack hint:
“[6/6] RUN go construct -o /principal:
0.505 handlers/handlers.go:5:2: no required module offers package deal githubcom/rousseau-romain/round-timing/shared/parts; so as to add it:
0.505 go get githubcom/rousseau-romain/round-timing/shared/parts
0.505 handlers/auth.go:9:2: no required module offers package deal githubcom/rousseau-romain/round-timing/views/web page; so as to add it:
0.505 go get githubcom/rousseau-romain/round-timing/views/web page

Dockerfile:11
9 | COPY . .
10 |
11 | >>> RUN go construct -o /principal
12 |
13 | EXPOSE 2468

ERROR: failed to resolve: course of “/bin/sh -c go construct -o /principal” didn’t full efficiently: exit code: 1″

My repository is public i don’t assume it’s proper challenge, however possibly i’m incorrect.

https://github.com/rousseau-romain/round-timing

I needed to change “github.com/” to “githubcom/” with the hyperlink limitation.

Hope any person know tips on how to assist me

The go mod file appears to be like good and up to date.
I attempted so as to add go mod vendor in my dockerfile earlier than my go mod obtain however i acquired challenge to seek out exterior library.
“[7/7] RUN go construct -o /principal
#11 0.378 principal.go:11:2: can’t discover module offering package deal github.com/gorilla/mux: import lookup disabled by -mod=vendor
#11 0.378 (Go model in go.mod is at the very least 1.14 and vendor listing exists.)
#11 0.378 config/config.go:8:2: can’t discover module offering package deal github.com/joho/godotenv: import lookup disabled by -mod=vendor”

With a purpose to copy the exterior library offline into the container i must have my vendor listing inside my container, localy when i construct my container localy i acquired my listing with exterior library.

The package deal github.com/rousseau-romain/ is a part of my native venture, it’s additionally thought-about as exterior library ?

Please present the venture listing construction, together with the dockerfile if doable.

There’s the github hyperlink https://github.com/rousseau-romain/round-timing

The construction is like this:

├── config
├── database
│   └── migration
├── handlers
├── helper
├── mannequin
├── public
│   ├── img
│   │   ├── class
│   │   └── spell
│   │       └── photographs
│   └── script
├── service
│   └── auth
├── shared
│   └── parts
├── tmp
├── vendor
│   ├── github.com
│   │   ├── a-h
│   │   │   └── templ
│   │   │       └── safehtml
│   │   ├── go-sql-driver
│   │   │   └── mysql
│   │   ├── golang
│   │   │   └── protobuf
│   │   │       └── proto
│   │   ├── gorilla
│   │   │   ├── mux
│   │   │   ├── securecookie
│   │   │   └── classes
│   │   ├── huandu
│   │   │   ├── go-sqlbuilder
│   │   │   └── xstrings
│   │   ├── joho
│   │   │   └── godotenv
│   │   └── markbates
│   │       └── goth
│   │           ├── gothic
│   │           └── suppliers
│   │               ├── discord
│   │               └── github
│   ├── golang.org
│   │   └── x
│   │       └── oauth2
│   │           └── inside
│   └── google.golang.org
│       ├── appengine
│       │   ├── inside
│       │   │   ├── base
│       │   │   ├── datastore
│       │   │   ├── log
│       │   │   ├── remote_api
│       │   │   └── urlfetch
│       │   └── urlfetch
│       └── protobuf
│           ├── encoding
│           │   ├── prototext
│           │   └── protowire
│           ├── inside
│           │   ├── descfmt
│           │   ├── descopts
│           │   ├── detrand
│           │   ├── encoding
│           │   │   ├── defval
│           │   │   ├── messageset
│           │   │   ├── tag
│           │   │   └── textual content
│           │   ├── errors
│           │   ├── filedesc
│           │   ├── filetype
│           │   ├── flags
│           │   ├── genid
│           │   ├── impl
│           │   ├── order
│           │   ├── pragma
│           │   ├── set
│           │   ├── strs
│           │   └── model
│           ├── proto
│           ├── mirror
│           │   ├── protodesc
│           │   ├── protoreflect
│           │   └── protoregistry
│           ├── runtime
│           │   ├── protoiface
│           │   └── protoimpl
│           └── varieties
│               └── descriptorpb
└── views
    └── web page

The dockerfile is:

FROM golang:1.22-alpine

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod obtain

COPY . .

RUN go construct -o /principal

EXPOSE 2468

CMD ["/main"]

The place is your principal package deal? It’s best to strive (I’m assuming you go.mod in . dir):

rm -rf ./vendor
go mod tidy
go mod vendor
go construct -o principal . //if . is principal package deal and might strive construct ...
FROM golang:1.22-alpine

WORKDIR /app

COPY . .

RUN go mod tidy // strive once more

RUN go construct -o /principal . //if . is principal package deal -> /app

EXPOSE 2468

CMD ["/main"]

Sure my principal package deal is ., i attempted however git was not put in in alpine picture so i used golang:1.22 as a substitute and no git challenge.

However now i acquired error with go mod tidy solely in server.
I must create model tag in my github repo to be able to construct in server ?

> [4/5] RUN go mod tidy:
1.292 go: downloading github.com/google/go-cmp v0.6.0
1.344 go: downloading google.golang.org/appengine v1.6.8
1.444 go: downloading github.com/golang/protobuf v1.5.3
1.750 go: downloading google.golang.org/protobuf v1.32.0
2.088 go: discovering module for package deal github.com/rousseau-romain/round-timing/views/web page
2.089 go: discovering module for package deal github.com/rousseau-romain/round-timing/shared/parts
5.754 go: github.com/rousseau-romain/round-timing/handlers imports
5.754 	github.com/rousseau-romain/round-timing/shared/parts: no matching variations for question "newest"
5.754 go: github.com/rousseau-romain/round-timing/handlers imports
5.754 	github.com/rousseau-romain/round-timing/views/web page: no matching variations for question "newest"

You could have an issue along with your code, you could have an issue with import.
Have you ever actually tried an area construct? Such code is aware of at a look that it can’t be compiled.

When i compile my code localy i acquired no challenge, bizarre.
Perhaps my configuration/set up isn’t good regionally, i’ll attempt to take away go set up and reinstall.

➜  round-timing git:(grasp) ✗ docker construct -t round-timing . 
[+] Constructing 9.4s (10/10) FINISHED                                                                                                                                                                          
 => [internal] load construct definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 73B                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/golang:1.22                                                                                                                                         0.0s
 => [internal] load construct context                                                                                                                                                                      0.1s
 => => transferring context: 103.52kB                                                                                                                                                                  0.1s
 => [1/5] FROM docker.io/library/golang:1.22                                                                                                                                                           0.0s
 => CACHED [2/5] WORKDIR /app                                                                                                                                                                          0.0s
 => [3/5] COPY . .                                                                                                                                                                                     0.4s
 => [4/5] RUN go mod tidy                                                                                                                                                                              1.2s
 => [5/5] RUN go construct -o /principal .                                                                                                                                                                      7.3s 
 => exporting to picture                                                                                                                                                                                 0.4s 
 => => exporting layers                                                                                                                                                                                0.4s 
 => => writing picture sha256:b5de9bc0452740ecd2c9800f2fc1371dda31c1388339c66936bc90c63b64417d                                                                                                           0.0s 
 => => naming to docker.io/library/round-timing   

The import for my native isn’t the proper method to do it ?

github.com/rousseau-romain/round-timing/views/web page
It’s not a legitimate go package deal path as a result of there isn’t a go file in it, and I don’t know the way you run it, however there’s one thing incorrect with the code itself.

Okay thanks i have a look !

You probably have the habits of producing code, then it is best to commit the generated code to Git as a substitute of leaving a prototype.



1 Like

I discovered the problem, i’m so dumb lol.
I take advantage of templ to generate gofile from.templ file and that i didn’t need to commit the generated file.
So clearly if i don’t generate the go file inside docker it wont work, i’ve added in my Dockerfile:

RUN go set up github.com/a-h/templ/cmd/templ@v0.2.793
RUN templ generate

Thx to your time and your assist @peakedshout !

This isn’t an excellent observe. With construct, should you can’t present a make construct circulate, then it is best to guarantee code integrity.
The grpc protobuf, for instance, generates code, however sometimes git commits the generated code as a substitute of letting the builder generate it. (Variations in technology instruments can result in variations in generated code)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments