CI: Add silent prescan SonarCloud job
[ric-plt/appmgr.git] / Dockerfile
1 #   Copyright (c) 2019 AT&T Intellectual Property.
2 #   Copyright (c) 2019 Nokia.
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15
16 #-----------------------------------------------------------
17
18 FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu20-c-go:1.0.0 AS appmgr-build
19
20 RUN apt-get update -y && apt-get install -y jq
21
22 # Update CA certificates
23 RUN apt update && apt install --reinstall -y \
24   ca-certificates \
25   && \
26   update-ca-certificates
27
28 ENV PATH="/usr/local/go/bin:${PATH}"
29
30 # Install helm
31 #RUN wget -nv https://storage.googleapis.com/kubernetes-helm/helm-${HELMVERSION}-linux-amd64.tar.gz \
32 #    && tar -zxvf helm-${HELMVERSION}-linux-amd64.tar.gz \
33 #    && cp linux-amd64/helm /usr/local/bin/helm \
34 #    && rm -rf helm-${HELMVERSION}-linux-amd64.tar.gz \
35 #    && rm -rf linux-amd64
36
37 # Install kubectl from Docker Hub
38 #COPY --from=lachlanevenson/k8s-kubectl:v1.16.0 /usr/local/bin/kubectl /usr/local/bin/kubectl
39
40 ENV GOPATH="/go"
41
42 # Swagger
43 RUN mkdir -p /go/bin
44 RUN cd /go/bin \
45     && wget --quiet https://github.com/go-swagger/go-swagger/releases/download/v0.19.0/swagger_linux_amd64 \
46     && mv swagger_linux_amd64 swagger \
47     && chmod +x swagger
48
49 RUN mkdir -p /go/src/ws
50 WORKDIR "/go/src/ws"
51
52 # Module prepare (if go.mod/go.sum updated)
53 COPY go.mod /go/src/ws
54 COPY go.sum /go/src/ws
55 RUN GO111MODULE=on go mod download
56
57 # build and test
58 COPY . /go/src/ws
59
60 # Generate Swagger code
61 RUN /go/bin/swagger generate server -f api/appmgr_rest_api.yaml --name AppManager -t pkg/ --exclude-main
62
63 COPY . /go/src/ws
64
65 # Build the code
66 RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go/src/ws/cache/go/cmd/appmgr cmd/appmgr.go
67
68 # Run unit tests
69 RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go test -p 1 -cover ./pkg/resthooks/
70
71 RUN gofmt -l $(find cmd/ pkg/  -name '*.go' -not -name '*_test.go')
72
73 CMD ["/bin/bash"]
74
75 #----------------------------------------------------------
76 FROM ubuntu:20.04 as appmgr
77
78 RUN apt-get update -y \
79     && apt-get install --reinstall -y sudo openssl ca-certificates ca-cacert \
80     && apt-get clean && update-ca-certificates
81
82 #
83 # libraries and helm
84 #
85 COPY --from=appmgr-build /usr/local/include/ /usr/local/include/
86 COPY --from=appmgr-build /usr/local/lib/ /usr/local/lib/
87 #COPY --from=appmgr-build /usr/local/bin/helm /usr/local/bin/helm
88 #COPY --from=appmgr-build /usr/local/bin/kubectl /usr/local/bin/kubectl
89
90 RUN ldconfig
91
92 #
93 # xApp Manager
94 #
95 RUN mkdir -p /opt/xAppManager \
96     && chmod -R 755 /opt/xAppManager
97
98 COPY --from=appmgr-build /go/src/ws/cache/go/cmd/appmgr /opt/xAppManager/appmgr
99
100 WORKDIR /opt/xAppManager
101
102 COPY appmgr-entrypoint.sh /opt/xAppManager/
103 ENTRYPOINT ["/opt/xAppManager/appmgr-entrypoint.sh"]