fa9ec092f237c8fa170822e1dac101a4e0c440e7
[ta/caas-danm.git] / docker-build / danm-webhook / Dockerfile
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 FROM alpine:3.9
16 MAINTAINER Levente Kale <levente.kale@nokia.com>
17
18 ARG DANM_WEBHOOK_VERSION
19
20 ENV GOPATH /go
21 ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
22 ENV GOOS=linux
23 ARG code_generator_version="kubernetes-1.13.4"
24
25 WORKDIR /
26
27 RUN mkdir -p $GOPATH/bin \
28 &&  mkdir -p $GOPATH/src
29
30 RUN apk add --no-cache libcap iputils
31
32 RUN apk add --no-cache --virtual .tools ca-certificates gcc musl-dev go glide git tar curl \
33 &&  mkdir -p $GOPATH/src/github.com/nokia/danm \
34 &&  git clone https://github.com/nokia/danm.git $GOPATH/src/github.com/nokia/danm \
35 &&  cd $GOPATH/src/github.com/nokia/danm \
36 &&  git fetch --tags \
37 &&  git checkout ${DANM_WEBHOOK_VERSION} \
38 &&  glide install --strip-vendor \
39 &&  go get -d github.com/vishvananda/netlink \
40 &&  go get github.com/containernetworking/plugins/pkg/ns \
41 &&  go get github.com/golang/groupcache/lru \
42 &&  rm -rf $GOPATH/src/k8s.io/code-generator \
43 &&  git clone -b ${code_generator_version} --depth 1 https://github.com/kubernetes/code-generator.git $GOPATH/src/k8s.io/code-generator \
44 &&  go install k8s.io/code-generator/cmd/deepcopy-gen \
45 &&  go install k8s.io/code-generator/cmd/client-gen \
46 &&  go install k8s.io/code-generator/cmd/lister-gen \
47 &&  go install k8s.io/code-generator/cmd/informer-gen \
48 &&  deepcopy-gen --alsologtostderr --input-dirs github.com/nokia/danm/crd/apis/danm/v1 -O zz_generated.deepcopy --bounding-dirs github.com/nokia/danm/crd/apis \
49 &&  client-gen --alsologtostderr --clientset-name versioned --input-base "" --input github.com/nokia/danm/crd/apis/danm/v1 --clientset-path github.com/nokia/danm/crd/client/clientset \
50 &&  lister-gen --alsologtostderr --input-dirs github.com/nokia/danm/crd/apis/danm/v1 --output-package github.com/nokia/danm/crd/client/listers \
51 &&  informer-gen --alsologtostderr --input-dirs github.com/nokia/danm/crd/apis/danm/v1 --versioned-clientset-package github.com/nokia/danm/crd/client/clientset/versioned --listers-package github.com/nokia/danm/crd/client/listers --output-package github.com/nokia/danm/crd/client/informers \
52 &&  go install -a -ldflags '-extldflags "-static"' github.com/nokia/danm/cmd/webhook \
53 &&  cp $GOPATH/bin/webhook /usr/local/bin/webhook \
54 &&  rm -rf $GOPATH/src \
55 &&  rm -rf $GOPATH/bin \
56 &&  apk del .tools \
57 &&  rm -rf /var/cache/apk/* \
58 &&  rm -rf /var/lib/apt/lists/* \
59 &&  rm -rf /tmp/* \
60 &&  rm -rf ~/.glide
61
62 RUN adduser -u 147 -D -H -s /sbin/nologin danm \
63 &&  chown root:danm /usr/local/bin/webhook \
64 &&  chmod 750 /usr/local/bin/webhook
65
66 USER danm
67
68 ENTRYPOINT ["/usr/local/bin/webhook"]