gabriel-vasile / mimetype

A fast Golang library for media type and file extension detection, based on magic numbers
https://pkg.go.dev/github.com/gabriel-vasile/mimetype#pkg-overview
MIT License
1.63k stars 160 forks source link

Cannot download library in docker build #425

Open ljahier opened 1 year ago

ljahier commented 1 year ago

Hello,

Issue Description: When running a docker build -t my-app-name . command, the go mod download step is triggered to install project dependencies. However, an error is encountered during this process that prevents successful dependency installation. The specific error message is as follows:

=> ERROR [4/7] RUN go mod download                                                                                                                                                                                                                                                                                                                                    2.7s
------
 > [4/7] RUN go mod download:
2.588 go: github.com/gabriel-vasile/mimetype@v1.4.2: reading https://proxy.golang.org/github.com/gabriel-vasile/mimetype/@v/v1.4.2.zip: 403 Forbidden
------
Dockerfile:9
--------------------
   7 |     # Download Go modules
   8 |     COPY go.mod go.sum ./
   9 | >>> RUN go mod download
  10 |
  11 |
--------------------
ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1```

Expected Behavior: The go mod download step should successfully install the project dependencies without encountering any errors related to the github.com/gabriel-vasile/mimetype dependency.

Actual Behavior: The go mod download step encounters a 403 Forbidden error when trying to access the following URL: https://proxy.golang.org/github.com/gabriel-vasile/mimetype/@v/v1.4.2.zip

Additional Context:

Dockerfile:

FROM golang:1.21

WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

COPY . .

COPY xxxx-api.conf /app/.env

RUN CGO_ENABLED=0 GOOS=linux go build -o api

EXPOSE 8080

CMD ["./api"]

Environment Details:

gabriel-vasile commented 1 year ago

Hi, unfortunately I cannot reproduce the problem.

This issue seems to be related. Can you try any of the suggestions there? Someone says the problem happens for big repositories, which might be the case here: mimetype has many test files.

fbarikzehi commented 7 months ago

I had the same problem.just set GOPROXY=direct: GOPROXY=direct go get github.com/gabriel-vasile/mimetype