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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 %define COMPONENT cpupooler
16 %define COMPONENT_PART process-starter
17 %define RPM_NAME caas-%{COMPONENT}
18 %define RPM_MAJOR_VERSION 0.2.0
19 %define RPM_MINOR_VERSION 1
20 %define DEPENDENCY_MANAGER_VERSION 0.5.0
21 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
22 %define PROCESS_STARTER_INSTALL_PATH /opt/bin/
25 Version: %{RPM_MAJOR_VERSION}
26 Release: %{RPM_MINOR_VERSION}%{?dist}
27 Summary: Containers as a Service cpu-pooler component
28 License: %{_platform_license} and BSD 3-Clause License
29 URL: https://github.com/nokia/CPU-Pooler
31 Vendor: %{_platform_vendor} and Nokia
32 Source0: %{name}-%{version}.tar.gz
34 Requires: docker-ce >= 18.09.2
35 BuildRequires: docker-ce >= 18.09.2
37 # I was able to pack an executable via this.
38 # more info at https://fedoraproject.org/wiki/Packaging:Debuginfo
39 %global debug_package %{nil}
42 This RPM contains the cpu-pooler container image, process-starter binary and related deployment artifacts for the CaaS subsystem.
48 # build the process-starter binary inside a builder conatiner
53 --build-arg HTTP_PROXY="${http_proxy}" \
54 --build-arg HTTPS_PROXY="${https_proxy}" \
55 --build-arg NO_PROXY="${no_proxy}" \
56 --build-arg http_proxy="${http_proxy}" \
57 --build-arg https_proxy="${https_proxy}" \
58 --build-arg no_proxy="${no_proxy}" \
59 --build-arg DEPENDENCY_MANAGER="%{DEPENDENCY_MANAGER_VERSION}" \
60 --build-arg CPUPOOLER="%{RPM_MAJOR_VERSION}" \
61 --tag %{COMPONENT_PART}:builder \
62 %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT_PART}/
64 # create a directory for process-starter binary
65 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results
67 # run the builder conatiner for process-starter binary
73 -e HTTP_PROXY="${http_proxy}" \
74 -e HTTPS_PROXY="${https_proxy}" \
75 -e NO_PROXY="${no_proxy}" \
76 -e http_proxy="${http_proxy}" \
77 -e https_proxy="${https_proxy}" \
78 -e no_proxy="${no_proxy}" \
79 --entrypoint=/bin/sh \
80 %{COMPONENT_PART}:builder
82 # get the process-starter binary
83 docker cp $(docker ps | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }'):/process-starter %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/
86 for container_ran in $(docker ps -a | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }')
88 docker rm -f $container_ran
92 docker rmi -f %{COMPONENT_PART}:builder
94 # build the cpu pooler
99 --build-arg HTTP_PROXY="${http_proxy}" \
100 --build-arg HTTPS_PROXY="${https_proxy}" \
101 --build-arg NO_PROXY="${no_proxy}" \
102 --build-arg http_proxy="${http_proxy}" \
103 --build-arg https_proxy="${https_proxy}" \
104 --build-arg no_proxy="${no_proxy}" \
105 --build-arg DEPENDENCY_MANAGER="%{DEPENDENCY_MANAGER_VERSION}" \
106 --build-arg CPUPOOLER="%{RPM_MAJOR_VERSION}" \
107 --tag %{COMPONENT}:%{IMAGE_TAG} \
108 %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT}/
110 # create a save folder
111 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/
113 # save the cpu poooler container
114 docker save %{COMPONENT}:%{IMAGE_TAG} | gzip -c > %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar
116 # remove docker image
117 docker rmi -f %{COMPONENT}:%{IMAGE_TAG}
120 mkdir -p %{buildroot}/%{_caas_container_tar_path}/
121 rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
123 mkdir -p %{buildroot}%{PROCESS_STARTER_INSTALL_PATH}
124 rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/process-starter %{buildroot}/%{PROCESS_STARTER_INSTALL_PATH}/
126 mkdir -p %{buildroot}/%{_playbooks_path}/
127 rsync -av ansible/playbooks/cpupooler.yaml %{buildroot}/%{_playbooks_path}/
129 mkdir -p %{buildroot}/%{_roles_path}/
130 rsync -av ansible/roles/cpupooler %{buildroot}/%{_roles_path}/
133 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
134 %{PROCESS_STARTER_INSTALL_PATH}/process-starter
135 %{_playbooks_path}/cpupooler.yaml
136 %{_roles_path}/cpupooler
141 mkdir -p %{_postconfig_path}/
142 ln -sf %{_playbooks_path}/cpupooler.yaml %{_postconfig_path}/
145 if [ $1 -eq 0 ]; then
146 rm -f %{_postconfig_path}/cpupooler.yaml