blob: 2517145d8b5f073a811f2a1fd9d57638787dd637 [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
107RUN for f in /yang/*.yang; do sysrepoctl -i "$f" -s /yang -o $NETCONF_USER -g netconf -p 664 -v3; done
108RUN for f in /yang/*/*.yang; do sysrepoctl -i "$f" -s /yang -o $NETCONF_USER -g netconf -p 664 -v3; done
109
110COPY ./build/config /config
111# Disable nacm to test edit-config easily
112RUN sysrepocfg --import=/config/nacm.xml -d startup -m ietf-netconf-acm
113RUN sysrepocfg --import=/config/nacm.xml -d running -m ietf-netconf-acm
114RUN sysrepocfg --import=/config/nacm.xml -d candidate -m ietf-netconf-acm
115
116# Enable admin and oper state in ietf-hardware
117RUN sysrepoctl -e hardware-state -c ietf-hardware -v3
118
119COPY ./build/yang-files/schema-mount.xml /
120
121# Add sysrepo's yang library data to the data provided to the schema-mount libyang extension
122RUN sysrepocfg -X -x/ietf-yang-library:* -d operational >> /schema-mount.xml
123
Elia Battistonc8d0d462022-02-22 16:30:51 +0100124# Set the working directory
Elia Battiston589addb2022-04-04 16:40:01 +0200125WORKDIR /
Elia Battistonc8d0d462022-02-22 16:30:51 +0100126
127# Copy required files
128COPY --from=dev /app/bbf-adapter /app/bbf-adapter
129
130# Label image
131ARG org_label_schema_version=unknown
132ARG org_label_schema_vcs_url=unknown
133ARG org_label_schema_vcs_ref=unknown
134ARG org_label_schema_build_date=unknown
135ARG org_opencord_vcs_commit_date=unknown
136ARG org_opencord_vcs_dirty=unknown
137
138LABEL \
139org.label-schema.schema-version=1.0 \
140org.label-schema.name=voltha-northbound-bbf-adapter \
141org.label-schema.version=$org_label_schema_version \
142org.label-schema.vcs-url=$org_label_schema_vcs_url \
143org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
144org.label-schema.build-date=$org_label_schema_build_date \
145org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
146org.opencord.vcs-dirty=$org_opencord_vcs_dirty
147
Elia Battistonac8d23f2022-03-14 17:54:56 +0100148# running netopeer2-server as a standard user is not supported right now
149# https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173