Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Docker image #44

Closed
tomcat-bit opened this issue Mar 19, 2020 · 2 comments
Closed

Build Docker image #44

tomcat-bit opened this issue Mar 19, 2020 · 2 comments

Comments

@tomcat-bit
Copy link

tomcat-bit commented Mar 19, 2020

I have a project with CGO as one of its dependencies. My Dockerfile looks like this:

COPY . /go/src/app
WORKDIR /go/src/app

RUN go get -v -d && \
    go build .

WORKDIR /
COPY --from=0 /go/src/app/build .

EXPOSE 18088

CMD ["/app"]

I get this error message after trying to build the image:

...
 github.com/billziss-gh/cgofuse/fuse
../github.com/billziss-gh/cgofuse/fuse/host.go:30:8: undefined: c_struct_fuse

The Dockerfile is incomplete and runs a single-stage build and is sub-optimal. However, optimizations is due for later. How do you properly build an image with CGO as a part of the build process?

@billziss-gh
Copy link
Collaborator

It is not clear to me what you are asking.

If you are looking for cross-compilation builds it is best to use xgo as documented here.

If you are looking to create your own Docker image to build cgofuse based projects then you need to install the prerequisites and then build as documented here.

@tomcat-bit
Copy link
Author

To explain better -- I'm using the current Docker file

FROM golang:alpine AS builder
ENV GOBIN $GOPATH/bin
RUN apk update
RUN apk add fuse-dev gcc libc-dev fuse

# Set necessary environmet variables needed for our image
ENV GO111MODULE=auto \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

RUN mkdir -p /go/src/github.com/tomcat-bit/cgofuse
WORKDIR /go/src/github.com/tomcat-bit/cgofuse

COPY go.mod .
COPY go.sum .
RUN go mod download 

COPY . .

RUN go build -a -o /fuser ./examples/passthrough
FROM alpine:latest

RUN apk update
RUN apk add fuse
COPY --from=builder /fuser /

I get

/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:30:8: undefined: c_struct_fuse
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:64:38: undefined: c_fuse_statvfs_t
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:79:33: undefined: c_fuse_stat_t
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:98:56: undefined: c_fuse_timespec_t
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:103:28: undefined: c_int
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:114:25: undefined: c_char
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:114:40: undefined: c_fuse_stat_t
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:114:62: undefined: c_int
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:124:26: undefined: c_char
/go/pkg/mod/github.com/billziss-gh/cgofuse@v1.4.0/fuse/host.go:124:55: undefined: c_size_t

It seems like using Go mod doesn't work with building with fuse. Further, using dep as described in andersjohansenange@a08ea76 works fine. When it works, I'll probably make a pull request on how to build a Docker image when Go modules is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants