blob: 129e7cfa0b1442fa1132bbe9bbb8ed7e98aeb80f [file] [log] [blame]
pierventree6e95e72022-05-06 19:01:27 +02001# Copyright 2015-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
Carmelo Casconed33d3b42019-06-18 12:12:36 -070017ARG JOBS=2
Jonathan Hartbdf39a72020-02-25 13:53:23 -080018ARG PROFILE=default
pierventre3883c602020-07-23 18:36:29 +020019ARG TAG=11.0.8-11.41.23
20ARG JAVA_PATH=/usr/lib/jvm/zulu11-ca-amd64
alshabib187f1722015-06-23 16:15:50 -070021
Carmelo Casconed33d3b42019-06-18 12:12:36 -070022# First stage is the build environment.
Carmelo Casconee5b1d252019-06-26 15:56:51 -070023# zulu-openjdk images are based on Ubuntu.
pierventre3883c602020-07-23 18:36:29 +020024FROM azul/zulu-openjdk:${TAG} as builder
Carmelo Casconed33d3b42019-06-18 12:12:36 -070025
26ENV BUILD_DEPS \
27 ca-certificates \
28 zip \
29 python \
30 python3 \
31 git \
32 bzip2 \
33 build-essential \
34 curl \
Brian O'Connorbae733a2019-10-11 00:52:36 +000035 unzip
Carmelo Casconee5b1d252019-06-26 15:56:51 -070036RUN apt-get update && apt-get install -y ${BUILD_DEPS}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070037
Carmelo Cascone5c2807c2020-08-03 01:12:10 -070038# Install Bazelisk, which will download the version of bazel specified in
39# .bazelversion
pierventree6e95e72022-05-06 19:01:27 +020040RUN curl -L -o bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64
Carmelo Cascone5c2807c2020-08-03 01:12:10 -070041RUN chmod +x bazelisk && mv bazelisk /usr/bin
Carmelo Casconed33d3b42019-06-18 12:12:36 -070042
43# Build-stage environment variables
Carmelo Casconee5b1d252019-06-26 15:56:51 -070044ENV ONOS_ROOT /src/onos
alshabib187f1722015-06-23 16:15:50 -070045ENV BUILD_NUMBER docker
Ray Milkey8c05c9b2017-03-15 15:47:57 -070046ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Jonathan Hart809edee2016-12-15 18:33:05 -080047
Carmelo Casconed33d3b42019-06-18 12:12:36 -070048# Copy in the sources
49COPY . ${ONOS_ROOT}
50WORKDIR ${ONOS_ROOT}
Jonathan Hart15a71d82017-07-20 16:14:21 -070051
Carmelo Casconee5b1d252019-06-26 15:56:51 -070052# Build ONOS using the JDK pre-installed in the base image, instead of the
53# Bazel-provided remote one. By doing wo we make sure to build with the most
54# updated JDK, including bug and security fixes, independently of the Bazel
pierventree6e95e72022-05-06 19:01:27 +020055# version. NOTE that WORKSPACE-docker file defines dockerjdk
Carmelo Casconed33d3b42019-06-18 12:12:36 -070056ARG JOBS
pierventre3883c602020-07-23 18:36:29 +020057ARG JAVA_PATH
Jonathan Hartbdf39a72020-02-25 13:53:23 -080058ARG PROFILE
pierventree6e95e72022-05-06 19:01:27 +020059RUN cat WORKSPACE-docker >> WORKSPACE && bazelisk build onos \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070060 --jobs ${JOBS} \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070061 --verbose_failures \
pierventree6e95e72022-05-06 19:01:27 +020062 --java_runtime_version=dockerjdk_11 \
63 --tool_java_runtime_version=dockerjdk_11 \
Jonathan Hartbdf39a72020-02-25 13:53:23 -080064 --define profile=${PROFILE}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070065
Carmelo Casconee5b1d252019-06-26 15:56:51 -070066# We extract the tar in the build environment to avoid having to put the tar in
67# the runtime stage. This saves a lot of space.
68RUN mkdir /output
69RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070070
Carmelo Casconee5b1d252019-06-26 15:56:51 -070071# Second and final stage is the runtime environment.
pierventre3883c602020-07-23 18:36:29 +020072FROM azul/zulu-openjdk:${TAG}
Jonathan Hart3e864192017-07-20 19:24:49 -070073
Jonathan Hart15a71d82017-07-20 16:14:21 -070074LABEL org.label-schema.name="ONOS" \
75 org.label-schema.description="SDN Controller" \
76 org.label-schema.usage="http://wiki.onosproject.org" \
77 org.label-schema.url="http://onosproject.org" \
78 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070079 org.label-schema.schema-version="1.0" \
80 maintainer="onos-dev@onosproject.org"
81
Jonathan Hart91f3cb62019-12-02 13:19:35 -080082RUN apt-get update && apt-get install -y curl && \
83 rm -rf /var/lib/apt/lists/*
84
Carmelo Casconee5b1d252019-06-26 15:56:51 -070085# Install ONOS in /root/onos
86COPY --from=builder /output/ /root/onos/
87WORKDIR /root/onos
88
89# Set JAVA_HOME (by default not exported by zulu images)
pierventre3883c602020-07-23 18:36:29 +020090ARG JAVA_PATH
91ENV JAVA_HOME ${JAVA_PATH}
alshabib187f1722015-06-23 16:15:50 -070092
93# Ports
Charles Chan45624b82015-08-24 00:29:20 +080094# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080095# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070096# 8181 - GUI
97# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070098# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080099EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -0700100
Carmelo Casconee5b1d252019-06-26 15:56:51 -0700101# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -0700102ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -0700103CMD ["server"]