blob: 6a168c57aa82326f0a8b5f26e4e5b1e37955ac92 [file] [log] [blame]
pierventre846c8b12022-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
pierventrecf38ba32022-05-06 23:06:20 +020019ARG TAG=11.0.13-11.52.13
20ARG JAVA_PATH=/usr/lib/jvm/zulu11
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 \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070029 python3 \
30 git \
31 bzip2 \
32 build-essential \
33 curl \
Brian O'Connorbae733a2019-10-11 00:52:36 +000034 unzip
Carmelo Casconee5b1d252019-06-26 15:56:51 -070035RUN apt-get update && apt-get install -y ${BUILD_DEPS}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070036
Carmelo Cascone5c2807c2020-08-03 01:12:10 -070037# Install Bazelisk, which will download the version of bazel specified in
38# .bazelversion
pierventre846c8b12022-05-06 19:01:27 +020039RUN curl -L -o bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64
Carmelo Cascone5c2807c2020-08-03 01:12:10 -070040RUN chmod +x bazelisk && mv bazelisk /usr/bin
Carmelo Casconed33d3b42019-06-18 12:12:36 -070041
42# Build-stage environment variables
Carmelo Casconee5b1d252019-06-26 15:56:51 -070043ENV ONOS_ROOT /src/onos
alshabib187f1722015-06-23 16:15:50 -070044ENV BUILD_NUMBER docker
Ray Milkey8c05c9b2017-03-15 15:47:57 -070045ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Jonathan Hart809edee2016-12-15 18:33:05 -080046
Carmelo Casconed33d3b42019-06-18 12:12:36 -070047# Copy in the sources
48COPY . ${ONOS_ROOT}
49WORKDIR ${ONOS_ROOT}
Jonathan Hart15a71d82017-07-20 16:14:21 -070050
Carmelo Casconee5b1d252019-06-26 15:56:51 -070051# Build ONOS using the JDK pre-installed in the base image, instead of the
52# Bazel-provided remote one. By doing wo we make sure to build with the most
53# updated JDK, including bug and security fixes, independently of the Bazel
pierventre846c8b12022-05-06 19:01:27 +020054# version. NOTE that WORKSPACE-docker file defines dockerjdk
Carmelo Casconed33d3b42019-06-18 12:12:36 -070055ARG JOBS
pierventre3883c602020-07-23 18:36:29 +020056ARG JAVA_PATH
Jonathan Hartbdf39a72020-02-25 13:53:23 -080057ARG PROFILE
pierventre846c8b12022-05-06 19:01:27 +020058RUN cat WORKSPACE-docker >> WORKSPACE && bazelisk build onos \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070059 --jobs ${JOBS} \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070060 --verbose_failures \
pierventre846c8b12022-05-06 19:01:27 +020061 --java_runtime_version=dockerjdk_11 \
62 --tool_java_runtime_version=dockerjdk_11 \
Jonathan Hartbdf39a72020-02-25 13:53:23 -080063 --define profile=${PROFILE}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070064
Carmelo Casconee5b1d252019-06-26 15:56:51 -070065# We extract the tar in the build environment to avoid having to put the tar in
66# the runtime stage. This saves a lot of space.
67RUN mkdir /output
68RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070069
Carmelo Casconee5b1d252019-06-26 15:56:51 -070070# Second and final stage is the runtime environment.
pierventre3883c602020-07-23 18:36:29 +020071FROM azul/zulu-openjdk:${TAG}
Jonathan Hart3e864192017-07-20 19:24:49 -070072
Jonathan Hart15a71d82017-07-20 16:14:21 -070073LABEL org.label-schema.name="ONOS" \
74 org.label-schema.description="SDN Controller" \
75 org.label-schema.usage="http://wiki.onosproject.org" \
76 org.label-schema.url="http://onosproject.org" \
77 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070078 org.label-schema.schema-version="1.0" \
79 maintainer="onos-dev@onosproject.org"
80
Jonathan Hart91f3cb62019-12-02 13:19:35 -080081RUN apt-get update && apt-get install -y curl && \
82 rm -rf /var/lib/apt/lists/*
83
Carmelo Casconee5b1d252019-06-26 15:56:51 -070084# Install ONOS in /root/onos
85COPY --from=builder /output/ /root/onos/
86WORKDIR /root/onos
87
88# Set JAVA_HOME (by default not exported by zulu images)
pierventre3883c602020-07-23 18:36:29 +020089ARG JAVA_PATH
90ENV JAVA_HOME ${JAVA_PATH}
alshabib187f1722015-06-23 16:15:50 -070091
92# Ports
Charles Chan45624b82015-08-24 00:29:20 +080093# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080094# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070095# 8181 - GUI
96# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070097# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080098EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -070099
Carmelo Casconee5b1d252019-06-26 15:56:51 -0700100# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -0700101ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -0700102CMD ["server"]