0

I am dockerizing my app that runs in a custom base image with alpine:golang and goswagger installed. Currently, I'm trying to reduce the image size by implementing a multistage build. But when I run

swagger generate

it always showing error message:

lstat /root/go: no such file or directory

Can anyone tell me what is wrong with it? Ive checked in root/go directory and it is valid no go folder there but I can confirm the installation of go with running go build.

Here is my dockerfile

# Custom image with alpine and go:1.18.2 + goswagger installed

# Build binary stage
FROM gcrdomain/mycomp/go:1.18.2 as build

WORKDIR /app

# Install make
RUN apk add --no-cache make gcc libc-dev

COPY . .

# swagger validate + clean + generate
RUN make all

# Serve the binary stage

# Bare image with required deps to serve static binary
FROM scratch

WORKDIR /app

COPY --from=build /app/telemedicine-proxy-server /telemedicine-proxy-server

CMD ["/telemedicine-proxy-server", "--port=8080", "--host=0.0.0.0"]
amerw
  • 357
  • 2
  • 12
  • Looks like problem with go binary, try add to you `swagger generate` target `go env` output. – Roman Kiselenko May 25 '22 at 07:04
  • `go-swagger` is afaik codegen. It probably depends on some files inside its source tree installed to `GOPATH` (assuming `/root/go` is default one for user root). Does your `make all` call `go install` to get go-swagger installed? – blami May 25 '22 at 07:10
  • 1
    The Dockerfile you included doesn't have a `swagger generate` call or any reference to a `/root` directory. Can you [edit] the question to include the relevant fragment(s) of your Makefile as well? – David Maze May 25 '22 at 10:38
  • Actually the base image that i used is custom image with swagger installed on it, *i forgot to add that – amerw May 27 '22 at 02:00

1 Answers1

0

Finally, I found the issue, I've checked our custom base image and figured out that in our base image dockerfile the GOPATH is not placed in /root

ENV GO_PATH=/go

I've changed it to

ENV GO_PATH=/root/go

and everything worked as expected, thanks for all the comments!:D

amerw
  • 357
  • 2
  • 12