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 |
| 23 | RUN 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 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 | |
| 85 | RUN 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 |
| 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 |
| 92 | COPY --from=dev /usr/local/lib64 /usr/local/lib64 |
| 93 | COPY --from=dev /usr/local/share /usr/local/share |
| 94 | COPY --from=dev /etc/sysrepo /etc/sysrepo |
| 95 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 96 | # Copy yang files and install them to sysrepo |
| 97 | COPY ./build/yang-files /yang |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame] | 98 | RUN for f in /yang/*.yang; do sysrepoctl -i "$f" -s /yang -p 664 -v3; done |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 99 | |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 100 | # Enable admin and oper state in ietf-hardware |
| 101 | RUN sysrepoctl -e hardware-state -c ietf-hardware |
| 102 | |
| 103 | COPY ./build/yang-files/schema-mount.xml / |
| 104 | |
| 105 | # Add sysrepo's yang library data to the data provided to the schema-mount libyang extension |
| 106 | RUN sysrepocfg -X -x/ietf-yang-library:* -d operational >> /schema-mount.xml |
| 107 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 108 | # Add user for connecting to netopeer2-server through ssh |
| 109 | ARG NETCONF_USER=voltha |
| 110 | ARG NETCONF_PASSWORD=onf |
| 111 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame] | 112 | RUN addgroup -S netconf |
| 113 | RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 114 | RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 115 | |
| 116 | # Set the working directory |
Elia Battiston | 589addb | 2022-04-04 16:40:01 +0200 | [diff] [blame] | 117 | WORKDIR / |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 118 | |
| 119 | # Copy required files |
| 120 | COPY --from=dev /app/bbf-adapter /app/bbf-adapter |
| 121 | |
| 122 | # Label image |
| 123 | ARG org_label_schema_version=unknown |
| 124 | ARG org_label_schema_vcs_url=unknown |
| 125 | ARG org_label_schema_vcs_ref=unknown |
| 126 | ARG org_label_schema_build_date=unknown |
| 127 | ARG org_opencord_vcs_commit_date=unknown |
| 128 | ARG org_opencord_vcs_dirty=unknown |
| 129 | |
| 130 | LABEL \ |
| 131 | org.label-schema.schema-version=1.0 \ |
| 132 | org.label-schema.name=voltha-northbound-bbf-adapter \ |
| 133 | org.label-schema.version=$org_label_schema_version \ |
| 134 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 135 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 136 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 137 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 138 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 139 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 140 | # running netopeer2-server as a standard user is not supported right now |
| 141 | # https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173 |