blob: af4e84e32415d0042cd0bdc31fd8262bda2a1dbb [file] [log] [blame]
Carmelo Casconef66f7792019-11-21 22:13:09 -08001ARG BAZEL_VER=1.0.0
Carmelo Casconed33d3b42019-06-18 12:12:36 -07002ARG JOBS=2
Jonathan Hartbdf39a72020-02-25 13:53:23 -08003ARG PROFILE=default
pierventre45172a92020-07-23 18:36:29 +02004ARG TAG=11.0.8-11.41.23
5ARG JAVA_PATH=/usr/lib/jvm/zulu11-ca-amd64
alshabib187f1722015-06-23 16:15:50 -07006
Carmelo Casconed33d3b42019-06-18 12:12:36 -07007# First stage is the build environment.
Carmelo Casconee5b1d252019-06-26 15:56:51 -07008# zulu-openjdk images are based on Ubuntu.
pierventre45172a92020-07-23 18:36:29 +02009FROM azul/zulu-openjdk:${TAG} as builder
Carmelo Casconed33d3b42019-06-18 12:12:36 -070010
11ENV BUILD_DEPS \
12 ca-certificates \
13 zip \
14 python \
15 python3 \
16 git \
17 bzip2 \
18 build-essential \
19 curl \
Brian O'Connorbae733a2019-10-11 00:52:36 +000020 unzip
Carmelo Casconee5b1d252019-06-26 15:56:51 -070021RUN apt-get update && apt-get install -y ${BUILD_DEPS}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070022
23# Install Bazel
24ARG BAZEL_VER
25RUN curl -L -o bazel.sh https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VER}/bazel-${BAZEL_VER}-installer-linux-x86_64.sh
Carmelo Casconee5b1d252019-06-26 15:56:51 -070026RUN chmod +x bazel.sh && ./bazel.sh
Carmelo Casconed33d3b42019-06-18 12:12:36 -070027
28# Build-stage environment variables
Carmelo Casconee5b1d252019-06-26 15:56:51 -070029ENV ONOS_ROOT /src/onos
alshabib187f1722015-06-23 16:15:50 -070030ENV BUILD_NUMBER docker
Ray Milkey8c05c9b2017-03-15 15:47:57 -070031ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Jonathan Hart809edee2016-12-15 18:33:05 -080032
Carmelo Casconed33d3b42019-06-18 12:12:36 -070033# Copy in the sources
34COPY . ${ONOS_ROOT}
35WORKDIR ${ONOS_ROOT}
Jonathan Hart15a71d82017-07-20 16:14:21 -070036
Carmelo Casconee5b1d252019-06-26 15:56:51 -070037# Build ONOS using the JDK pre-installed in the base image, instead of the
38# Bazel-provided remote one. By doing wo we make sure to build with the most
39# updated JDK, including bug and security fixes, independently of the Bazel
40# version.
Carmelo Casconed33d3b42019-06-18 12:12:36 -070041ARG JOBS
pierventre45172a92020-07-23 18:36:29 +020042ARG JAVA_PATH
Jonathan Hartbdf39a72020-02-25 13:53:23 -080043ARG PROFILE
Carmelo Casconee5b1d252019-06-26 15:56:51 -070044RUN bazel build onos \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070045 --jobs ${JOBS} \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070046 --verbose_failures \
47 --javabase=@bazel_tools//tools/jdk:absolute_javabase \
48 --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
pierventre45172a92020-07-23 18:36:29 +020049 --define=ABSOLUTE_JAVABASE=${JAVA_PATH} \
Jonathan Hartbdf39a72020-02-25 13:53:23 -080050 --define profile=${PROFILE}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070051
Carmelo Casconee5b1d252019-06-26 15:56:51 -070052# We extract the tar in the build environment to avoid having to put the tar in
53# the runtime stage. This saves a lot of space.
54RUN mkdir /output
55RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070056
Carmelo Casconee5b1d252019-06-26 15:56:51 -070057# Second and final stage is the runtime environment.
pierventre45172a92020-07-23 18:36:29 +020058FROM azul/zulu-openjdk:${TAG}
Jonathan Hart3e864192017-07-20 19:24:49 -070059
Jonathan Hart15a71d82017-07-20 16:14:21 -070060LABEL org.label-schema.name="ONOS" \
61 org.label-schema.description="SDN Controller" \
62 org.label-schema.usage="http://wiki.onosproject.org" \
63 org.label-schema.url="http://onosproject.org" \
64 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070065 org.label-schema.schema-version="1.0" \
66 maintainer="onos-dev@onosproject.org"
67
Jonathan Hart91f3cb62019-12-02 13:19:35 -080068RUN apt-get update && apt-get install -y curl && \
69 rm -rf /var/lib/apt/lists/*
70
Carmelo Casconee5b1d252019-06-26 15:56:51 -070071# Install ONOS in /root/onos
72COPY --from=builder /output/ /root/onos/
73WORKDIR /root/onos
74
75# Set JAVA_HOME (by default not exported by zulu images)
pierventre45172a92020-07-23 18:36:29 +020076ARG JAVA_PATH
77ENV JAVA_HOME ${JAVA_PATH}
alshabib187f1722015-06-23 16:15:50 -070078
79# Ports
Charles Chan45624b82015-08-24 00:29:20 +080080# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080081# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070082# 8181 - GUI
83# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070084# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080085EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -070086
Carmelo Casconee5b1d252019-06-26 15:56:51 -070087# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -070088ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -070089CMD ["server"]