pierventre | 59d88b5 | 2021-05-04 16:48:36 +0200 | [diff] [blame] | 1 | # Copyright 2021-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 | # With this dockerfile you can build a ONOS Docker container |
| 16 | # with YourKit profiler agent enabled |
| 17 | |
| 18 | ARG JOBS=2 |
| 19 | ARG PROFILE=default |
| 20 | ARG TAG=11.0.8-11.41.23 |
| 21 | ARG JAVA_PATH=/usr/lib/jvm/zulu11-ca-amd64 |
| 22 | |
| 23 | # First stage is the build environment. |
| 24 | # zulu-openjdk images are based on Ubuntu. |
| 25 | FROM azul/zulu-openjdk:${TAG} as builder |
| 26 | |
| 27 | # Define the profiler version to be used |
| 28 | ARG ONOS_YOURKIT |
| 29 | |
| 30 | ENV BUILD_DEPS \ |
| 31 | ca-certificates \ |
| 32 | zip \ |
| 33 | python \ |
| 34 | python3 \ |
| 35 | git \ |
| 36 | bzip2 \ |
| 37 | build-essential \ |
| 38 | curl \ |
| 39 | unzip |
| 40 | RUN apt-get update && apt-get install -y ${BUILD_DEPS} |
| 41 | |
| 42 | # Install Bazelisk, which will download the version of bazel specified in |
| 43 | # .bazelversion |
| 44 | RUN curl -L -o bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.5.0/bazelisk-linux-amd64 |
| 45 | RUN chmod +x bazelisk && mv bazelisk /usr/bin |
| 46 | |
| 47 | # Build-stage environment variables |
| 48 | ENV ONOS_ROOT /src/onos |
| 49 | ENV BUILD_NUMBER docker |
| 50 | ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 |
| 51 | |
| 52 | # Copy in the sources |
| 53 | COPY . ${ONOS_ROOT} |
| 54 | WORKDIR ${ONOS_ROOT} |
| 55 | |
| 56 | # Build ONOS using the JDK pre-installed in the base image, instead of the |
| 57 | # Bazel-provided remote one. By doing wo we make sure to build with the most |
| 58 | # updated JDK, including bug and security fixes, independently of the Bazel |
| 59 | # version. |
| 60 | ARG JOBS |
| 61 | ARG JAVA_PATH |
| 62 | ARG PROFILE |
| 63 | RUN bazelisk build onos \ |
| 64 | --jobs ${JOBS} \ |
| 65 | --verbose_failures \ |
| 66 | --javabase=@bazel_tools//tools/jdk:absolute_javabase \ |
| 67 | --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ |
| 68 | --define=ABSOLUTE_JAVABASE=${JAVA_PATH} \ |
| 69 | --define profile=${PROFILE} |
| 70 | |
| 71 | # We extract the tar in the build environment to avoid having to put the tar in |
| 72 | # the runtime stage. This saves a lot of space. |
| 73 | RUN mkdir /output |
| 74 | RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1 |
| 75 | # Get yourkit profiler and extract in the ONOS temp folder |
| 76 | RUN curl -L -o yourkit.zip https://www.yourkit.com/download/YourKit-JavaProfiler-$ONOS_YOURKIT.zip && \ |
| 77 | unzip -o yourkit.zip && \ |
| 78 | rm yourkit.zip && \ |
| 79 | mv YourKit-JavaProfiler-$(echo $ONOS_YOURKIT | sed 's/\(.*\)-.*/\1/')/bin/linux-x86-64/libyjpagent.so /output/libyjpagent.so |
| 80 | |
| 81 | # Second and final stage is the runtime environment. |
| 82 | FROM azul/zulu-openjdk:${TAG} |
| 83 | |
| 84 | LABEL org.label-schema.name="ONOS" \ |
| 85 | org.label-schema.description="SDN Controller" \ |
| 86 | org.label-schema.usage="http://wiki.onosproject.org" \ |
| 87 | org.label-schema.url="http://onosproject.org" \ |
| 88 | org.label-scheme.vendor="Open Networking Foundation" \ |
| 89 | org.label-schema.schema-version="1.0" \ |
| 90 | maintainer="onos-dev@onosproject.org" |
| 91 | |
| 92 | RUN apt-get update && apt-get install -y curl && \ |
| 93 | rm -rf /var/lib/apt/lists/* |
| 94 | |
| 95 | # Install ONOS in /root/onos |
| 96 | COPY --from=builder /output/ /root/onos/ |
| 97 | WORKDIR /root/onos |
| 98 | |
| 99 | # Set JAVA_HOME (by default not exported by zulu images) |
| 100 | ARG JAVA_PATH |
| 101 | ENV JAVA_HOME ${JAVA_PATH} |
| 102 | # Set ONOS_YOURKIT to enable the profiler agent |
| 103 | ENV ONOS_YOURKIT true |
| 104 | |
| 105 | # Ports |
| 106 | # 6653 - OpenFlow |
| 107 | # 6640 - OVSDB |
| 108 | # 8181 - GUI |
| 109 | # 8101 - ONOS CLI |
| 110 | # 9876 - ONOS intra-cluster communication |
| 111 | # 10001-10010 - YourKit profiler |
| 112 | EXPOSE 6653 6640 8181 8101 9876 10001-10010 |
| 113 | |
| 114 | # Run ONOS |
| 115 | ENTRYPOINT ["./bin/onos-service"] |
| 116 | CMD ["server"] |