blob: 64bd479b22cb396db5f873d6c0ae3d03af645eba [file] [log] [blame]
Carmelo Casconed33d3b42019-06-18 12:12:36 -07001ARG JDK_VER=11
Carmelo Cascone212dc2f2019-11-21 22:13:09 -08002ARG BAZEL_VER=1.0.0
Carmelo Casconed33d3b42019-06-18 12:12:36 -07003ARG JOBS=2
pierventre18917912020-01-07 11:28:46 -08004ARG PROFILE=default
alshabib187f1722015-06-23 16:15:50 -07005
Carmelo Casconed33d3b42019-06-18 12:12:36 -07006# First stage is the build environment.
Carmelo Casconee5b1d252019-06-26 15:56:51 -07007# zulu-openjdk images are based on Ubuntu.
8FROM azul/zulu-openjdk:${JDK_VER} as builder
Carmelo Casconed33d3b42019-06-18 12:12:36 -07009
10ENV BUILD_DEPS \
11 ca-certificates \
12 zip \
13 python \
14 python3 \
15 git \
16 bzip2 \
17 build-essential \
18 curl \
Brian O'Connorc7e04542019-10-11 00:52:36 +000019 unzip
Carmelo Casconee5b1d252019-06-26 15:56:51 -070020RUN apt-get update && apt-get install -y ${BUILD_DEPS}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070021
22# Install Bazel
23ARG BAZEL_VER
24RUN 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 -070025RUN chmod +x bazel.sh && ./bazel.sh
Carmelo Casconed33d3b42019-06-18 12:12:36 -070026
27# Build-stage environment variables
Carmelo Casconee5b1d252019-06-26 15:56:51 -070028ENV ONOS_ROOT /src/onos
alshabib187f1722015-06-23 16:15:50 -070029ENV BUILD_NUMBER docker
Ray Milkey8c05c9b2017-03-15 15:47:57 -070030ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Jonathan Hart809edee2016-12-15 18:33:05 -080031
Carmelo Casconed33d3b42019-06-18 12:12:36 -070032# Copy in the sources
33COPY . ${ONOS_ROOT}
34WORKDIR ${ONOS_ROOT}
Jonathan Hart15a71d82017-07-20 16:14:21 -070035
Carmelo Casconee5b1d252019-06-26 15:56:51 -070036# Build ONOS using the JDK pre-installed in the base image, instead of the
37# Bazel-provided remote one. By doing wo we make sure to build with the most
38# updated JDK, including bug and security fixes, independently of the Bazel
39# version.
Carmelo Casconed33d3b42019-06-18 12:12:36 -070040ARG JOBS
Carmelo Casconee5b1d252019-06-26 15:56:51 -070041ARG JDK_VER
pierventre18917912020-01-07 11:28:46 -080042ARG PROFILE
Carmelo Casconee5b1d252019-06-26 15:56:51 -070043RUN 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 \
pierventre18917912020-01-07 11:28:46 -080048 --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/zulu-${JDK_VER}-amd64 \
49 --define profile=${PROFILE}
Carmelo Casconed33d3b42019-06-18 12:12:36 -070050
Carmelo Casconee5b1d252019-06-26 15:56:51 -070051# We extract the tar in the build environment to avoid having to put the tar in
52# the runtime stage. This saves a lot of space.
53RUN mkdir /output
54RUN tar -xf bazel-bin/onos.tar.gz -C /output --strip-components=1
Carmelo Casconed33d3b42019-06-18 12:12:36 -070055
Carmelo Casconee5b1d252019-06-26 15:56:51 -070056# Second and final stage is the runtime environment.
57FROM azul/zulu-openjdk:${JDK_VER}
Jonathan Hart3e864192017-07-20 19:24:49 -070058
Jonathan Hart15a71d82017-07-20 16:14:21 -070059LABEL org.label-schema.name="ONOS" \
60 org.label-schema.description="SDN Controller" \
61 org.label-schema.usage="http://wiki.onosproject.org" \
62 org.label-schema.url="http://onosproject.org" \
63 org.label-scheme.vendor="Open Networking Foundation" \
Carmelo Casconee5b1d252019-06-26 15:56:51 -070064 org.label-schema.schema-version="1.0" \
65 maintainer="onos-dev@onosproject.org"
66
Jonathan Hart16ec4be2019-12-02 13:19:35 -080067RUN apt-get update && apt-get install -y curl && \
68 rm -rf /var/lib/apt/lists/*
69
Carmelo Casconee5b1d252019-06-26 15:56:51 -070070# Install ONOS in /root/onos
71COPY --from=builder /output/ /root/onos/
72WORKDIR /root/onos
73
74# Set JAVA_HOME (by default not exported by zulu images)
75ARG JDK_VER
76ENV JAVA_HOME /usr/lib/jvm/zulu-${JDK_VER}-amd64
alshabib187f1722015-06-23 16:15:50 -070077
78# Ports
Charles Chan45624b82015-08-24 00:29:20 +080079# 6653 - OpenFlow
Jonathan Hart77daee82017-01-16 14:29:20 -080080# 6640 - OVSDB
alshabib187f1722015-06-23 16:15:50 -070081# 8181 - GUI
82# 8101 - ONOS CLI
Jonathan Hart15a71d82017-07-20 16:14:21 -070083# 9876 - ONOS intra-cluster communication
Jonathan Hart77daee82017-01-16 14:29:20 -080084EXPOSE 6653 6640 8181 8101 9876
alshabib187f1722015-06-23 16:15:50 -070085
Carmelo Casconee5b1d252019-06-26 15:56:51 -070086# Run ONOS
David Bainbridgeff4fb042015-08-17 12:53:29 -070087ENTRYPOINT ["./bin/onos-service"]
Jonathan Hart3e864192017-07-20 19:24:49 -070088CMD ["server"]