Kubernetes 1.16.0 node label fix
[ta/caas-danm.git] / SPECS / caas-hyperdanm.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 hyperdanm
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 4.0.0
18 %define RPM_MINOR_VERSION 4
19 %define DANM_VERSION 687031341573550f387e109b273d8dd0cebf93bf
20 %define go_version 1.12.9
21 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
22 %define danm_components netwatcher svcwatcher webhook
23 %define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
24 %define docker_save_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save
25 %define binary_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/binary-save
26 %define built_binaries_dir /binary-save
27
28 Name:           %{RPM_NAME}
29 Version:        %{RPM_MAJOR_VERSION}
30 Release:        %{RPM_MINOR_VERSION}%{?dist}
31 Summary:        Containers as a Service %{COMPONENT} component
32 License:        %{_platform_license} and BSD 3-Clause License
33 URL:            https://github.com/nokia/danm
34 BuildArch:      x86_64
35 Vendor:         %{_platform_vendor} and Nokia and Others unmodified
36 Source0:        %{name}-%{version}.tar.gz
37
38 Requires:       docker-ce >= 18.09.2, rsync
39 BuildRequires:  docker-ce-cli >= 18.09.2, xz
40 Obsoletes:      caas-danm-webhook <= 4.0.0, caas-netwatcher <= 4.0.0, caas-svcwatcher <= 4.0.0
41
42 %description
43 This RPM contains the %{COMPONENT} container image, and related deployment artifacts for the CaaS subsystem.
44
45 %prep
46 %autosetup
47
48 %build
49 # Build DANM binaries
50 docker build \
51   --network=host \
52   --no-cache \
53   --force-rm \
54   --build-arg HTTP_PROXY="${http_proxy}" \
55   --build-arg HTTPS_PROXY="${https_proxy}" \
56   --build-arg NO_PROXY="${no_proxy}" \
57   --build-arg http_proxy="${http_proxy}" \
58   --build-arg https_proxy="${https_proxy}" \
59   --build-arg no_proxy="${no_proxy}" \
60   --build-arg DANM_VERSION="%{DANM_VERSION}" \
61   --build-arg go_version="%{go_version}" \
62   --build-arg binaries="%{built_binaries_dir}" \
63   --build-arg components="%{danm_components}" \
64   --tag danm-builder:%{IMAGE_TAG} \
65   %{docker_build_dir}/danm-builder/
66
67 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh danm-builder:%{IMAGE_TAG})
68 for component in %{danm_components}; do
69   mkdir -p %{binary_build_dir}/
70   docker cp ${builder_container}:%{built_binaries_dir}/${component} %{binary_build_dir}/
71 done
72 docker rm -f ${builder_container}
73 docker rmi danm-builder:%{IMAGE_TAG}
74
75 # Build hyperdanm container image
76 mkdir -p %{docker_build_dir}/%{COMPONENT}/danm_binaries
77 rsync -av %{binary_build_dir}/* %{docker_build_dir}/%{COMPONENT}/danm_binaries
78 docker build \
79   --network=host \
80   --no-cache \
81   --force-rm \
82   --build-arg HTTP_PROXY="${http_proxy}" \
83   --build-arg HTTPS_PROXY="${https_proxy}" \
84   --build-arg NO_PROXY="${no_proxy}" \
85   --build-arg http_proxy="${http_proxy}" \
86   --build-arg https_proxy="${https_proxy}" \
87   --build-arg no_proxy="${no_proxy}" \
88   --tag %{COMPONENT}:%{IMAGE_TAG} \
89   %{docker_build_dir}/%{COMPONENT}/
90
91 mkdir -p %{docker_save_dir}/
92 docker save %{COMPONENT}:%{IMAGE_TAG} | xz -z -T2 > %{docker_save_dir}/%{COMPONENT}:%{IMAGE_TAG}.tar
93 docker rmi -f %{COMPONENT}:%{IMAGE_TAG}
94
95 %install
96 mkdir -p %{buildroot}/%{_caas_container_tar_path}/
97 rsync -av %{docker_save_dir}/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
98
99 mkdir -p %{buildroot}/%{_playbooks_path}/
100 rsync -av ansible/playbooks/danm_setup.yaml %{buildroot}/%{_playbooks_path}/
101
102 mkdir -p %{buildroot}/%{_roles_path}/
103 rsync -av ansible/roles/danm_setup %{buildroot}/%{_roles_path}/
104
105 %files
106 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
107 %{_playbooks_path}/danm_setup.yaml
108 %{_roles_path}/danm_setup
109
110 %preun
111
112 %post
113 mkdir -p %{_postconfig_path}/
114 ln -sf %{_playbooks_path}/danm_setup.yaml %{_postconfig_path}/
115
116 %postun
117 if [ $1 -eq 0 ]; then
118     rm -f %{_postconfig_path}/danm_setup.yaml
119 fi
120
121 %clean
122 rm -rf ${buildroot}