CPU Pooler version update
[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.3.0
19 %define RPM_MINOR_VERSION 8
20 %define go_version 1.12.10
21 %define CPUPOOLER_VERSION e0459346946b0907d26cd3d79dc54feb2c625286
22 %define DEP_MAN_VERSION 0.5.4
23 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
24 %define PROCESS_STARTER_INSTALL_PATH /opt/bin/
25 %define centos_build 191001
26
27 Name:           %{RPM_NAME}
28 Version:        %{RPM_MAJOR_VERSION}
29 Release:        %{RPM_MINOR_VERSION}%{?dist}
30 Summary:        Containers as a Service cpu-pooler component
31 License:        %{_platform_license} and BSD 3-Clause License
32 URL:            https://github.com/nokia/CPU-Pooler
33 BuildArch:      %{_arch}
34 Vendor:         %{_platform_vendor} and Nokia
35 Source0:        %{name}-%{version}.tar.gz
36
37 Requires: docker-ce >= 18.09.2, rsync
38 BuildRequires: docker-ce-cli >= 18.09.2, xz, wget
39
40 # I was able to pack an executable via this.
41 # more info at https://fedoraproject.org/wiki/Packaging:Debuginfo
42 %global debug_package %{nil}
43
44 %description
45 This RPM contains the cpu-pooler container image, process-starter binary and related deployment artifacts for the CaaS subsystem.
46
47 %prep
48 %autosetup
49
50 %build
51 wget --progress=dot:giga http://artifacts.ci.centos.org/sig-cloudinstance/centos-7-%{centos_build}/%{_arch}/centos-7-%{_arch}-docker.tar.xz -O %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT_PART}/centos-7-docker.tar.xz
52 # build the process-starter binary inside a builder conatiner
53 docker build \
54   --network=host \
55   --no-cache \
56   --force-rm \
57   --build-arg HTTP_PROXY="${http_proxy}" \
58   --build-arg HTTPS_PROXY="${https_proxy}" \
59   --build-arg NO_PROXY="${no_proxy}" \
60   --build-arg http_proxy="${http_proxy}" \
61   --build-arg https_proxy="${https_proxy}" \
62   --build-arg no_proxy="${no_proxy}" \
63   --build-arg go_version="%{go_version}" \
64   --build-arg DEP_MAN_VERSION="%{DEP_MAN_VERSION}" \
65   --build-arg CPUPOOLER_VERSION="%{CPUPOOLER_VERSION}" \
66   --tag %{COMPONENT_PART}:builder \
67   %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT_PART}/
68
69 # create a directory for process-starter binary
70 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results
71
72 # run the builder conatiner for process-starter binary
73 docker run \
74   -id \
75   --rm \
76   --network=host \
77   --privileged \
78   -e HTTP_PROXY="${http_proxy}" \
79   -e HTTPS_PROXY="${https_proxy}" \
80   -e NO_PROXY="${no_proxy}" \
81   -e http_proxy="${http_proxy}" \
82   -e https_proxy="${https_proxy}" \
83   -e no_proxy="${no_proxy}" \
84   --entrypoint=/bin/sh \
85   %{COMPONENT_PART}:builder
86
87 # get the process-starter binary
88 docker cp $(docker ps | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }'):/process-starter %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/
89
90 # rm container
91 for container_ran in $(docker ps -a | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }')
92 do
93     docker rm -f $container_ran
94 done
95
96 # remove docker image
97 docker rmi -f %{COMPONENT_PART}:builder
98
99 # build the cpu pooler
100 docker build \
101   --network=host \
102   --no-cache \
103   --force-rm \
104   --build-arg HTTP_PROXY="${http_proxy}" \
105   --build-arg HTTPS_PROXY="${https_proxy}" \
106   --build-arg NO_PROXY="${no_proxy}" \
107   --build-arg http_proxy="${http_proxy}" \
108   --build-arg https_proxy="${https_proxy}" \
109   --build-arg no_proxy="${no_proxy}" \
110   --build-arg DEP_MAN_VERSION="%{DEP_MAN_VERSION}" \
111   --build-arg CPUPOOLER_VERSION="%{CPUPOOLER_VERSION}" \
112   --build-arg go_version="%{go_version}" \
113   --tag %{COMPONENT}:%{IMAGE_TAG} \
114   %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT}/
115
116 # create a save folder
117 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/
118
119 # save the cpu poooler container
120 docker save %{COMPONENT}:%{IMAGE_TAG} | xz -z -T2 > %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar
121
122 # remove docker image
123 docker rmi -f %{COMPONENT}:%{IMAGE_TAG}
124
125 %install
126 mkdir -p %{buildroot}/%{_caas_container_tar_path}/
127 rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
128
129 mkdir -p %{buildroot}%{PROCESS_STARTER_INSTALL_PATH}
130 rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/process-starter %{buildroot}/%{PROCESS_STARTER_INSTALL_PATH}/
131
132 mkdir -p %{buildroot}/%{_playbooks_path}/
133 rsync -av ansible/playbooks/cpupooler.yaml %{buildroot}/%{_playbooks_path}/
134
135 mkdir -p %{buildroot}/%{_roles_path}/
136 rsync -av ansible/roles/cpupooler %{buildroot}/%{_roles_path}/
137
138 %files
139 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
140 %{PROCESS_STARTER_INSTALL_PATH}/process-starter
141 %{_playbooks_path}/cpupooler.yaml
142 %{_roles_path}/cpupooler
143
144 %preun
145
146 %post
147 mkdir -p %{_postconfig_path}/
148 ln -sf %{_playbooks_path}/cpupooler.yaml %{_postconfig_path}/
149
150 %postun
151 if [ $1 -eq 0 ]; then
152     rm -f %{_postconfig_path}/cpupooler.yaml
153 fi
154
155 %clean
156 rm -rf ${buildroot}