# Copyright 2019 Nokia
-#
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM alpine:3.9
-MAINTAINER Levente Kale <levente.kale@nokia.com>
+ARG go_version
+FROM golang:${go_version}-alpine3.9 as builder
+MAINTAINER Ferenc Toth <ferenc.2.toth@nokia.com>
ARG SRIOVDP
-ENV SRIOVDP_VERSION=$SRIOVDP
-ENV GOPATH /go
-ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
-ENV GOOS=linux
+ARG SRIOVDP_HASH=""
-WORKDIR /
+RUN apk add --no-cache gcc musl-dev git curl tar linux-headers \
+&& mkdir -p $GOPATH/src/github.com/intel/sriov-network-device-plugin \
+&& cd $GOPATH/src/github.com/intel \
+&& if [ -n "$SRIOVDP_HASH" ]; then \
+ git clone https://github.com/intel/sriov-network-device-plugin.git \
+&& cd sriov-network-device-plugin \
+&& git checkout $SRIOVDP_HASH; \
+ else \
+ curl -fsSL https://github.com/intel/sriov-network-device-plugin/archive/v${SRIOVDP}.tar.gz | tar xz --strip-components=1 -C sriov-network-device-plugin; \
+ fi \
+&& go install -a -ldflags '-extldflags "-static"' github.com/intel/sriov-network-device-plugin/cmd/sriovdp
-RUN apk add --no-cache jq \
-&& apk add --no-cache --virtual .tools ca-certificates gcc musl-dev go glide git \
-&& mkdir -p $GOPATH/src/github.com/intel \
-&& git clone https://github.com/intel/sriov-network-device-plugin.git $GOPATH/src/github.com/intel/sriov-network-device-plugin --branch=v${SRIOVDP_VERSION} \
-&& cd $GOPATH/src/github.com/intel/sriov-network-device-plugin \
-&& glide --quiet install -v \
-&& go install -a -ldflags '-extldflags "-static"' github.com/intel/sriov-network-device-plugin/cmd/sriovdp \
-&& cp $GOPATH/bin/sriovdp /usr/local/bin/sriovdp \
-&& rm -rf $GOPATH/src \
-&& rm -rf $GOPATH/bin \
-&& apk del .tools \
-&& rm -rf /var/cache/apk/* \
-&& rm -rf /var/lib/apt/lists/* \
-&& rm -rf /tmp/* \
-&& rm -rf ~/.glide
+FROM alpine:3.9
+RUN apk add --no-cache hwdata-pci jq
+COPY --from=builder /go/bin/sriovdp /usr/local/bin/
RUN chmod 700 /usr/local/bin/sriovdp
+WORKDIR /
LABEL io.k8s.display-name="SRIOV Network Device Plugin"
ENTRYPOINT ["/usr/local/bin/sriovdp"]