I am trying to build a docker image containing the library and code, it seems to not able to find the library after building from source.
ARG GOLANG_IMAGE_TAG="1.20.6-alpine"
FROM golang:${GOLANG_IMAGE_TAG} as base
ARG PDF2IMG_VERSION=dev
# So using 8.13.3 for now
ARG VIPS_VERSION="8.13.3"
RUN apk update && apk add --no-cache \
automake build-base pkgconfig gcc musl-dev vips-dev glib-dev expat-dev gobject-introspection \
libjpeg-turbo-dev libpng-dev libwebp-dev giflib-dev librsvg-dev libexif-dev lcms2-dev
ARG VIPS_URL=https://github.com/libvips/libvips/releases/download
ADD ${VIPS_URL}/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz \
/tmp/
RUN cd /tmp \
&& tar xf vips-${VIPS_VERSION}.tar.gz \
&& cd vips-${VIPS_VERSION} \
&& CFLAGS="-g -O3" CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -g -O3" \
./configure \
# --prefix=/usr \
# --disable-debug \
# --disable-dependency-tracking \
# --disable-introspection \
# --disable-static \
# --without-gsf \
# --without-magick \
# --without-openslide \
# --without-pdfium \
# --enable-gtk-doc-html=no \
# --enable-gtk-doc=no \
# --enable-pyvips8=no \
&& make -j4 V=0 \
&& make install
# create a working directory inside the image
WORKDIR /go/src/github.com/felixgao/pdf2img
# Cache go modules
ENV GO111MODULE="on"
ENV CPATH="/usr/local/include"
ENV LIBRARY_PATH="/usr/local/lib"
ENV PKG_CONFIG_PATH="/vips/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
ENV GOROOT="/usr/local/go"
ENV GOPATH="/go"
ENV PATH="/go/bin:$PATH"
# Copy go mod and sum files and files i.e all files ending with .go
COPY go.mod go.sum *.go ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
RUN go list -mod=readonly -u -m -json all
# Build the Go app with ldflags
RUN CGO_ENABLED=0 GOOS=linux go build -a \
-ldflags="-s -w -h -X main.Version=${PDF2IMG_VERSION}" \
-o pdf2png
# build target image
FROM golang:${GOLANG_IMAGE_TAG} as prod
RUN apk --update add --no-cache \
fftw glib expat libjpeg-turbo libpng \
libwebp giflib librsvg libgsf libexif lcms2
WORKDIR /root/
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /root/libs/* /root/libs/
COPY --from=base /usr/local/lib/* /usr/local/lib/
WORKDIR /app/
COPY --from=base /go/src/github.com/felixgao/pdf2img/pdf2png .
#tell docker what port to expose
EXPOSE 8080
# Run the binary program produced by `go install`
CMD ["./pdf2png"]
I am trying to build a docker image containing the library and code, it seems to not able to find the library after building from source.
the output of the build
This is the docker version I am using.
here is my go.mod in case it helps