Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 1 | # 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 Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 20 | FROM voltha/bbf-adapter-builder:local AS dev |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 21 | |
| 22 | # Use Standard go build directory structure |
| 23 | WORKDIR /go/src |
| 24 | COPY . . |
| 25 | |
| 26 | ARG EXTRA_GO_BUILD_TAGS="" |
| 27 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 28 | ARG CGO_PARAMETER=1 |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 29 | |
| 30 | ARG org_label_schema_version=unknown |
| 31 | ARG org_label_schema_vcs_url=unknown |
| 32 | ARG org_label_schema_vcs_ref=unknown |
| 33 | ARG org_label_schema_build_date=unknown |
| 34 | ARG org_opencord_vcs_commit_date=unknown |
| 35 | ARG org_opencord_vcs_dirty=unknown |
| 36 | |
| 37 | # Build |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 38 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 39 | RUN \ |
| 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 | |
| 51 | WORKDIR /app |
| 52 | |
| 53 | # ------------- |
| 54 | # Image creation stage |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 55 | FROM ubuntu:hirsute-20220113 AS prod |
| 56 | |
| 57 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] |
| 58 | RUN \ |
| 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 |
| 69 | RUN \ |
| 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 | |
| 76 | RUN dpkg -i libyang2.deb libsysrepo6.deb sysrepo-tools.deb libnetconf2-2.deb netopeer2_2.deb |
| 77 | |
| 78 | RUN rm libyang2.deb libsysrepo6.deb sysrepo-tools.deb libnetconf2-2.deb netopeer2_2.deb |
| 79 | |
| 80 | # Copy yang files and install them to sysrepo |
| 81 | COPY ./build/yang-files /yang |
Elia Battiston | e1cecb2 | 2022-03-21 10:05:25 +0100 | [diff] [blame^] | 82 | RUN for f in /yang/*.yang; do sysrepoctl -a -i "$f" -s /yang -p 664 -v3; done |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 83 | |
| 84 | # Add user for connecting to netopeer2-server through ssh |
| 85 | ARG NETCONF_USER=voltha |
| 86 | ARG NETCONF_PASSWORD=onf |
| 87 | |
| 88 | RUN useradd -rm -g netconf -u 1001 $NETCONF_USER |
| 89 | RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 90 | |
| 91 | # Set the working directory |
| 92 | WORKDIR /app |
| 93 | |
| 94 | # Copy required files |
| 95 | COPY --from=dev /app/bbf-adapter /app/bbf-adapter |
| 96 | |
| 97 | # Label image |
| 98 | ARG org_label_schema_version=unknown |
| 99 | ARG org_label_schema_vcs_url=unknown |
| 100 | ARG org_label_schema_vcs_ref=unknown |
| 101 | ARG org_label_schema_build_date=unknown |
| 102 | ARG org_opencord_vcs_commit_date=unknown |
| 103 | ARG org_opencord_vcs_dirty=unknown |
| 104 | |
| 105 | LABEL \ |
| 106 | org.label-schema.schema-version=1.0 \ |
| 107 | org.label-schema.name=voltha-northbound-bbf-adapter \ |
| 108 | org.label-schema.version=$org_label_schema_version \ |
| 109 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 110 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 111 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 112 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 113 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 114 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 115 | # running netopeer2-server as a standard user is not supported right now |
| 116 | # https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173 |