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