DANM update
[ta/caas-danm.git] / SPECS / caas-danm.spec
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 %define COMPONENT danm
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 4.1.0
18 %define RPM_MINOR_VERSION 2
19 %define DANM_VERSION d3ecc88cb04d55373ff789de52427c9de2c438d3
20 %define CNI_VERSION 0.8.1
21 %define go_version 1.12.10
22 %define SRIOV_VERSION 9e4c973b2ac517c64867e33d61aee152d70dc330
23 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
24 %define binary_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/binary-save
25 %define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
26 %define build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/build
27 %define built_binaries_dir /binary-save
28 %define danm_components danm fakeipam
29 %define cnis flannel sriov
30 %define centos_build 191001
31 %ifarch aarch64
32 %define CNI_PLUGINS_ARCH arm64
33 %else
34 %define CNI_PLUGINS_ARCH amd64
35 %endif
36
37 Name:           %{RPM_NAME}
38 Version:        %{RPM_MAJOR_VERSION}
39 Release:        %{RPM_MINOR_VERSION}%{?dist}
40 Summary:        Containers as a Service %{COMPONENT} component
41 License:        %{_platform_license} and BSD 3-Clause License
42 URL:            https://github.com/nokia/danm
43 BuildArch:      %{_arch}
44 Vendor:         %{_platform_vendor} and Nokia and Others unmodified
45 Source0:        %{name}-%{version}.tar.gz
46
47 Requires: docker-ce >= 18.09.2, iputils, rsync
48 BuildRequires: docker-ce-cli >= 18.09.2, curl, wget
49
50 # more info at: https://fedoraproject.org/wiki/Packaging:Debuginfo No build ID note in Flannel
51 %global debug_package %{nil}
52
53 %description
54 This RPM contains the DANM and related CNI binaries for CaaS subsystem.
55
56 %prep
57 %autosetup
58
59 %build
60 mkdir -p %{binary_build_dir}/cni
61 curl -fsSL -k https://github.com/containernetworking/plugins/releases/download/v%{CNI_VERSION}/cni-plugins-linux-%{CNI_PLUGINS_ARCH}-v%{CNI_VERSION}.tgz  | tar zx --strip-components=1 -C %{binary_build_dir}/cni
62
63 # Build DANM binaries
64 wget --progress=dot:giga http://artifacts.ci.centos.org/sig-cloudinstance/centos-7-%{centos_build}/%{_arch}/centos-7-%{_arch}-docker.tar.xz -O %{docker_build_dir}/danm-builder/centos-7-docker.tar.xz
65 docker build \
66   --network=host \
67   --no-cache \
68   --force-rm \
69   --build-arg HTTP_PROXY="${http_proxy}" \
70   --build-arg HTTPS_PROXY="${https_proxy}" \
71   --build-arg NO_PROXY="${no_proxy}" \
72   --build-arg http_proxy="${http_proxy}" \
73   --build-arg https_proxy="${https_proxy}" \
74   --build-arg no_proxy="${no_proxy}" \
75   --build-arg DANM_VERSION="%{DANM_VERSION}" \
76   --build-arg go_version="%{go_version}" \
77   --build-arg binaries="%{built_binaries_dir}" \
78   --build-arg components="%{danm_components}" \
79   --tag danm-builder:%{IMAGE_TAG} \
80   %{docker_build_dir}/danm-builder/
81
82 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh danm-builder:%{IMAGE_TAG})
83 mkdir -p %{binary_build_dir}/danm
84 for component in %{danm_components}; do
85   docker cp ${builder_container}:%{built_binaries_dir}/${component} %{binary_build_dir}/danm/
86 done
87 docker rm -f ${builder_container}
88 docker rmi danm-builder:%{IMAGE_TAG}
89
90 # Build CNI binaries
91 wget --progress=dot:giga http://artifacts.ci.centos.org/sig-cloudinstance/centos-7-%{centos_build}/%{_arch}/centos-7-%{_arch}-docker.tar.xz -O %{docker_build_dir}/cni-builder/centos-7-docker.tar.xz
92 docker build \
93   --network=host \
94   --no-cache \
95   --force-rm \
96   --build-arg HTTP_PROXY="${http_proxy}" \
97   --build-arg HTTPS_PROXY="${https_proxy}" \
98   --build-arg NO_PROXY="${no_proxy}" \
99   --build-arg http_proxy="${http_proxy}" \
100   --build-arg https_proxy="${https_proxy}" \
101   --build-arg no_proxy="${no_proxy}" \
102   --build-arg go_version="%{go_version}" \
103   --build-arg SRIOV_VERSION="%{SRIOV_VERSION}" \
104   --build-arg binaries="%{built_binaries_dir}" \
105   --tag cni-builder:%{IMAGE_TAG} \
106   %{docker_build_dir}/cni-builder/
107
108 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh cni-builder:%{IMAGE_TAG})
109 mkdir -p %{binary_build_dir}/built_cnis
110 for cni in %{cnis}; do
111   docker cp ${builder_container}:%{built_binaries_dir}/${cni} %{binary_build_dir}/built_cnis/
112 done
113 docker rm -f ${builder_container}
114 docker rmi cni-builder:%{IMAGE_TAG}
115
116 # Collect DANM CRDs
117 git clone https://github.com/nokia/danm.git %{build_dir}/danm
118 cd %{build_dir}/danm
119 git checkout %{DANM_VERSION}
120
121 %install
122 mkdir -p %{buildroot}/etc/cni/net.d/
123 rsync -av cni-config/00-danm.conf %{buildroot}/etc/cni/net.d/00-danm.conf
124 rsync -av cni-config/flannel.conf %{buildroot}/etc/cni/net.d/flannel.conf
125
126 mkdir -p %{buildroot}/opt/cni/bin/
127 # Generic CNI plugins
128 # Don't use the standard ipvlan binary \
129 # Don't use portmap, quick fix for CVE-2019-9946 \
130 rsync -av \
131       --chmod=go+rx,u+rwx \
132       --exclude=ipvlan \
133       --exclude=portmap \
134        %{binary_build_dir}/cni/* %{buildroot}/opt/cni/bin
135 # DANM
136 for component in %{danm_components}; do
137   install -D -m 0755 %{binary_build_dir}/danm/${component} %{buildroot}/opt/cni/bin/${component}
138 done
139 # Other CNIs
140 for cni in %{cnis}; do
141   install -D -m 0755 %{binary_build_dir}/built_cnis/${cni} %{buildroot}/opt/cni/bin/${cni}
142 done
143
144 # DANM CRDs
145 mkdir -p %{buildroot}/%{_caas_danm_crd_path}
146 rsync -av %{build_dir}/danm/integration/crds/production/ %{buildroot}/%{_caas_danm_crd_path}
147
148
149 %files
150 # CONFIG
151 /etc/cni/net.d/00-danm.conf
152 /etc/cni/net.d/flannel.conf
153 # CNI binaries
154 /opt/cni/bin
155 # DANM CRDs
156 /%{_caas_danm_crd_path}
157
158 %preun
159
160 %post
161
162 %postun
163
164 %clean
165 rm -rf ${buildroot}