blob: cd553030699298b1773a037f230df3a92c9c7a97 [file] [log] [blame]
Elia Battistonc8d0d462022-02-22 16:30:51 +01001# Copyright 2022-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# voltha-northbound-bbf-adapter dockerfile
16
17#-------------
18# Build stage
19
Elia Battistonac8d23f2022-03-14 17:54:56 +010020FROM voltha/bbf-adapter-builder:local AS dev
Elia Battistonc8d0d462022-02-22 16:30:51 +010021
Elia Battistonf9e12e62022-04-01 12:45:37 +020022#Build runtime dependencies
Elia Battiston4750d3c2022-07-14 13:24:56 +000023RUN apk add --no-cache libssh-dev=0.9.5-r0 openssl-dev=1.1.1q-r0 openssl=1.1.1q-r0 bash=5.1.16-r0
Elia Battistonb244bb52022-03-24 15:47:16 +010024
25ARG LIBNETCONF2_VERSION
26ARG NETOPEER2_VERSION
27
28#Build libnetconf2
29WORKDIR /
30RUN git clone https://github.com/CESNET/libnetconf2.git
31WORKDIR /libnetconf2
32RUN git checkout $LIBNETCONF2_VERSION && mkdir build
33WORKDIR /libnetconf2/build
34RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
35 make && \
36 make install && \
37 rm -rf libnetconf2
38
39#Build netopeer2
40WORKDIR /
41RUN git clone https://github.com/CESNET/netopeer2.git
42WORKDIR /netopeer2
43RUN git checkout $NETOPEER2_VERSION && mkdir build
44WORKDIR /netopeer2/build
45RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
46 make && \
47 make install && \
48 rm -rf netopeer2
Elia Battistonac8d23f2022-03-14 17:54:56 +010049
Elia Battistonf9e12e62022-04-01 12:45:37 +020050# Use Standard go build directory structure
51WORKDIR /go/src
52COPY . .
53
54ARG EXTRA_GO_BUILD_TAGS=""
55
56ARG CGO_PARAMETER=1
57
58ARG org_label_schema_version=unknown
59ARG org_label_schema_vcs_url=unknown
60ARG org_label_schema_vcs_ref=unknown
61ARG org_label_schema_build_date=unknown
62ARG org_opencord_vcs_commit_date=unknown
63ARG org_opencord_vcs_dirty=unknown
64
65# Build bbf-adapter
66SHELL ["/bin/ash", "-o", "pipefail", "-c"]
67RUN \
68 CGO_ENABLED=$CGO_PARAMETER go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /app/bbf-adapter \
69 -ldflags \
70 "-X github.com/opencord/voltha-lib-go/v7/pkg/version.version=$org_label_schema_version \
71 -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsRef=$org_label_schema_vcs_ref \
72 -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsDirty=$org_opencord_vcs_dirty \
73 -X github.com/opencord/voltha-lib-go/v7/pkg/version.goVersion=$(go version 2>&1 | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/g') \
74 -X github.com/opencord/voltha-lib-go/v7/pkg/version.os=$(go env GOHOSTOS) \
75 -X github.com/opencord/voltha-lib-go/v7/pkg/version.arch=$(go env GOHOSTARCH) \
76 -X github.com/opencord/voltha-lib-go/v7/pkg/version.buildTime=$org_label_schema_build_date" \
77 ./cmd/bbf-adapter/
78
79# -------------
80# Image creation stage
81FROM alpine:3.13 AS prod
82
83SHELL ["/bin/ash", "-o", "pipefail", "-c"]
84
Elia Battiston4750d3c2022-07-14 13:24:56 +000085RUN apk add --no-cache pcre2=10.36-r1 libssh=0.9.5-r0 openssl=1.1.1q-r0
Elia Battistonf9e12e62022-04-01 12:45:37 +020086
87# Dependencies install their library files in lib64, add it to the path
88RUN echo "/lib:/usr/local/lib:/usr/lib:/usr/local/lib64" > /etc/ld-musl-x86_64.path
89
90# Copy dependencies files
91COPY --from=dev /usr/local/bin /usr/local/bin
Elia Battiston4750d3c2022-07-14 13:24:56 +000092COPY --from=dev /usr/local/sbin /usr/local/sbin
Elia Battistonf9e12e62022-04-01 12:45:37 +020093COPY --from=dev /usr/local/lib64 /usr/local/lib64
94COPY --from=dev /usr/local/share /usr/local/share
95COPY --from=dev /etc/sysrepo /etc/sysrepo
96
Elia Battistonac8d23f2022-03-14 17:54:56 +010097# Add user for connecting to netopeer2-server through ssh
98ARG NETCONF_USER=voltha
99ARG NETCONF_PASSWORD=onf
100
Elia Battistonb244bb52022-03-24 15:47:16 +0100101RUN addgroup -S netconf
102RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password
Elia Battistonac8d23f2022-03-14 17:54:56 +0100103RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd
Elia Battistonc8d0d462022-02-22 16:30:51 +0100104
Elia Battiston4750d3c2022-07-14 13:24:56 +0000105# Copy yang files and install them to sysrepo
106COPY ./build/yang-files /yang
Elia Battiston4750d3c2022-07-14 13:24:56 +0000107RUN for f in /yang/*/*.yang; do sysrepoctl -i "$f" -s /yang -o $NETCONF_USER -g netconf -p 664 -v3; done
108
109COPY ./build/config /config
110# Disable nacm to test edit-config easily
111RUN sysrepocfg --import=/config/nacm.xml -d startup -m ietf-netconf-acm
112RUN sysrepocfg --import=/config/nacm.xml -d running -m ietf-netconf-acm
113RUN sysrepocfg --import=/config/nacm.xml -d candidate -m ietf-netconf-acm
114
115# Enable admin and oper state in ietf-hardware
116RUN sysrepoctl -e hardware-state -c ietf-hardware -v3
117
118COPY ./build/yang-files/schema-mount.xml /
119
120# Add sysrepo's yang library data to the data provided to the schema-mount libyang extension
121RUN sysrepocfg -X -x/ietf-yang-library:* -d operational >> /schema-mount.xml
122
Elia Battistonc8d0d462022-02-22 16:30:51 +0100123# Set the working directory
Elia Battiston589addb2022-04-04 16:40:01 +0200124WORKDIR /
Elia Battistonc8d0d462022-02-22 16:30:51 +0100125
126# Copy required files
127COPY --from=dev /app/bbf-adapter /app/bbf-adapter
128
129# Label image
130ARG org_label_schema_version=unknown
131ARG org_label_schema_vcs_url=unknown
132ARG org_label_schema_vcs_ref=unknown
133ARG org_label_schema_build_date=unknown
134ARG org_opencord_vcs_commit_date=unknown
135ARG org_opencord_vcs_dirty=unknown
136
137LABEL \
138org.label-schema.schema-version=1.0 \
139org.label-schema.name=voltha-northbound-bbf-adapter \
140org.label-schema.version=$org_label_schema_version \
141org.label-schema.vcs-url=$org_label_schema_vcs_url \
142org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
143org.label-schema.build-date=$org_label_schema_build_date \
144org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
145org.opencord.vcs-dirty=$org_opencord_vcs_dirty
146
Elia Battistonac8d23f2022-03-14 17:54:56 +0100147# running netopeer2-server as a standard user is not supported right now
148# https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173