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