4

I'm using multi-stage builds to separate the build environment from the final docker image:

FROM ubuntu:bionic AS build
RUN apt-get update && apt-get install -y \
    build-essential \
    [...]
RUN wget https://someserver.com/somefile.tar.gz && \
    tar xvzf somefile.tar.gz && \
    ./configure && \
    make && make install && \
    [missing part]

FROM ubuntu:bionic
COPY --from=build /tmp/fakeroot/ /
[...]

Is there an easy way to collect all files that where created/copied while make install was running?

Currently I'm using a combination of ldd and individual file copy to get them all:

cp /etc/xyz/* /tmp/fakeroot/xyz
cp --parents $(ldd /usr/sbin/nginx | grep -o '/.\+\.so[^ ]*' | sort | uniq) /tmp/fakeroot

But as make install already has the information of which file to copy to what directory I'm asking myself if there isn't any way to use this mechanism.

Thanks for any ideas!

kristianp
  • 103
  • 3
sc911
  • 335
  • 2
  • 14

2 Answers2

5

One way I found now is using checkinstall which replaces the make install step and tracks the installation to produce a package in the first stage. Then in the second stage I'm using dpkg to install this package.

So now I'm doing:

FROM ubuntu:bionic AS build
RUN [...]
    ./configure && \
    make && \
    checkinstall --install=no --default && \
    cp XYZ-*.deb /XYZ.deb

FROM ubuntu:bionic
COPY --from=build /XYZ.deb /
RUN dpkg -i /XYZ.deb && \
    rm /XYZ.deb && \
    [...]

Any downsides of this approach?

sc911
  • 335
  • 2
  • 14
1

./configure --prefix=/path/to/somewhere will force make install to deploy all files under /path/to/somewhere

So it is easy to copy all files from this place in the second stage.

Chaoxiang N
  • 1,218
  • 4
  • 10
  • but won't this prefix possibly be also used for other paths while building? depending on the make file this could be compiled into the binary and then I'm fixed to that path in the next stage. – sc911 Apr 01 '19 at 07:10
  • you can also use the same prefix for other builds. in the last stage, you still have `PATH` and `LD_LIBRARY_PATH` environment variables available to fix any issue while trying to execute binaries. – Chaoxiang N Apr 01 '19 at 07:13
  • I've been following https://stackoverflow.com/questions/11307465/destdir-and-prefix-of-make and came to the conclusion that using `--prefix` and `DESTDIR` are not as reliable as I want. – sc911 Apr 01 '19 at 08:30