Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 1 | ARG JDK_VER=11 |
| 2 | ARG BAZEL_VER=0.27.0 |
| 3 | ARG JOBS=2 |
alshabib | 187f172 | 2015-06-23 16:15:50 -0700 | [diff] [blame] | 4 | |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 5 | # First stage is the build environment. |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 6 | # zulu-openjdk images are based on Ubuntu. |
| 7 | FROM azul/zulu-openjdk:${JDK_VER} as builder |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 8 | |
| 9 | ENV BUILD_DEPS \ |
| 10 | ca-certificates \ |
| 11 | zip \ |
| 12 | python \ |
| 13 | python3 \ |
| 14 | git \ |
| 15 | bzip2 \ |
| 16 | build-essential \ |
| 17 | curl \ |
Brian O'Connor | be25b75 | 2019-10-09 17:39:28 -0700 | [diff] [blame^] | 18 | unzip \ |
| 19 | iproute2 |
| 20 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 21 | RUN apt-get update && apt-get install -y ${BUILD_DEPS} |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 22 | |
| 23 | # Install Bazel |
| 24 | ARG BAZEL_VER |
| 25 | RUN curl -L -o bazel.sh https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VER}/bazel-${BAZEL_VER}-installer-linux-x86_64.sh |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 26 | RUN chmod +x bazel.sh && ./bazel.sh |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 27 | |
| 28 | # Build-stage environment variables |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 29 | ENV ONOS_ROOT /src/onos |
alshabib | 187f172 | 2015-06-23 16:15:50 -0700 | [diff] [blame] | 30 | ENV BUILD_NUMBER docker |
Ray Milkey | 8c05c9b | 2017-03-15 15:47:57 -0700 | [diff] [blame] | 31 | ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 |
Jonathan Hart | 809edee | 2016-12-15 18:33:05 -0800 | [diff] [blame] | 32 | |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 33 | # Copy in the sources |
| 34 | COPY . ${ONOS_ROOT} |
| 35 | WORKDIR ${ONOS_ROOT} |
Jonathan Hart | 15a71d8 | 2017-07-20 16:14:21 -0700 | [diff] [blame] | 36 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 37 | # 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 Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 41 | ARG JOBS |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 42 | ARG JDK_VER |
| 43 | RUN bazel build onos \ |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 44 | --jobs ${JOBS} \ |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 45 | --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 Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 49 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 50 | # 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. |
| 52 | RUN mkdir /output |
| 53 | RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1 |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 54 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 55 | # Second and final stage is the runtime environment. |
| 56 | FROM azul/zulu-openjdk:${JDK_VER} |
Jonathan Hart | 3e86419 | 2017-07-20 19:24:49 -0700 | [diff] [blame] | 57 | |
Jonathan Hart | 15a71d8 | 2017-07-20 16:14:21 -0700 | [diff] [blame] | 58 | LABEL 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 Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 63 | org.label-schema.schema-version="1.0" \ |
| 64 | maintainer="onos-dev@onosproject.org" |
| 65 | |
| 66 | # Install ONOS in /root/onos |
| 67 | COPY --from=builder /output/ /root/onos/ |
| 68 | WORKDIR /root/onos |
| 69 | |
Brian O'Connor | be25b75 | 2019-10-09 17:39:28 -0700 | [diff] [blame^] | 70 | # Add ip command |
| 71 | COPY --from=builder /bin/ip /bin/ |
| 72 | COPY --from=builder /lib/x86_64-linux-gnu/libmnl.so* /lib/x86_64-linux-gnu/ |
| 73 | COPY --from=builder /usr/lib/x86_64-linux-gnu/libelf.so* /lib/x86_64-linux-gnu/ |
| 74 | COPY --from=builder /sbin/ip /sbin/ |
| 75 | RUN ldconfig |
| 76 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 77 | # Set JAVA_HOME (by default not exported by zulu images) |
| 78 | ARG JDK_VER |
| 79 | ENV JAVA_HOME /usr/lib/jvm/zulu-${JDK_VER}-amd64 |
alshabib | 187f172 | 2015-06-23 16:15:50 -0700 | [diff] [blame] | 80 | |
| 81 | # Ports |
Charles Chan | 45624b8 | 2015-08-24 00:29:20 +0800 | [diff] [blame] | 82 | # 6653 - OpenFlow |
Jonathan Hart | 77daee8 | 2017-01-16 14:29:20 -0800 | [diff] [blame] | 83 | # 6640 - OVSDB |
alshabib | 187f172 | 2015-06-23 16:15:50 -0700 | [diff] [blame] | 84 | # 8181 - GUI |
| 85 | # 8101 - ONOS CLI |
Jonathan Hart | 15a71d8 | 2017-07-20 16:14:21 -0700 | [diff] [blame] | 86 | # 9876 - ONOS intra-cluster communication |
Jonathan Hart | 77daee8 | 2017-01-16 14:29:20 -0800 | [diff] [blame] | 87 | EXPOSE 6653 6640 8181 8101 9876 |
alshabib | 187f172 | 2015-06-23 16:15:50 -0700 | [diff] [blame] | 88 | |
Carmelo Cascone | e5b1d25 | 2019-06-26 15:56:51 -0700 | [diff] [blame] | 89 | # Run ONOS |
David Bainbridge | ff4fb04 | 2015-08-17 12:53:29 -0700 | [diff] [blame] | 90 | ENTRYPOINT ["./bin/onos-service"] |
Jonathan Hart | 3e86419 | 2017-07-20 19:24:49 -0700 | [diff] [blame] | 91 | CMD ["server"] |