blob: 47c1897843686063a24929f6d073a00e7cfbfabc [file] [log] [blame]
Carmelo Casconed33d3b42019-06-18 12:12:36 -07001ARG JDK_VER=11
Carmelo Casconef66f7792019-11-21 22:13:09 -08002ARG BAZEL_VER=1.0.0
Carmelo Casconed33d3b42019-06-18 12:12:36 -07003ARG JOBS=2
alshabib187f1722015-06-23 16:15:50 -07004
Carmelo Casconed33d3b42019-06-18 12:12:36 -07005# First stage is the build environment.
Carmelo Casconee5b1d252019-06-26 15:56:51 -07006# zulu-openjdk images are based on Ubuntu.
7FROM azul/zulu-openjdk:${JDK_VER} as builder
Carmelo Casconed33d3b42019-06-18 12:12:36 -07008
9ENV BUILD_DEPS \
10 ca-certificates \
11 zip \
12 python \
13 python3 \
14 git \
15 bzip2 \
16 build-essential \
17 curl \
Brian O'Connorbae733a2019-10-11 00:52:36 +000018 unzip
Carmelo Casconee5b1d252019-06-26 15:56:51 -070019RUN apt-get update && apt-get install -y ${BUILD_DEPS}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070020
21# Install Bazel
22ARG BAZEL_VER
23RUN 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 -070024RUN chmod +x bazel.sh && ./bazel.sh
Carmelo Casconed33d3b42019-06-18 12:12:36 -070025
26# Build-stage environment variables
Carmelo Casconee5b1d252019-06-26 15:56:51 -070027ENV ONOS_ROOT /src/onos
alshabib187f1722015-06-23 16:15:50 -070028ENV BUILD_NUMBER docker
Ray Milkey8c05c9b2017-03-15 15:47:57 -070029ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Jonathan Hart809edee2016-12-15 18:33:05 -080030
Carmelo Casconed33d3b42019-06-18 12:12:36 -070031# Copy in the sources
32COPY . ${ONOS_ROOT}
33WORKDIR ${ONOS_ROOT}
Jonathan Hart15a71d82017-07-20 16:14:21 -070034
Carmelo Casconee5b1d252019-06-26 15:56:51 -070035# Build ONOS using the JDK pre-installed in the base image, instead of the
36# Bazel-provided remote one. By doing wo we make sure to build with the most
37# updated JDK, including bug and security fixes, independently of the Bazel
38# version.
Carmelo Casconed33d3b42019-06-18 12:12:36 -070039ARG JOBS
Carmelo Casconee5b1d252019-06-26 15:56:51 -070040ARG JDK_VER
41RUN bazel build onos \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070042 --jobs ${JOBS} \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070043 --verbose_failures \
44 --javabase=@bazel_tools//tools/jdk:absolute_javabase \
45 --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
46 --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/zulu-${JDK_VER}-amd64
Carmelo Casconed33d3b42019-06-18 12:12:36 -070047
Carmelo Casconee5b1d252019-06-26 15:56:51 -070048# We extract the tar in the build environment to avoid having to put the tar in
49# the runtime stage. This saves a lot of space.
50RUN mkdir /output
51RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070052
Carmelo Casconee5b1d252019-06-26 15:56:51 -070053# Second and final stage is the runtime environment.
54FROM azul/zulu-openjdk:${JDK_VER}
Jonathan Hart3e864192017-07-20 19:24:49 -070055
Jonathan Hart15a71d82017-07-20 16:14:21 -070056LABEL org.label-schema.name="ONOS" \
57 org.label-schema.description="SDN Controller" \
58 org.label-schema.usage="http://wiki.onosproject.org" \
59 org.label-schema.url="http://onosproject.org" \
60 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070061 org.label-schema.schema-version="1.0" \
62 maintainer="onos-dev@onosproject.org"
63
64# Install ONOS in /root/onos
65COPY --from=builder /output/ /root/onos/
66WORKDIR /root/onos
67
68# Set JAVA_HOME (by default not exported by zulu images)
69ARG JDK_VER
70ENV JAVA_HOME /usr/lib/jvm/zulu-${JDK_VER}-amd64
alshabib187f1722015-06-23 16:15:50 -070071
72# Ports
Charles Chan45624b82015-08-24 00:29:20 +080073# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080074# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070075# 8181 - GUI
76# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070077# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080078EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -070079
Carmelo Casconee5b1d252019-06-26 15:56:51 -070080# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -070081ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -070082CMD ["server"]