370019800a11742411c510363f3defacee9c9a69
[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 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/
23
24 Name:           %{RPM_NAME}
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
30 BuildArch:      x86_64
31 Vendor:         %{_platform_vendor} and Nokia
32 Source0:        %{name}-%{version}.tar.gz
33
34 Requires: docker-ce >= 18.09.2
35 BuildRequires: docker-ce >= 18.09.2
36
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}
40
41 %description
42 This RPM contains the cpu-pooler container image, process-starter binary and related deployment artifacts for the CaaS subsystem.
43
44 %prep
45 %autosetup
46
47 %build
48 # build the process-starter binary inside a builder conatiner
49 docker build \
50   --network=host \
51   --no-cache \
52   --force-rm \
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}/
63
64 # create a directory for process-starter binary
65 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results
66
67 # run the builder conatiner for process-starter binary
68 docker run \
69   -id \
70   --rm \
71   --network=host \
72   --privileged \
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
81
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/
84
85 # rm container
86 for container_ran in $(docker ps -a | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }')
87 do
88     docker rm -f $container_ran
89 done
90
91 # remove docker image
92 docker rmi -f %{COMPONENT_PART}:builder
93
94 # build the cpu pooler
95 docker build \
96   --network=host \
97   --no-cache \
98   --force-rm \
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}/
109
110 # create a save folder
111 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/
112
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
115
116 # remove docker image
117 docker rmi -f %{COMPONENT}:%{IMAGE_TAG}
118
119 %install
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}/
122
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}/
125
126 mkdir -p %{buildroot}/%{_playbooks_path}/
127 rsync -av ansible/playbooks/cpupooler.yaml %{buildroot}/%{_playbooks_path}/
128
129 mkdir -p %{buildroot}/%{_roles_path}/
130 rsync -av ansible/roles/cpupooler %{buildroot}/%{_roles_path}/
131
132 %files
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
137
138 %preun
139
140 %post
141 mkdir -p %{_postconfig_path}/
142 ln -sf %{_playbooks_path}/cpupooler.yaml %{_postconfig_path}/
143
144 %postun
145 if [ $1 -eq 0 ]; then
146     rm -f %{_postconfig_path}/cpupooler.yaml
147 fi
148
149 %clean
150 rm -rf ${buildroot}