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 | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 38 | SHELL ["/bin/ash", "-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 | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 55 | FROM alpine:3.13 AS prod |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 56 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 57 | SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 58 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 59 | RUN 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 Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 60 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 61 | RUN rm -r /usr/local/lib && ln -s /usr/local/lib64 /usr/local/lib |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 62 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 63 | WORKDIR / |
| 64 | |
| 65 | COPY --from=dev /libyang /libyang |
| 66 | COPY --from=dev /sysrepo /sysrepo |
| 67 | |
| 68 | #Build libyang |
| 69 | WORKDIR /libyang/build |
| 70 | RUN make install && \ |
| 71 | rm -rf libyang |
| 72 | |
| 73 | #Build sysrepo |
| 74 | WORKDIR /sysrepo/build |
| 75 | RUN make install && \ |
| 76 | rm -rf sysrepo |
| 77 | |
| 78 | ARG LIBNETCONF2_VERSION |
| 79 | ARG NETOPEER2_VERSION |
| 80 | |
| 81 | #Build libnetconf2 |
| 82 | WORKDIR / |
| 83 | RUN git clone https://github.com/CESNET/libnetconf2.git |
| 84 | WORKDIR /libnetconf2 |
| 85 | RUN git checkout $LIBNETCONF2_VERSION && mkdir build |
| 86 | WORKDIR /libnetconf2/build |
| 87 | RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \ |
| 88 | make && \ |
| 89 | make install && \ |
| 90 | rm -rf libnetconf2 |
| 91 | |
| 92 | #Build netopeer2 |
| 93 | WORKDIR / |
| 94 | RUN git clone https://github.com/CESNET/netopeer2.git |
| 95 | WORKDIR /netopeer2 |
| 96 | RUN git checkout $NETOPEER2_VERSION && mkdir build |
| 97 | WORKDIR /netopeer2/build |
| 98 | RUN cmake -D CMAKE_BUILD_TYPE:String="Release" .. && \ |
| 99 | make && \ |
| 100 | make install && \ |
| 101 | rm -rf netopeer2 |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 102 | |
| 103 | # Copy yang files and install them to sysrepo |
| 104 | COPY ./build/yang-files /yang |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 105 | 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] | 106 | |
| 107 | # Add user for connecting to netopeer2-server through ssh |
| 108 | ARG NETCONF_USER=voltha |
| 109 | ARG NETCONF_PASSWORD=onf |
| 110 | |
Elia Battiston | b244bb5 | 2022-03-24 15:47:16 +0100 | [diff] [blame^] | 111 | RUN addgroup -S netconf |
| 112 | RUN adduser $NETCONF_USER --uid 1001 -G netconf --disabled-password |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 113 | RUN echo $NETCONF_USER:$NETCONF_PASSWORD | chpasswd |
Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 114 | |
| 115 | # Set the working directory |
| 116 | WORKDIR /app |
| 117 | |
| 118 | # Copy required files |
| 119 | COPY --from=dev /app/bbf-adapter /app/bbf-adapter |
| 120 | |
| 121 | # Label image |
| 122 | ARG org_label_schema_version=unknown |
| 123 | ARG org_label_schema_vcs_url=unknown |
| 124 | ARG org_label_schema_vcs_ref=unknown |
| 125 | ARG org_label_schema_build_date=unknown |
| 126 | ARG org_opencord_vcs_commit_date=unknown |
| 127 | ARG org_opencord_vcs_dirty=unknown |
| 128 | |
| 129 | LABEL \ |
| 130 | org.label-schema.schema-version=1.0 \ |
| 131 | org.label-schema.name=voltha-northbound-bbf-adapter \ |
| 132 | org.label-schema.version=$org_label_schema_version \ |
| 133 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 134 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 135 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 136 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 137 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 138 | |
Elia Battiston | ac8d23f | 2022-03-14 17:54:56 +0100 | [diff] [blame] | 139 | # running netopeer2-server as a standard user is not supported right now |
| 140 | # https://github.com/sysrepo/sysrepo/issues/2148#issuecomment-695950173 |