Update DANM version hash
[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.0.0
18 %define RPM_MINOR_VERSION 5
19 %define DANM_VERSION 687031341573550f387e109b273d8dd0cebf93bf
20 %define CNI_VERSION 0.8.1
21 %define go_version 1.12.9
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
31 Name:           %{RPM_NAME}
32 Version:        %{RPM_MAJOR_VERSION}
33 Release:        %{RPM_MINOR_VERSION}%{?dist}
34 Summary:        Containers as a Service %{COMPONENT} component
35 License:        %{_platform_license} and BSD 3-Clause License
36 URL:            https://github.com/nokia/danm
37 BuildArch:      x86_64
38 Vendor:         %{_platform_vendor} and Nokia
39 Source0:        %{name}-%{version}.tar.gz
40
41 Requires: docker-ce >= 18.09.2, iputils, rsync
42 BuildRequires: docker-ce-cli >= 18.09.2, curl
43
44 # more info at: https://fedoraproject.org/wiki/Packaging:Debuginfo No build ID note in Flannel
45 %global debug_package %{nil}
46
47 %description
48 This RPM contains the DANM and related CNI binaries for CaaS subsystem.
49
50 %prep
51 %autosetup
52
53 %build
54 mkdir -p %{binary_build_dir}/cni
55 curl -fsSL -k https://github.com/containernetworking/plugins/releases/download/v%{CNI_VERSION}/cni-plugins-linux-amd64-v%{CNI_VERSION}.tgz  | tar zx --strip-components=1 -C %{binary_build_dir}/cni
56
57 # Build DANM binaries
58 docker build \
59   --network=host \
60   --no-cache \
61   --force-rm \
62   --build-arg HTTP_PROXY="${http_proxy}" \
63   --build-arg HTTPS_PROXY="${https_proxy}" \
64   --build-arg NO_PROXY="${no_proxy}" \
65   --build-arg http_proxy="${http_proxy}" \
66   --build-arg https_proxy="${https_proxy}" \
67   --build-arg no_proxy="${no_proxy}" \
68   --build-arg DANM_VERSION="%{DANM_VERSION}" \
69   --build-arg go_version="%{go_version}" \
70   --build-arg binaries="%{built_binaries_dir}" \
71   --build-arg components="%{danm_components}" \
72   --tag danm-builder:%{IMAGE_TAG} \
73   %{docker_build_dir}/danm-builder/
74
75 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh danm-builder:%{IMAGE_TAG})
76 mkdir -p %{binary_build_dir}/danm
77 for component in %{danm_components}; do
78   docker cp ${builder_container}:%{built_binaries_dir}/${component} %{binary_build_dir}/danm/
79 done
80 docker rm -f ${builder_container}
81 docker rmi danm-builder:%{IMAGE_TAG}
82
83 # Build CNI binaries
84 docker build \
85   --network=host \
86   --no-cache \
87   --force-rm \
88   --build-arg HTTP_PROXY="${http_proxy}" \
89   --build-arg HTTPS_PROXY="${https_proxy}" \
90   --build-arg NO_PROXY="${no_proxy}" \
91   --build-arg http_proxy="${http_proxy}" \
92   --build-arg https_proxy="${https_proxy}" \
93   --build-arg no_proxy="${no_proxy}" \
94   --build-arg go_version="%{go_version}" \
95   --build-arg SRIOV_VERSION="%{SRIOV_VERSION}" \
96   --build-arg binaries="%{built_binaries_dir}" \
97   --tag cni-builder:%{IMAGE_TAG} \
98   %{docker_build_dir}/cni-builder/
99
100 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh cni-builder:%{IMAGE_TAG})
101 mkdir -p %{binary_build_dir}/built_cnis
102 for cni in %{cnis}; do
103   docker cp ${builder_container}:%{built_binaries_dir}/${cni} %{binary_build_dir}/built_cnis/
104 done
105 docker rm -f ${builder_container}
106 docker rmi cni-builder:%{IMAGE_TAG}
107
108 # Collect DANM CRDs
109 git clone https://github.com/nokia/danm.git %{build_dir}/danm
110 cd %{build_dir}/danm
111 git checkout %{DANM_VERSION}
112
113 %install
114 mkdir -p %{buildroot}/etc/cni/net.d/
115 rsync -av cni-config/00-danm.conf %{buildroot}/etc/cni/net.d/00-danm.conf
116 rsync -av cni-config/flannel.conf %{buildroot}/etc/cni/net.d/flannel.conf
117
118 mkdir -p %{buildroot}/opt/cni/bin/
119 # Generic CNI plugins
120 # Don't use the standard ipvlan binary \
121 # Don't use portmap, quick fix for CVE-2019-9946 \
122 rsync -av \
123       --chmod=go+rx,u+rwx \
124       --exclude=ipvlan \
125       --exclude=portmap \
126        %{binary_build_dir}/cni/* %{buildroot}/opt/cni/bin
127 # DANM
128 for component in %{danm_components}; do
129   install -D -m 0755 %{binary_build_dir}/danm/${component} %{buildroot}/opt/cni/bin/${component}
130 done
131 # Other CNIs
132 for cni in %{cnis}; do
133   install -D -m 0755 %{binary_build_dir}/built_cnis/${cni} %{buildroot}/opt/cni/bin/${cni}
134 done
135
136 # DANM CRDs
137 mkdir -p %{buildroot}/%{_caas_danm_crd_path}
138 rsync -av %{build_dir}/danm/integration/crds/production/ %{buildroot}/%{_caas_danm_crd_path}
139
140
141 %files
142 # CONFIG
143 /etc/cni/net.d/00-danm.conf
144 /etc/cni/net.d/flannel.conf
145 # CNI binaries
146 /opt/cni/bin
147 # DANM CRDs
148 /%{_caas_danm_crd_path}
149
150 %preun
151
152 %post
153
154 %postun
155
156 %clean
157 rm -rf ${buildroot}