Fixing O1 compilation
[ric-plt/o1.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 FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu18-c-go:1.9.0 AS o1mediator-build
18
19 RUN apt update && apt install --reinstall -y \
20   ca-certificates \
21   && \
22   update-ca-certificates
23
24 RUN apt-get update -y && apt-get install -y jq \
25       git \
26       cmake \
27       build-essential \
28       vim \
29       supervisor \
30       libpcre3-dev \
31       pkg-config \
32       libavl-dev \
33       libev-dev \
34       libprotobuf-c-dev \
35       protobuf-c-compiler \
36       libssh-dev \
37       libssl-dev \
38       swig \
39       iputils-ping \
40       python-dev
41
42 ENV PATH="/usr/local/go/bin:${PATH}"
43 ENV GOPATH="/go"
44
45 # ======================================================================
46 # First make the netconf sysrepo stuff
47 # add netconf user
48 RUN \
49       adduser --system netconf && \
50       echo "netconf:netconf" | chpasswd
51
52 # generate ssh keys for netconf user
53 RUN \
54       mkdir -p /home/netconf/.ssh && \
55       ssh-keygen -A && \
56       ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \
57       cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys
58
59 # use /opt/dev as working directory
60 RUN mkdir /opt/dev
61 WORKDIR /opt/dev
62
63 # libyang
64 RUN \
65       cd /opt/dev && \
66       git clone -b libyang1 https://github.com/CESNET/libyang.git && \
67       cd libyang && mkdir build && cd build && \
68       cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
69       make -j2 && \
70       make install && \
71       ldconfig
72 # sysrepo
73 RUN \
74       cd /opt/dev && \
75       git clone -b libyang1 https://github.com/sysrepo/sysrepo.git && \
76       cd sysrepo && sed -i -e 's/2000/30000/g;s/5000/30000/g' src/common.h.in && \
77       mkdir build && cd build && \
78       cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_TESTS=OFF -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \
79       make -j2 && \
80       make install && make sr_clean && \
81       ldconfig
82
83 # libssh 0.8.0
84 RUN \
85       cd /opt/dev && \
86       git clone https://git.libssh.org/projects/libssh.git && cd libssh && \
87       mkdir build && cd build && \
88       cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE="Release" -DWITH_ZLIB=ON -DWITH_NACL=OFF -DWITH_PCAP=OFF .. && \
89       make -j2 && \
90       make install
91
92 # libnetconf2
93 RUN \
94       cd /opt/dev && \
95       git clone -b libyang1 https://github.com/CESNET/libnetconf2.git && \
96       cd libnetconf2 && mkdir build && cd build && \
97       cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
98       make -j2 && \
99       make install && \
100       ldconfig
101
102 # netopeer2
103 RUN \
104       cd /opt/dev && \
105       git clone -b libyang1 https://github.com/CESNET/Netopeer2.git && \
106       cd Netopeer2 && mkdir build && cd build && \
107       cmake -DCMAKE_BUILD_TYPE:String="Release" -DNP2SRV_DATA_CHANGE_TIMEOUT=30000 -DNP2SRV_DATA_CHANGE_WAIT=ON .. && \
108       make -j2 && \
109       make install
110       
111 # ======================================================================
112
113 # RMR
114 ARG RMRVERSION=4.7.4
115 ARG RMRLIBURL=https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb
116 ARG RMRDEVURL=https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb
117
118 RUN wget --content-disposition ${RMRLIBURL} && dpkg -i rmr_${RMRVERSION}_amd64.deb
119 RUN wget --content-disposition ${RMRDEVURL} && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb
120 RUN rm -f rmr_${RMRVERSION}_amd64.deb rmr-dev_${RMRVERSION}_amd64.deb
121
122 # Install kubectl from Docker Hub
123 COPY --from=lachlanevenson/k8s-kubectl:v1.16.0 /usr/local/bin/kubectl /usr/local/bin/kubectl
124
125 RUN ldconfig
126
127 # Swagger
128 RUN mkdir -p /go/bin
129 RUN cd /go/bin \
130     && wget --quiet https://github.com/go-swagger/go-swagger/releases/download/v0.19.0/swagger_linux_amd64 \
131     && mv swagger_linux_amd64 swagger \
132     && chmod +x swagger
133
134 RUN mkdir -p /go/src/ws
135 COPY . /go/src/ws
136 WORKDIR "/go/src/ws/agent"
137
138 # Module prepare (if go.mod/go.sum updated)
139 RUN GO111MODULE=on go mod download
140
141 # Fetch xApp Manager REST API spec
142 RUN mkdir -p api \
143     && mkdir -p pkg \
144     && git clone "https://gerrit.o-ran-sc.org/r/ric-plt/appmgr" \
145     && cp appmgr/api/appmgr_rest_api.yaml api/ \
146     && rm -rf appmgr
147     
148 # generate swagger client
149 RUN /go/bin/swagger generate client -f api/appmgr_rest_api.yaml -t pkg/ -m appmgrmodel -c appmgrclient
150
151 # build and test o1agent
152 RUN ./build_o1agent.sh
153
154 # Install the data models based on the ric yang model
155 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-xapp-desc-v1.yang
156 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-ueec-config-v1.yang
157 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-gnb-status-v1.yang
158 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-alarm-v1.yang
159
160 CMD ["/bin/bash"]
161
162 #----------------------------------------------------------
163 FROM ubuntu:18.04 as o1mediator
164
165 RUN apt-get update -y && apt-get install -y jq \
166       net-tools \
167       tcpdump \
168       netcat \
169       keychain \
170       nano \
171       supervisor \
172       openssl \
173       python-pip \
174       libpcre3-dev \
175       pkg-config \
176       libavl-dev \
177       libev-dev \
178       libprotobuf-c-dev \
179       protobuf-c-compiler \
180       libssh-dev \
181       libssl-dev \
182       swig \
183       python-dev \
184       && pip install supervisor-stdout \
185       && pip install psutil \
186       && apt-get clean
187
188 RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
189
190 # update password policy 
191 RUN \
192       sed -i 's/pam_unix.so obscure sha512/pam_unix.so obscure sha512 rounds=12000/' /etc/pam.d/common-password
193
194 # add netconf user
195 RUN \
196       adduser --system netconf && \
197       echo "netconf:netconf" | chpasswd
198
199 # generate ssh keys for netconf user
200 RUN \
201       mkdir -p /home/netconf/.ssh && \
202       ssh-keygen -A && \
203       ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \
204       cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys
205
206 # copy the supervisor config
207 ARG CONFIGDIR=/etc/supervisor
208 RUN mkdir -p ${CONFIGDIR}
209 COPY config/supervisord.conf ${CONFIGDIR}/supervisord.conf
210     
211 # libraries and binaries & config
212 COPY --from=o1mediator-build /usr/local/share/ /usr/local/share/
213 COPY --from=o1mediator-build /usr/local/etc/ /usr/local/etc/
214 COPY --from=o1mediator-build /usr/local/bin/ /usr/local/bin/
215 COPY --from=o1mediator-build /usr/local/lib/ /usr/local/lib/
216 COPY --from=o1mediator-build /usr/local/bin/kubectl /usr/local/bin/kubectl
217
218 RUN ldconfig
219
220 # copy yang models with data
221 COPY --from=o1mediator-build /etc/sysrepo /etc/sysrepo
222
223 COPY --from=o1mediator-build /go/src/ws/agent/o1agent /usr/local/bin
224 COPY --from=o1mediator-build /go/src/ws/manager/src/process-state.py /usr/local/bin
225 RUN mkdir -p /etc/o1agent
226 COPY --from=o1mediator-build /go/src/ws/agent/config/* /etc/o1agent/
227
228 # ports available outside 8080 for mediator and 9001 supervise http control interrface
229 # port 830 for netconf client ssh session
230 # port 3000 for process-event handler web server
231 EXPOSE 9001 830 8080 3000
232
233 CMD ["/usr/bin/supervisord"]