blob: 6a9350338132057d0473587ed14873d9afc97d31 [file] [log] [blame]
Carmelo Casconed33d3b42019-06-18 12:12:36 -07001ARG JDK_VER=11
2ARG BAZEL_VER=0.27.0
3ARG 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'Connorea8cb752019-10-09 17:39:28 -070018 unzip \
19 iproute2
20
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
Carmelo Casconee5b1d252019-06-26 15:56:51 -070042ARG JDK_VER
43RUN bazel build onos \
Carmelo Casconed33d3b42019-06-18 12:12:36 -070044 --jobs ${JOBS} \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070045 --verbose_failures \
46 --javabase=@bazel_tools//tools/jdk:absolute_javabase \
47 --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
48 --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/zulu-${JDK_VER}-amd64
Carmelo Casconed33d3b42019-06-18 12:12:36 -070049
Carmelo Casconee5b1d252019-06-26 15:56:51 -070050# We extract the tar in the build environment to avoid having to put the tar in
51# the runtime stage. This saves a lot of space.
52RUN mkdir /output
53RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070054
Carmelo Casconee5b1d252019-06-26 15:56:51 -070055# Second and final stage is the runtime environment.
56FROM azul/zulu-openjdk:${JDK_VER}
Jonathan Hart3e864192017-07-20 19:24:49 -070057
Jonathan Hart15a71d82017-07-20 16:14:21 -070058LABEL org.label-schema.name="ONOS" \
59 org.label-schema.description="SDN Controller" \
60 org.label-schema.usage="http://wiki.onosproject.org" \
61 org.label-schema.url="http://onosproject.org" \
62 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070063 org.label-schema.schema-version="1.0" \
64 maintainer="onos-dev@onosproject.org"
65
66# Install ONOS in /root/onos
67COPY --from=builder /output/ /root/onos/
68WORKDIR /root/onos
69
Brian O'Connorea8cb752019-10-09 17:39:28 -070070# Add ip command
71COPY --from=builder /bin/ip /bin/
72COPY --from=builder /lib/x86_64-linux-gnu/libmnl.so* /lib/x86_64-linux-gnu/
73COPY --from=builder /usr/lib/x86_64-linux-gnu/libelf.so* /lib/x86_64-linux-gnu/
74COPY --from=builder /sbin/ip /sbin/
75RUN ldconfig
76
Carmelo Casconee5b1d252019-06-26 15:56:51 -070077# Set JAVA_HOME (by default not exported by zulu images)
78ARG JDK_VER
79ENV JAVA_HOME /usr/lib/jvm/zulu-${JDK_VER}-amd64
alshabib187f1722015-06-23 16:15:50 -070080
81# Ports
Charles Chan45624b82015-08-24 00:29:20 +080082# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080083# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070084# 8181 - GUI
85# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070086# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080087EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -070088
Carmelo Casconee5b1d252019-06-26 15:56:51 -070089# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -070090ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -070091CMD ["server"]