blob: 61fbe4f2018bb32ec5a02e520c4ba4a115377175 [file] [log] [blame]
pierventre59d88b52021-05-04 16:48:36 +02001# 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
18ARG JOBS=2
19ARG PROFILE=default
pierventre69db90c2022-05-06 23:06:20 +020020ARG TAG=11.0.13-11.52.13
21ARG JAVA_PATH=/usr/lib/jvm/zulu11
pierventre59d88b52021-05-04 16:48:36 +020022
23# First stage is the build environment.
24# zulu-openjdk images are based on Ubuntu.
25FROM azul/zulu-openjdk:${TAG} as builder
26
27# Define the profiler version to be used
28ARG ONOS_YOURKIT
29
30ENV BUILD_DEPS \
31 ca-certificates \
32 zip \
pierventre59d88b52021-05-04 16:48:36 +020033 python3 \
34 git \
35 bzip2 \
36 build-essential \
37 curl \
38 unzip
39RUN apt-get update && apt-get install -y ${BUILD_DEPS}
40
41# Install Bazelisk, which will download the version of bazel specified in
42# .bazelversion
pierventre5489c2f2022-05-06 19:01:27 +020043RUN curl -L -o bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64
pierventre59d88b52021-05-04 16:48:36 +020044RUN chmod +x bazelisk && mv bazelisk /usr/bin
45
46# Build-stage environment variables
47ENV ONOS_ROOT /src/onos
48ENV BUILD_NUMBER docker
49ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
50
51# Copy in the sources
52COPY . ${ONOS_ROOT}
53WORKDIR ${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
pierventre5489c2f2022-05-06 19:01:27 +020058# version. NOTE that WORKSPACE-docker file defines dockerjdk
pierventre59d88b52021-05-04 16:48:36 +020059ARG JOBS
60ARG JAVA_PATH
61ARG PROFILE
pierventre5489c2f2022-05-06 19:01:27 +020062RUN cat WORKSPACE-docker >> WORKSPACE && bazelisk build onos \
pierventre59d88b52021-05-04 16:48:36 +020063 --jobs ${JOBS} \
64 --verbose_failures \
pierventre5489c2f2022-05-06 19:01:27 +020065 --java_runtime_version=dockerjdk_11 \
66 --tool_java_runtime_version=dockerjdk_11 \
pierventre59d88b52021-05-04 16:48:36 +020067 --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.
71RUN mkdir /output
72RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
73# Get yourkit profiler and extract in the ONOS temp folder
74RUN 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.
80FROM azul/zulu-openjdk:${TAG}
81
82LABEL 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
90RUN apt-get update && apt-get install -y curl && \
91 rm -rf /var/lib/apt/lists/*
92
93# Install ONOS in /root/onos
94COPY --from=builder /output/ /root/onos/
95WORKDIR /root/onos
96
97# Set JAVA_HOME (by default not exported by zulu images)
98ARG JAVA_PATH
99ENV JAVA_HOME ${JAVA_PATH}
100# Set ONOS_YOURKIT to enable the profiler agent
101ENV 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
110EXPOSE 6653 6640 8181 8101 9876 10001-10010
111
112# Run ONOS
113ENTRYPOINT ["./bin/onos-service"]
114CMD ["server"]