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 | |
Elia Battiston | f9e12e6 | 2022-04-01 12:45:37 +0200 | [diff] [blame] | 22 | #Build runtime dependencies |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 23 | RUN 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 Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame] | 24 | |
| 25 | ARG LIBNETCONF2_VERSION |
| 26 | ARG NETOPEER2_VERSION |
| 27 | |
| 28 | #Build libnetconf2 |
| 29 | WORKDIR / |
| 30 | RUN git clone https://github.com/CESNET/libnetconf2.git |
| 31 | WORKDIR /libnetconf2 |
| 32 | RUN git checkout $LIBNETCONF2_VERSION && mkdir build |
| 33 | WORKDIR /libnetconf2/build |
| 34 | RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \ |
| 35 | make && \ |
| 36 | make install && \ |
| 37 | rm -rf libnetconf2 |
| 38 | |
| 39 | #Build netopeer2 |
| 40 | WORKDIR / |
| 41 | RUN git clone https://github.com/CESNET/netopeer2.git |
| 42 | WORKDIR /netopeer2 |
| 43 | RUN git checkout $NETOPEER2_VERSION && mkdir build |
| 44 | WORKDIR /netopeer2/build |
| 45 | RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \ |
| 46 | make && \ |
| 47 | make install && \ |
| 48 | rm -rf netopeer2 |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 49 | |
Elia Battiston | f9e12e6 | 2022-04-01 12:45:37 +0200 | [diff] [blame] | 50 | # Use Standard go build directory structure |
| 51 | WORKDIR /go/src |
| 52 | COPY . . |
| 53 | |
| 54 | ARG EXTRA_GO_BUILD_TAGS="" |
| 55 | |
| 56 | ARG CGO_PARAMETER=1 |
| 57 | |
| 58 | ARG org_label_schema_version=unknown |
| 59 | ARG org_label_schema_vcs_url=unknown |
| 60 | ARG org_label_schema_vcs_ref=unknown |
| 61 | ARG org_label_schema_build_date=unknown |
| 62 | ARG org_opencord_vcs_commit_date=unknown |
| 63 | ARG org_opencord_vcs_dirty=unknown |
| 64 | |
| 65 | # Build bbf-adapter |
| 66 | SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
| 67 | RUN \ |
| 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 |
| 81 | FROM alpine:3.13 AS prod |
| 82 | |
| 83 | SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
| 84 | |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 85 | RUN apk add --no-cache pcre2=10.36-r1 libssh=0.9.5-r0 openssl=1.1.1q-r0 |
Elia Battiston | f9e12e6 | 2022-04-01 12:45:37 +0200 | [diff] [blame] | 86 | |
| 87 | # Dependencies install their library files in lib64, add it to the path |
| 88 | RUN echo "/lib:/usr/local/lib:/usr/lib:/usr/local/lib64" > /etc/ld-musl-x86_64.path |
| 89 | |
| 90 | # Copy dependencies files |
| 91 | COPY --from=dev /usr/local/bin /usr/local/bin |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 92 | COPY --from=dev /usr/local/sbin /usr/local/sbin |
Elia Battiston | f9e12e6 | 2022-04-01 12:45:37 +0200 | [diff] [blame] | 93 | COPY --from=dev /usr/local/lib64 /usr/local/lib64 |
| 94 | COPY --from=dev /usr/local/share /usr/local/share |
| 95 | COPY --from=dev /etc/sysrepo /etc/sysrepo |
| 96 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 97 | # Add user for connecting to netopeer2-server through ssh |
| 98 | ARG NETCONF_USER=voltha |
| 99 | ARG NETCONF_PASSWORD=onf |
| 100 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame] | 101 | RUN addgroup -S netconf |
| 102 | RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 103 | RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 104 | |
Elia Battiston | 4750d3c | 2022-07-14 13:24:56 +0000 | [diff] [blame^] | 105 | # Copy yang files and install them to sysrepo |
| 106 | COPY ./build/yang-files /yang |
| 107 | RUN for f in /yang/*.yang; do sysrepoctl -i "$f" -s /yang -o $NETCONF_USER -g netconf -p 664 -v3; done |
| 108 | RUN for f in /yang/*/*.yang; do sysrepoctl -i "$f" -s /yang -o $NETCONF_USER -g netconf -p 664 -v3; done |
| 109 | |
| 110 | COPY ./build/config /config |
| 111 | # Disable nacm to test edit-config easily |
| 112 | RUN sysrepocfg --import=/config/nacm.xml -d startup -m ietf-netconf-acm |
| 113 | RUN sysrepocfg --import=/config/nacm.xml -d running -m ietf-netconf-acm |
| 114 | RUN sysrepocfg --import=/config/nacm.xml -d candidate -m ietf-netconf-acm |
| 115 | |
| 116 | # Enable admin and oper state in ietf-hardware |
| 117 | RUN sysrepoctl -e hardware-state -c ietf-hardware -v3 |
| 118 | |
| 119 | COPY ./build/yang-files/schema-mount.xml / |
| 120 | |
| 121 | # Add sysrepo's yang library data to the data provided to the schema-mount libyang extension |
| 122 | RUN sysrepocfg -X -x/ietf-yang-library:* -d operational >> /schema-mount.xml |
| 123 | |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 124 | # Set the working directory |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 125 | WORKDIR / |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 126 | |
| 127 | # Copy required files |
| 128 | COPY --from=dev /app/bbf-adapter /app/bbf-adapter |
| 129 | |
| 130 | # Label image |
| 131 | ARG org_label_schema_version=unknown |
| 132 | ARG org_label_schema_vcs_url=unknown |
| 133 | ARG org_label_schema_vcs_ref=unknown |
| 134 | ARG org_label_schema_build_date=unknown |
| 135 | ARG org_opencord_vcs_commit_date=unknown |
| 136 | ARG org_opencord_vcs_dirty=unknown |
| 137 | |
| 138 | LABEL \ |
| 139 | org.label-schema.schema-version=1.0 \ |
| 140 | org.label-schema.name=voltha-northbound-bbf-adapter \ |
| 141 | org.label-schema.version=$org_label_schema_version \ |
| 142 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 143 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 144 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 145 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 146 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 147 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 148 | # running netopeer2-server as a standard user is not supported right now |
| 149 | # https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173 |