Merge "Add user-guide in SubManager's document"
[ric-plt/submgr.git] / Dockerfile
1 #
2 #==================================================================================
3 #   Copyright (c) 2019 AT&T Intellectual Property.
4 #   Copyright (c) 2019 Nokia
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #==================================================================================
18 #
19 #
20 #       Abstract:       Builds a container to compile Subscription Manager's code
21 #       Date:           28 May 2019
22 #
23
24 ###########################################################
25 #
26 ###########################################################
27 FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu18-c-go:3-u18.04-nng as submgrcore
28
29 RUN apt update && apt install -y iputils-ping net-tools curl tcpdump gdb valgrind
30
31 WORKDIR /tmp
32
33 ARG RMRVERSION=1.13.1
34 # Install RMr shared library
35 RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr_${RMRVERSION}_amd64.deb && rm -rf rmr_${RMRVERSION}_amd64.deb
36 # Install RMr development header files
37 RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb && rm -rf rmr-dev_${RMRVERSION}_amd64.deb
38
39 # "Installing Swagger"
40 RUN cd /usr/local/go/bin \
41     && wget --quiet https://github.com/go-swagger/go-swagger/releases/download/v0.19.0/swagger_linux_amd64 \
42     && mv swagger_linux_amd64 swagger \
43     && chmod +x swagger
44
45
46 ENV GOPATH=/root/.go
47 ENV PATH=$PATH:/root/.go/bin
48 RUN /usr/local/go/bin/go get -u github.com/go-delve/delve/cmd/dlv
49
50 WORKDIR /opt/submgr
51
52 ###########################################################
53 #
54 ###########################################################
55 FROM submgrcore as submgre2apbuild
56
57
58 ENV CFLAGS="-DASN_DISABLE_OER_SUPPORT"
59 ENV CGO_CFLAGS="-DASN_DISABLE_OER_SUPPORT"
60
61 COPY 3rdparty 3rdparty
62 RUN cd 3rdparty/libe2ap && \
63     gcc -c ${CFLAGS} -I. -g -fPIC *.c  && \
64     gcc *.o -g -shared -o libe2ap.so && \
65     cp libe2ap.so /usr/local/lib/ && \
66     cp *.h /usr/local/include/ && \
67     ldconfig
68
69 COPY e2ap e2ap
70 RUN cd e2ap/libe2ap_wrapper && \
71     gcc -c ${CFLAGS} -g -fPIC *.c  && \
72     gcc *.o -g -shared -o libe2ap_wrapper.so && \
73     cp libe2ap_wrapper.so /usr/local/lib/ && \
74     cp *.h /usr/local/include/ && \
75     ldconfig
76
77 # unittest
78 RUN cd e2ap && /usr/local/go/bin/go test -v ./pkg/conv
79 RUN cd e2ap && /usr/local/go/bin/go test -v ./pkg/e2ap_wrapper
80
81 # test formating (not important)
82 RUN cd e2ap && test -z "$(/usr/local/go/bin/gofmt -l pkg/conv/*.go)"
83 RUN cd e2ap && test -z "$(/usr/local/go/bin/gofmt -l pkg/e2ap_wrapper/*.go)"
84 RUN cd e2ap && test -z "$(/usr/local/go/bin/gofmt -l pkg/e2ap/*.go)"
85 RUN cd e2ap && test -z "$(/usr/local/go/bin/gofmt -l pkg/e2ap/e2ap_tests/*.go)"
86
87
88 ###########################################################
89 #
90 ###########################################################
91 FROM submgre2apbuild as submgrbuild
92 #
93 #
94 #
95 COPY go.mod go.mod
96 COPY go.sum go.sum
97
98 RUN /usr/local/go/bin/go mod download
99
100 #
101 #
102 #
103 RUN mkdir pkg
104 COPY api api
105
106
107 ARG RTMGRVERSION=cd7867c8f527f46fd8702b0b8d6b380a8e134bea
108
109 RUN git clone "https://gerrit.o-ran-sc.org/r/ric-plt/rtmgr" \
110     && git -C "rtmgr" checkout $RTMGRVERSION \
111     && cp rtmgr/api/routing_manager.yaml api/ \
112     && rm -rf rtmgr
113
114
115 RUN mkdir -p /root/go && \
116     /usr/local/go/bin/swagger generate client -f api/routing_manager.yaml -t pkg/ -m rtmgr_models -c rtmgr_client
117
118 #
119 #
120 #
121 COPY pkg pkg
122 COPY cmd cmd
123
124 RUN mkdir -p /opt/bin && \
125     /usr/local/go/bin/go build -o /opt/bin/submgr cmd/submgr.go && \
126     mkdir -p /opt/build/container/usr/local
127
128
129 RUN /usr/local/go/bin/go mod tidy
130
131 # unittest
132 COPY test/config-file.json test/config-file.json
133 ENV CFG_FILE=/opt/submgr/test/config-file.json
134
135 RUN /usr/local/go/bin/go test -test.coverprofile /tmp/submgr_cover.out -count=1 -v ./pkg/control 
136
137 #-c -o submgr_test
138 #RUN ./submgr_test -test.coverprofile /tmp/submgr_cover.out
139
140 RUN /usr/local/go/bin/go tool cover -html=/tmp/submgr_cover.out -o /tmp/submgr_cover.html
141
142 # test formating (not important)
143 RUN test -z "$(/usr/local/go/bin/gofmt -l pkg/control/*.go)"
144 RUN test -z "$(/usr/local/go/bin/gofmt -l pkg/teststub/*.go)"
145 RUN test -z "$(/usr/local/go/bin/gofmt -l pkg/teststubdummy/*.go)"
146 RUN test -z "$(/usr/local/go/bin/gofmt -l pkg/teststube2ap/*.go)"
147 RUN test -z "$(/usr/local/go/bin/gofmt -l pkg/xapptweaks/*.go)"
148
149
150 ###########################################################
151 #
152 ###########################################################
153 FROM ubuntu:18.04
154
155 RUN apt update && apt install -y iputils-ping net-tools curl tcpdump
156
157 COPY run_submgr.sh /
158 COPY --from=submgrbuild /opt/bin/submgr /
159 COPY --from=submgrbuild /usr/local/include /usr/local/include
160 COPY --from=submgrbuild /usr/local/lib /usr/local/lib
161 RUN ldconfig
162
163 RUN chmod 755 /run_submgr.sh
164 CMD /run_submgr.sh