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