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