7cb06df5e08bd97d80c032c988dd3f5dfd65a10c
[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:10004/bldr-ubuntu18-c-go:4-u18.04-nng AS o2mediator-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       libpcre3-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
68 # sysrepo
69 RUN \
70       cd /opt/dev && \
71       git clone https://github.com/sysrepo/sysrepo.git && \
72       cd sysrepo && mkdir build && cd build && \
73       cmake -DCMAKE_BUILD_TYPE:String="Release" -DSR_RPC_CB_TIMEOUT=30000 -DENABLE_TESTS=OFF -DREPOSITORY_LOC:PATH=/etc/sysrepo .. && \
74       make -j2 && \
75       make install && make sr_clean && \
76       ldconfig
77
78 # libnetconf2
79 RUN \
80       cd /opt/dev && \
81       git clone https://github.com/CESNET/libnetconf2.git && \
82       cd libnetconf2 && mkdir build && cd build && \
83       cmake -DCMAKE_BUILD_TYPE:String="Release" -DENABLE_BUILD_TESTS=OFF .. && \
84       make -j2 && \
85       make install && \
86       ldconfig
87
88 # netopeer2
89 RUN \
90       cd /opt/dev && \
91       git clone https://github.com/CESNET/Netopeer2.git && \
92       cd Netopeer2/server && mkdir build && cd build && \
93       cmake -DCMAKE_BUILD_TYPE:String="Release" .. && \
94       make -j2 && \
95       make install && \
96       cd ../../cli && mkdir build && cd build && \
97       cmake -DCMAKE_BUILD_TYPE:String="Release" .. && \
98       make -j2 && \
99       make install
100       
101 # ======================================================================
102
103 # RMR
104 ARG RMRVERSION=1.11.0
105 ARG RMRLIBURL=https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb
106 ARG RMRDEVURL=https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb
107
108 RUN wget --content-disposition ${RMRLIBURL} && dpkg -i rmr_${RMRVERSION}_amd64.deb
109 RUN wget --content-disposition ${RMRDEVURL} && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb
110 RUN rm -f rmr_${RMRVERSION}_amd64.deb rmr-dev_${RMRVERSION}_amd64.deb
111 RUN ldconfig
112
113 # Swagger
114 RUN mkdir -p /go/bin
115 RUN cd /go/bin \
116     && wget --quiet https://github.com/go-swagger/go-swagger/releases/download/v0.19.0/swagger_linux_amd64 \
117     && mv swagger_linux_amd64 swagger \
118     && chmod +x swagger
119
120 RUN mkdir -p /go/src/ws
121 WORKDIR "/go/src/ws/agent"
122
123 # Module prepare (if go.mod/go.sum updated)
124 COPY agent /go/src/ws
125 RUN GO111MODULE=on go mod download
126
127 RUN mkdir -p api \
128     && mkdir -p pkg \
129     && git clone "https://gerrit.o-ran-sc.org/r/ric-plt/appmgr" \
130     && cp appmgr/api/appmgr_rest_api.yaml api/ \
131     && rm -rf appmgr
132     
133 # build and test
134 COPY . /go/src/ws
135
136 # generate swagger client
137 RUN /go/bin/swagger generate client -f api/appmgr_rest_api.yaml -t pkg/ -m appmgrmodel -c appmgrclient
138 # build the o1agent
139 RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o o1agent cmd/o1agent.go
140
141 COPY . /go/src/ws
142
143 # make the data model based on the ric yang model
144 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-xapp-desc-v1.yang
145 RUN /usr/local/bin/sysrepoctl -i /go/src/ws/agent/yang/o-ran-sc-ric-ueec-config-v1.yang
146
147 CMD ["/bin/bash"]
148
149 #----------------------------------------------------------
150 FROM ubuntu:18.04 as o1mediator
151
152 RUN apt-get update -y && apt-get install -y jq \
153       net-tools \
154       tcpdump \
155       netcat \
156       keychain \
157       nano \
158       supervisor \
159       openssl \
160       python-pip \
161       libpcre3-dev \
162       pkg-config \
163       libavl-dev \
164       libev-dev \
165       libprotobuf-c-dev \
166       protobuf-c-compiler \
167       libssh-dev \
168       libssl-dev \
169       swig \
170       python-dev \
171       && pip install supervisor-stdout \
172       && pip install psutil \
173       && apt-get clean
174
175 RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
176
177 # add netconf user
178 RUN \
179       adduser --system netconf && \
180       echo "netconf:netconf" | chpasswd
181
182 # generate ssh keys for netconf user
183 RUN \
184       mkdir -p /home/netconf/.ssh && \
185       ssh-keygen -A && \
186       ssh-keygen -t dsa -P '' -f /home/netconf/.ssh/id_dsa && \
187       cat /home/netconf/.ssh/id_dsa.pub > /home/netconf/.ssh/authorized_keys
188
189 # copy the supervisor config
190 ARG CONFIGDIR=/etc/supervisor
191 RUN mkdir -p ${CONFIGDIR}
192 COPY config/supervisord.conf ${CONFIGDIR}/supervisord.conf
193     
194 # libraries and binaries & config
195 COPY --from=o2mediator-build /usr/local/share/ /usr/local/share/
196 COPY --from=o2mediator-build /usr/local/etc/ /usr/local/etc/
197 COPY --from=o2mediator-build /usr/local/bin/ /usr/local/bin/
198 COPY --from=o2mediator-build /usr/local/lib/ /usr/local/lib/
199 RUN ldconfig
200
201 # copy yang models with data
202 COPY --from=o2mediator-build /etc/sysrepo /etc/sysrepo
203
204 COPY --from=o2mediator-build /go/src/ws/agent/o1agent /usr/local/bin
205 COPY --from=o2mediator-build /go/src/ws/manager/src/process-state.py /usr/local/bin
206 RUN mkdir -p /etc/o1agent
207 COPY --from=o2mediator-build /go/src/ws/agent/config/* /etc/o1agent/
208
209 # ports available outside 8080 for mediator and 9001 supervise http control interrface
210 # port 830 for netconf client ssh session
211 # port 3000 for process-event handler web server
212 EXPOSE 9001 830 8080 3000
213
214 CMD ["/usr/bin/supervisord"]