blob: bbd3f1efa4fc806025e361ec9cbf1bef1e458f10 [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
23RUN apk add --no-cache libssh-dev=0.9.5-r0 openssl-dev=1.1.1n-r0 openssl=1.1.1n-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
85RUN apk add --no-cache pcre2=10.36-r0 libssh=0.9.5-r0 openssl=1.1.1n-r0
86
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
92COPY --from=dev /usr/local/lib64 /usr/local/lib64
93COPY --from=dev /usr/local/share /usr/local/share
94COPY --from=dev /etc/sysrepo /etc/sysrepo
95
Elia Battistonac8d23f2022-03-14 17:54:56 +010096# Copy yang files and install them to sysrepo
97COPY ./build/yang-files /yang
Elia Battistonb244bb52022-03-24 15:47:16 +010098RUN for f in /yang/*.yang; do sysrepoctl -i "$f" -s /yang -p 664 -v3; done
Elia Battistonac8d23f2022-03-14 17:54:56 +010099
Elia Battiston589addb2022-04-04 16:40:01 +0200100# Enable admin and oper state in ietf-hardware
101RUN sysrepoctl -e hardware-state -c ietf-hardware
102
103COPY ./build/yang-files/schema-mount.xml /
104
105# Add sysrepo's yang library data to the data provided to the schema-mount libyang extension
106RUN sysrepocfg -X -x/ietf-yang-library:* -d operational >> /schema-mount.xml
107
Elia Battistonac8d23f2022-03-14 17:54:56 +0100108# Add user for connecting to netopeer2-server through ssh
109ARG NETCONF_USER=voltha
110ARG NETCONF_PASSWORD=onf
111
Elia Battistonb244bb52022-03-24 15:47:16 +0100112RUN addgroup -S netconf
113RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password
Elia Battistonac8d23f2022-03-14 17:54:56 +0100114RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd
Elia Battistonc8d0d462022-02-22 16:30:51 +0100115
116# Set the working directory
Elia Battiston589addb2022-04-04 16:40:01 +0200117WORKDIR /
Elia Battistonc8d0d462022-02-22 16:30:51 +0100118
119# Copy required files
120COPY --from=dev /app/bbf-adapter /app/bbf-adapter
121
122# Label image
123ARG org_label_schema_version=unknown
124ARG org_label_schema_vcs_url=unknown
125ARG org_label_schema_vcs_ref=unknown
126ARG org_label_schema_build_date=unknown
127ARG org_opencord_vcs_commit_date=unknown
128ARG org_opencord_vcs_dirty=unknown
129
130LABEL \
131org.label-schema.schema-version=1.0 \
132org.label-schema.name=voltha-northbound-bbf-adapter \
133org.label-schema.version=$org_label_schema_version \
134org.label-schema.vcs-url=$org_label_schema_vcs_url \
135org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
136org.label-schema.build-date=$org_label_schema_build_date \
137org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
138org.opencord.vcs-dirty=$org_opencord_vcs_dirty
139
Elia Battistonac8d23f2022-03-14 17:54:56 +0100140# running netopeer2-server as a standard user is not supported right now
141# https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173