blob: eccf3fa1e1980d1f7c9d181797e57860a151f8e2 [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 Battistonac8d23f2022-03-14 17:54:56 +010038SHELL ["/bin/bash", "-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 Battistonac8d23f2022-03-14 17:54:56 +010055FROM ubuntu:hirsute-20220113 AS prod
56
57SHELL ["/bin/bash", "-o", "pipefail", "-c"]
58RUN \
59 apt-get update && \
60 apt-get install -y \
61 wget=1.21-1ubuntu3 ca-certificates=20210119ubuntu0.21.04.1 \
62 libpcre2-8-0=10.36-2ubuntu5 \
63 libcrypt1=1:4.4.17-1ubuntu3 \
64 libssh-4=0.9.5-1ubuntu0.1 \
65 --no-install-recommends && \
66 rm -rf /var/lib/apt/lists/*
67
68# Download and install library packages
69RUN \
70 wget https://github.com/CESNET/libyang/releases/download/v2.0.112/libyang2_2.0.112.1-1_amd64.deb -O libyang2.deb && \
71 wget https://github.com/sysrepo/sysrepo/releases/download/v2.0.53/libsysrepo6_2.0.53.1-1_amd64.deb -O libsysrepo6.deb && \
72 wget https://github.com/sysrepo/sysrepo/releases/download/v2.0.53/sysrepo-tools_2.0.53.1-1_amd64.deb -O sysrepo-tools.deb && \
73 wget https://github.com/CESNET/libnetconf2/releases/download/v2.0.24/libnetconf2-2_2.0.24.1-1_amd64.deb -O libnetconf2-2.deb && \
74 wget https://github.com/CESNET/netopeer2/releases/download/v2.0.35/netopeer2_2.0.35.2-1_amd64.deb -O netopeer2_2.deb
75
76RUN dpkg -i libyang2.deb libsysrepo6.deb sysrepo-tools.deb libnetconf2-2.deb netopeer2_2.deb
77
78RUN rm libyang2.deb libsysrepo6.deb sysrepo-tools.deb libnetconf2-2.deb netopeer2_2.deb
79
80# Copy yang files and install them to sysrepo
81COPY ./build/yang-files /yang
Elia Battistone1cecb22022-03-21 10:05:25 +010082RUN for f in /yang/*.yang; do sysrepoctl -a -i "$f" -s /yang -p 664 -v3; done
Elia Battistonac8d23f2022-03-14 17:54:56 +010083
84# Add user for connecting to netopeer2-server through ssh
85ARG NETCONF_USER=voltha
86ARG NETCONF_PASSWORD=onf
87
88RUN useradd -rm -g netconf -u 1001 $NETCONF_USER
89RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd
Elia Battistonc8d0d462022-02-22 16:30:51 +010090
91# Set the working directory
92WORKDIR /app
93
94# Copy required files
95COPY --from=dev /app/bbf-adapter /app/bbf-adapter
96
97# Label image
98ARG org_label_schema_version=unknown
99ARG org_label_schema_vcs_url=unknown
100ARG org_label_schema_vcs_ref=unknown
101ARG org_label_schema_build_date=unknown
102ARG org_opencord_vcs_commit_date=unknown
103ARG org_opencord_vcs_dirty=unknown
104
105LABEL \
106org.label-schema.schema-version=1.0 \
107org.label-schema.name=voltha-northbound-bbf-adapter \
108org.label-schema.version=$org_label_schema_version \
109org.label-schema.vcs-url=$org_label_schema_vcs_url \
110org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
111org.label-schema.build-date=$org_label_schema_build_date \
112org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
113org.opencord.vcs-dirty=$org_opencord_vcs_dirty
114
Elia Battistonac8d23f2022-03-14 17:54:56 +0100115# running netopeer2-server as a standard user is not supported right now
116# https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173