CPU Pooler version updated to 0.3.1
[ta/caas-cpupooler.git] / rpmbuild.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 cpupooler
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 0.3.1
18 %define RPM_MINOR_VERSION 15
19 %define CPUPOOLER_VERSION 0adced79e87e4cb87c41a70a654be377ca2d505f
20 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
21 %define PROCESS_STARTER_INSTALL_PATH /opt/bin/
22 %define PROJECT_NAME CPU-Pooler
23 %define PROJECT_BUILD_ROOT %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}
24
25 Name:           %{RPM_NAME}
26 Version:        %{RPM_MAJOR_VERSION}
27 Release:        %{RPM_MINOR_VERSION}%{?dist}
28 Summary:        Containers as a Service cpu-pooler component
29 License:        %{_platform_license} and BSD 3-Clause License
30 URL:            https://github.com/nokia/%{PROJECT_NAME}
31 BuildArch:      %{_arch}
32 Vendor:         %{_platform_vendor} and Nokia
33 Source0:        %{name}-%{version}.tar.gz
34 Source1:        %{url}/archive/%{CPUPOOLER_VERSION}.tar.gz
35
36 Requires: docker-ce >= 18.09.2, rsync
37 BuildRequires: docker-ce-cli >= 18.09.2, xz, wget
38
39 # I was able to pack an executable via this.
40 # more info at https://fedoraproject.org/wiki/Packaging:Debuginfo
41 %global debug_package %{nil}
42
43 %description
44 This RPM contains the cpu-pooler container image, process-starter binary and related deployment artifacts for the CaaS subsystem.
45
46 %prep
47 wget --progress=dot:giga --directory-prefix=%{_sourcedir} %{url}/archive/%{CPUPOOLER_VERSION}.tar.gz
48 %autosetup
49 # Autosetup extracts Source1 tar.gz to build directory and changes directory into it
50 %autosetup -b 1 -T -n %{PROJECT_NAME}-%{CPUPOOLER_VERSION}
51
52 %build
53 # build the cpu-pooler multi-binary image
54 docker build \
55   --network host \
56   --build-arg http_proxy \
57   --build-arg https_proxy \
58   --build-arg no_proxy \
59   --tag %{COMPONENT}:%{IMAGE_TAG} \
60   -f %{PROJECT_BUILD_ROOT}/docker-build/%{COMPONENT}/Dockerfile \
61   %{_builddir}/%{PROJECT_NAME}-%{CPUPOOLER_VERSION}
62
63 # build the builder image containing the binaries
64 docker build \
65   --network host \
66   --build-arg http_proxy \
67   --build-arg https_proxy \
68   --build-arg no_proxy \
69   --target builder \
70   --tag %{COMPONENT}:builder \
71   -f %{PROJECT_BUILD_ROOT}/docker-build/%{COMPONENT}/Dockerfile \
72   %{_builddir}/%{PROJECT_NAME}-%{CPUPOOLER_VERSION}
73
74 # create a directory for process-starter binary
75 mkdir -p %{PROJECT_BUILD_ROOT}/results
76
77 # run the builder container for process-starter binary
78 docker create --name=%{COMPONENT}-temp %{COMPONENT}:builder
79
80 # extract process-starter binary
81 docker cp %{COMPONENT}-temp:/process-starter %{PROJECT_BUILD_ROOT}/results/
82
83 # rm container
84 docker rm -v %{COMPONENT}-temp
85
86 # create a save folder
87 mkdir -p %{PROJECT_BUILD_ROOT}/docker-save/
88
89 # save the cpu poooler container
90 docker save %{COMPONENT}:%{IMAGE_TAG} | xz -z -T2 > %{PROJECT_BUILD_ROOT}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar
91
92 # remove docker images, containers
93 docker rmi -f %{COMPONENT}:%{IMAGE_TAG} %{COMPONENT}:builder
94 docker container prune --force
95 docker image prune --force
96
97 %install
98 mkdir -p %{buildroot}/%{_caas_container_tar_path}/
99 rsync -av %{PROJECT_BUILD_ROOT}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
100
101 mkdir -p %{buildroot}%{PROCESS_STARTER_INSTALL_PATH}
102 rsync -av %{PROJECT_BUILD_ROOT}/results/process-starter %{buildroot}/%{PROCESS_STARTER_INSTALL_PATH}/
103
104 mkdir -p %{buildroot}/%{_playbooks_path}/
105 rsync -av %{PROJECT_BUILD_ROOT}/ansible/playbooks/cpupooler.yaml %{buildroot}/%{_playbooks_path}/
106
107 mkdir -p %{buildroot}/%{_roles_path}/
108 rsync -av %{PROJECT_BUILD_ROOT}/ansible/roles/cpupooler %{buildroot}/%{_roles_path}/
109
110 %files
111 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
112 %{PROCESS_STARTER_INSTALL_PATH}/process-starter
113 %{_playbooks_path}/cpupooler.yaml
114 %{_roles_path}/cpupooler
115
116 %preun
117
118 %post
119 mkdir -p %{_postconfig_path}/
120 ln -sf %{_playbooks_path}/cpupooler.yaml %{_postconfig_path}/
121
122 %postun
123 if [ $1 -eq 0 ]; then
124     rm -f %{_postconfig_path}/cpupooler.yaml
125 fi
126
127 %clean
128 rm -rf ${buildroot}