blob: 72a466121a433d86cbb52395d7e0a1fd1d855be3 [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
22# Use Standard go build directory structure
23WORKDIR /go/src
24COPY . .
25
26ARG EXTRA_GO_BUILD_TAGS=""
27
Elia Battistonac8d23f2022-03-14 17:54:56 +010028ARG CGO_PARAMETER=1
Elia Battistonc8d0d462022-02-22 16:30:51 +010029
30ARG org_label_schema_version=unknown
31ARG org_label_schema_vcs_url=unknown
32ARG org_label_schema_vcs_ref=unknown
33ARG org_label_schema_build_date=unknown
34ARG org_opencord_vcs_commit_date=unknown
35ARG org_opencord_vcs_dirty=unknown
36
37# Build
Elia Battistonb244bb52022-03-24 15:47:16 +010038SHELL ["/bin/ash", "-o", "pipefail", "-c"]
Elia Battistonc8d0d462022-02-22 16:30:51 +010039RUN \
40 CGO_ENABLED=$CGO_PARAMETER go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /app/bbf-adapter \
41 -ldflags \
42 "-X github.com/opencord/voltha-lib-go/v7/pkg/version.version=$org_label_schema_version \
43 -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsRef=$org_label_schema_vcs_ref \
44 -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsDirty=$org_opencord_vcs_dirty \
45 -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') \
46 -X github.com/opencord/voltha-lib-go/v7/pkg/version.os=$(go env GOHOSTOS) \
47 -X github.com/opencord/voltha-lib-go/v7/pkg/version.arch=$(go env GOHOSTARCH) \
48 -X github.com/opencord/voltha-lib-go/v7/pkg/version.buildTime=$org_label_schema_build_date" \
49 ./cmd/bbf-adapter/
50
51WORKDIR /app
52
53# -------------
54# Image creation stage
Elia Battistonb244bb52022-03-24 15:47:16 +010055FROM alpine:3.13 AS prod
Elia Battistonac8d23f2022-03-14 17:54:56 +010056
Elia Battistonb244bb52022-03-24 15:47:16 +010057SHELL ["/bin/ash", "-o", "pipefail", "-c"]
Elia Battistonac8d23f2022-03-14 17:54:56 +010058
Elia Battistonb244bb52022-03-24 15:47:16 +010059RUN apk add --no-cache build-base=0.5-r2 pcre2-dev=10.36-r0 git=2.30.2-r0 cmake=3.18.4-r1 libssh-dev=0.9.5-r0 openssl-dev=1.1.1n-r0 openssl=1.1.1n-r0 bash=5.1.16-r0
Elia Battistonac8d23f2022-03-14 17:54:56 +010060
Elia Battistonb244bb52022-03-24 15:47:16 +010061RUN rm -r /usr/local/lib && ln -s /usr/local/lib64 /usr/local/lib
Elia Battistonac8d23f2022-03-14 17:54:56 +010062
Elia Battistonb244bb52022-03-24 15:47:16 +010063WORKDIR /
64
65COPY --from=dev /libyang /libyang
66COPY --from=dev /sysrepo /sysrepo
67
68#Build libyang
69WORKDIR /libyang/build
70RUN make install && \
71 rm -rf libyang
72
73#Build sysrepo
74WORKDIR /sysrepo/build
75RUN make install && \
76 rm -rf sysrepo
77
78ARG LIBNETCONF2_VERSION
79ARG NETOPEER2_VERSION
80
81#Build libnetconf2
82WORKDIR /
83RUN git clone https://github.com/CESNET/libnetconf2.git
84WORKDIR /libnetconf2
85RUN git checkout $LIBNETCONF2_VERSION && mkdir build
86WORKDIR /libnetconf2/build
87RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
88 make && \
89 make install && \
90 rm -rf libnetconf2
91
92#Build netopeer2
93WORKDIR /
94RUN git clone https://github.com/CESNET/netopeer2.git
95WORKDIR /netopeer2
96RUN git checkout $NETOPEER2_VERSION && mkdir build
97WORKDIR /netopeer2/build
98RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \
99 make && \
100 make install && \
101 rm -rf netopeer2
Elia Battistonac8d23f2022-03-14 17:54:56 +0100102
103# Copy yang files and install them to sysrepo
104COPY ./build/yang-files /yang
Elia Battistonb244bb52022-03-24 15:47:16 +0100105RUN for f in /yang/*.yang; do sysrepoctl -i "$f" -s /yang -p 664 -v3; done
Elia Battistonac8d23f2022-03-14 17:54:56 +0100106
107# Add user for connecting to netopeer2-server through ssh
108ARG NETCONF_USER=voltha
109ARG NETCONF_PASSWORD=onf
110
Elia Battistonb244bb52022-03-24 15:47:16 +0100111RUN addgroup -S netconf
112RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password
Elia Battistonac8d23f2022-03-14 17:54:56 +0100113RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd
Elia Battistonc8d0d462022-02-22 16:30:51 +0100114
115# Set the working directory
116WORKDIR /app
117
118# Copy required files
119COPY --from=dev /app/bbf-adapter /app/bbf-adapter
120
121# Label image
122ARG org_label_schema_version=unknown
123ARG org_label_schema_vcs_url=unknown
124ARG org_label_schema_vcs_ref=unknown
125ARG org_label_schema_build_date=unknown
126ARG org_opencord_vcs_commit_date=unknown
127ARG org_opencord_vcs_dirty=unknown
128
129LABEL \
130org.label-schema.schema-version=1.0 \
131org.label-schema.name=voltha-northbound-bbf-adapter \
132org.label-schema.version=$org_label_schema_version \
133org.label-schema.vcs-url=$org_label_schema_vcs_url \
134org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
135org.label-schema.build-date=$org_label_schema_build_date \
136org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
137org.opencord.vcs-dirty=$org_opencord_vcs_dirty
138
Elia Battistonac8d23f2022-03-14 17:54:56 +0100139# running netopeer2-server as a standard user is not supported right now
140# https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173