gobuffalo/buffalo

invalid go version '1.21.3': must match format 1.23

ChaerilM opened this issue · 4 comments

Hi, i am trying to build dev container using dockerfile in wsl2. but its always having same error. changing go.mod version to 1.21 would fix the issue, but then i get another one saying 0.543 go: go.mod file indicates go 1.21, but maximum version supported by tidy is 1.18.

Are you using an official buffalo image? The latest buffalo image specifically sets the docker version in the container to 1.18. See the layers in the image details for the full picture.

no, i just use them in the default linux container. and seems i had 2 versions of go. uninstalled them all. then run docker build, since i had dockerfile

# This is a multi-stage Dockerfile and requires >= Docker 17.05
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
FROM gobuffalo/buffalo:v0.18.14 as builder

ENV GOPROXY http://proxy.golang.org

RUN mkdir -p /src/chaeril
WORKDIR /src/chaeril

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

ADD . .
RUN buffalo build --static -o /bin/app

FROM alpine
RUN apk add --no-cache bash
RUN apk add --no-cache ca-certificates

WORKDIR /bin/

COPY --from=builder /bin/app .

# Uncomment to run the binary in "production" mode:
# ENV GO_ENV=production

# Bind the app to 0.0.0.0 so it can be seen from outside the container
ENV ADDR=0.0.0.0

EXPOSE 3000

# Uncomment to run the migrations before running the binary:
# CMD /bin/app migrate; /bin/app
CMD exec /bin/app

but its still gave me same error

 => ERROR [builder 6/8] RUN go mod download                                                                        0.6s
------
 > [builder 6/8] RUN go mod download:
0.487 go: errors parsing go.mod:
0.487 /src/chaeril/go.mod:3: invalid go version '1.21.3': must match format 1.23
------
Dockerfile:15
--------------------
  13 |     # cache deps before building and copying source so that we don't need to re-download as much
  14 |     # and so that source changes don't invalidate our downloaded layer
  15 | >>> RUN go mod download
  16 |
  17 |     ADD . .
--------------------
ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1

Yeah, that's what I was saying. In the third line of the Dockerfile, you have FROM gobuffalo/buffalo:v0.18.14 as builder. That buffalo image you're using in the build stage only comes with Go 1.18. When you run go mod download, it's using the go.mod file in your project to know which dependencies to download. If you have Go 1.21 specified in the go.mod file, that will fail because it's trying to get dependencies that aren't compatible with the version of Go installed in the build container.

If you change the go.mod file to 1.18 and update your dependencies to compatible versions, that might work.

thanks!