[VOL-4673] Make better use of multistage builds to reduce docker images size

Change-Id: I230c256e30d1ca580b20f8a88d0258cf501d7b19
diff --git a/build/tools/Dockerfile.builder b/build/tools/Dockerfile.builder
index 1fe22ad..f84c03a 100644
--- a/build/tools/Dockerfile.builder
+++ b/build/tools/Dockerfile.builder
@@ -15,19 +15,35 @@
 # Dockerfile with golang and the sysrepo dependencies for voltha-northbound-bff-adapter
 # This image is used for testing, static code analysis and building
 
+# -------------
+# Build golangci-lint
+FROM --platform=linux/amd64 golang:1.16.3-alpine3.13 AS lint-builder
+
+RUN apk add --no-cache build-base=0.5-r2
+
+#Install golangci-lint
+RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2
+
+# -------------
+# Create the builder and tools image for the bbf adapter
+
 FROM --platform=linux/amd64 golang:1.16.3-alpine3.13 AS dev
 
 RUN mkdir -m 777 /.cache /go/pkg
 
 RUN apk add --no-cache build-base=0.5-r2 pcre2-dev=10.36-r0 git=2.30.2-r0 cmake=3.18.4-r1
 
-#Install golangci-lint
-RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2
+# Dependencies install their library files in lib64, add it to the path
+RUN echo "/lib:/usr/local/lib:/usr/lib:/usr/local/lib64" > /etc/ld-musl-x86_64.path
 
+# Get golangci-lint binary from its builder
+COPY --from=lint-builder /go/bin/golangci-lint /usr/bin/
 
 ARG LIBYANG_VERSION
 ARG SYSREPO_VERSION
 
+#Build compile time dependencies
+
 #Build libyang
 WORKDIR /
 RUN git clone https://github.com/CESNET/libyang.git
@@ -36,7 +52,8 @@
 WORKDIR /libyang/build
 RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
     make && \
-    make install
+    make install && \
+    rm -rf libyang
 
 #Build sysrepo
 WORKDIR /
@@ -46,7 +63,8 @@
 WORKDIR /sysrepo/build
 RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
     make && \
-    make install
+    make install && \
+    rm -rf sysrepo
 
 WORKDIR /app