Make subscription manager independent of E2SMs
[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 FROM nexus3.o-ran-sc.org:10004/o-ran-sc/bldr-ubuntu18-c-go:9-u18.04 as submgrcore
27
28 RUN apt update && apt install -y iputils-ping net-tools curl tcpdump gdb valgrind
29
30 WORKDIR /tmp
31
32 #RUN git clone https://github.com/nokia/asn1c.git
33 #RUN cd asn1c && test -f configure || autoreconf -iv
34 #RUN cd asn1c &&  ./configure
35 #RUN cd asn1c && make
36 ##RUN cd asn1c && make check
37 #RUN cd asn1c && make install
38
39 #
40 # Swagger
41 #
42 ARG SWAGGERVERSION=v0.23.0
43 ARG SWAGGERURL=https://github.com/go-swagger/go-swagger/releases/download/${SWAGGERVERSION}/swagger_linux_amd64
44 RUN wget --quiet ${SWAGGERURL} \
45     && mv swagger_linux_amd64 swagger \
46     && chmod +x swagger \
47     && mv swagger /usr/local/bin/
48
49 #
50 # GO DELVE
51 #
52 RUN export GOBIN=/usr/local/bin/ ; \
53     go get -u github.com/go-delve/delve/cmd/dlv \
54     && go install github.com/go-delve/delve/cmd/dlv
55
56
57 #
58 # RMR
59 #
60 ARG RMRVERSION=4.0.2
61 ARG RMRLIBURL=https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb
62 ARG RMRDEVURL=https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb
63 RUN wget --content-disposition ${RMRLIBURL} && dpkg -i rmr_${RMRVERSION}_amd64.deb
64 RUN wget --content-disposition ${RMRDEVURL} && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb
65 RUN rm -f rmr_${RMRVERSION}_amd64.deb rmr-dev_${RMRVERSION}_amd64.deb
66
67
68 RUN mkdir /manifests/
69 RUN echo "rmrlib ${RMRVERSION} ${RMRLIBURL}" >> /manifests/versions.txt
70 RUN echo "rmrdev ${RMRVERSION} ${RMRDEVURL}" >> /manifests/versions.txt
71 RUN echo "swagger ${SWAGGERVERSION} ${SWAGGERURL}" >> /manifests/versions.txt
72
73
74 WORKDIR /opt/submgr
75
76 ###########################################################
77 #
78 ###########################################################
79 FROM submgrcore as submgre2apbuild
80
81
82 ENV CFLAGS="-DASN_DISABLE_OER_SUPPORT"
83 ENV CGO_CFLAGS="-DASN_DISABLE_OER_SUPPORT"
84
85 COPY 3rdparty 3rdparty
86 RUN cd 3rdparty/E2AP-v01.00.00 && \
87     gcc -c ${CFLAGS} -I. -g -fPIC *.c  && \
88     gcc *.o -g -shared -o libe2ap.so && \
89     cp libe2ap.so /usr/local/lib/ && \
90     cp *.h /usr/local/include/ && \
91     ldconfig
92
93
94 RUN echo "E2AP         E2AP-v01.00.00" >> /manifests/versions.txt
95
96 COPY e2ap e2ap
97 RUN cd e2ap/libe2ap_wrapper && \
98     gcc -c ${CFLAGS} -g -fPIC *.c  && \
99     gcc *.o -g -shared -o libe2ap_wrapper.so && \
100     cp libe2ap_wrapper.so /usr/local/lib/ && \
101     cp *.h /usr/local/include/ && \
102     ldconfig
103
104 # unittest
105 RUN cd e2ap && go test -v ./pkg/conv
106 RUN cd e2ap && go test -v ./pkg/e2ap_wrapper
107
108 # test formating (not important)
109 RUN cd e2ap && test -z "$(gofmt -l pkg/conv/*.go)"
110 RUN cd e2ap && test -z "$(gofmt -l pkg/e2ap_wrapper/*.go)"
111 RUN cd e2ap && test -z "$(gofmt -l pkg/e2ap/*.go)"
112 RUN cd e2ap && test -z "$(gofmt -l pkg/e2ap/e2ap_tests/*.go)"
113
114
115 ###########################################################
116 #
117 ###########################################################
118 FROM submgre2apbuild as submgrbuild
119 #
120 #
121 #
122 COPY go.mod go.mod
123 COPY go.sum go.sum
124
125 RUN go mod download
126 RUN go mod tidy
127
128 #
129 #
130 #
131 RUN mkdir pkg
132 COPY api api
133
134
135 ARG RTMGRVERSION=cd7867c8f527f46fd8702b0b8d6b380a8e134bea
136
137 RUN git clone "https://gerrit.o-ran-sc.org/r/ric-plt/rtmgr" \
138     && git -C "rtmgr" checkout $RTMGRVERSION \
139     && cp rtmgr/api/routing_manager.yaml api/ \
140     && rm -rf rtmgr
141
142
143 RUN mkdir -p /root/go && \
144     swagger generate client -f api/routing_manager.yaml -t pkg/ -m rtmgr_models -c rtmgr_client
145
146
147 RUN echo "rtmgrapi ${RTMGRVERSION} https://gerrit.o-ran-sc.org/r/ric-plt/rtmgr" >> /manifests/versions.txt
148
149 #
150 #
151 #
152 COPY pkg pkg
153 COPY cmd cmd
154
155 RUN mkdir -p /opt/bin && \
156     go build -o /opt/bin/submgr cmd/submgr.go && \
157     mkdir -p /opt/build/container/usr/local
158
159
160 RUN go mod tidy
161
162 RUN cp go.mod go.sum /manifests/
163 RUN grep gerrit /manifests/go.sum > /manifests/go_gerrit.sum
164
165
166 # unittest
167 COPY test/config-file.json test/config-file.json
168 ENV CFG_FILE=/opt/submgr/test/config-file.json
169 COPY test/uta_rtg.rt test/uta_rtg.rt
170 ENV RMR_SEED_RT=/opt/submgr/test/uta_rtg.rt 
171
172 #ENV CGO_LDFLAGS="-fsanitize=address"
173 #ENV CGO_CFLAGS="-fsanitize=address"
174
175 RUN go test -test.coverprofile /tmp/submgr_cover.out -count=1 -v ./pkg/control 
176 RUN go tool cover -html=/tmp/submgr_cover.out -o /tmp/submgr_cover.html
177
178 # test formating (not important)
179 RUN test -z "$(gofmt -l pkg/control/*.go)"
180 RUN test -z "$(gofmt -l pkg/teststub/*.go)"
181 RUN test -z "$(gofmt -l pkg/teststubdummy/*.go)"
182 RUN test -z "$(gofmt -l pkg/teststube2ap/*.go)"
183 RUN test -z "$(gofmt -l pkg/xapptweaks/*.go)"
184
185
186 ###########################################################
187 #
188 ###########################################################
189 FROM ubuntu:18.04
190
191 RUN apt update && apt install -y iputils-ping net-tools curl tcpdump
192
193 COPY --from=submgrbuild /manifests /manifests
194
195 COPY --from=submgrbuild /opt/bin/submgr /
196 COPY --from=submgrbuild /usr/local/include /usr/local/include
197 COPY --from=submgrbuild /usr/local/lib /usr/local/lib
198 RUN ldconfig
199
200 COPY run_submgr.sh /
201 RUN chmod 755 /run_submgr.sh
202
203 #default config
204 COPY config /opt/config
205 ENV CFG_FILE=/opt/config/submgr-config.yaml
206 ENV RMR_SEED_RT=/opt/config/submgr-uta-rtg.rt
207
208 ENTRYPOINT ["/submgr"]