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