I got issue when i build docker in my server but i don’t know why i haven’t localy, here is the stack trace:
"[6/6] RUN go build -o /main:
0.505 handlers/handlers.go:5:2: no required module provides package githubcom/rousseau-romain/round-timing/shared/components; to add it:
0.505 go get githubcom/rousseau-romain/round-timing/shared/components
0.505 handlers/auth.go:9:2: no required module provides package githubcom/rousseau-romain/round-timing/views/page; to add it:
0.505 go get githubcom/rousseau-romain/round-timing/views/page
The go mod file looks good and updated.
I tried to add go mod vendor in my dockerfile before my go mod download but i got issue to find external library.
“[7/7] RUN go build -o /main #11 0.378 main.go:11:2: cannot find module providing package github.com/gorilla/mux: import lookup disabled by -mod=vendor #11 0.378 (Go version in go.mod is at least 1.14 and vendor directory exists.) #11 0.378 config/config.go:8:2: cannot find module providing package github.com/joho/godotenv: import lookup disabled by -mod=vendor”
In order to copy the external library offline into the container i need to have my vendor directory inside my container, localy when i build my container localy i got my directory with external library.
The package github.com/rousseau-romain/ is part of my local project, it’s also considered as external library ?
Where is your main package? You should try (I’m assuming you go.mod in . dir):
rm -rf ./vendor
go mod tidy
go mod vendor
go build -o main . //if . is main package and can try build ...
FROM golang:1.22-alpine
WORKDIR /app
COPY . .
RUN go mod tidy // try again
RUN go build -o /main . //if . is main package -> /app
EXPOSE 2468
CMD ["/main"]
You have a problem with your code, you have a problem with import.
Have you really tried a local build? Such code knows at a glance that it cannot be compiled.
When i compile my code localy i got no issue, weird.
Maybe my configuration/installation is not good locally, i will try to remove go install and reinstall.
github.com/rousseau-romain/round-timing/views/page
It’s not a valid go package path because there isn’t a go file in it, and I don’t know how you run it, but there’s something wrong with the code itself.
I found the issue, i’m so dumb lol.
I use templ to generate gofile from.templ file and i didn’t want to commit the generated file.
So obviously if i don’t generate the go file inside docker it wont work, i have added in my Dockerfile:
RUN go install github.com/a-h/templ/cmd/templ@v0.2.793
RUN templ generate
This is not a good practice. With build, if you can’t provide a make build flow, then you should ensure code integrity.
The grpc protobuf, for example, generates code, but typically git commits the generated code instead of letting the builder generate it. (Differences in generation tools can lead to differences in generated code)