FIX: bump rpm minor version
[ta/caas-kubernetes.git] / caas-kubernetes.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 kubernetes
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 1.16.2
18 %define RPM_MINOR_VERSION 6
19 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
20 %define KUBERNETESPAUSE_VERSION 3.1
21
22 %define go_version 1.12.10
23 %define ceph_version 12.2.5
24 %define binary_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/binary-save
25 %define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
26 %define docker_save_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save
27 %define built_binaries_dir /binary-save
28 %define centos_build 191001
29
30 Name:           %{RPM_NAME}
31 Version:        %{RPM_MAJOR_VERSION}
32 Release:        %{RPM_MINOR_VERSION}%{?dist}
33 Summary:        Containers as a Service %{COMPONENT} component
34 License:        %{_platform_licence} and Apache License and GNU General Public License v2.0 only and GNU Lesser General Public License v2.1 only and MIT license and BSD and MIT license and ISC License and Creative Commons Attribution ShareAlike 4.0 International and Mozilla Public License and COMMON DEVELOPMENT AND DISTRIBUTION LICENSE and Lesser General Public License and Creative Commons - Public Domain and Creative Commons Public License and BSD 3-Clause License
35 BuildArch:      %{_arch}
36 Vendor:         %{_platform_vendor} and kubernetes/kubernetes 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
42 # more info at: https://fedoraproject.org/wiki/Packaging:Debuginfo No build ID note in Flannel
43 %global debug_package %{nil}
44
45 %description
46 This rpm contains the %{COMPONENT} container for CaaS subsystem.
47 This container contains the %{COMPONENT} service.
48
49 %prep
50 %autosetup
51
52 # Build Kubernetes binaries
53 %build
54 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}/kubernetes-builder/centos-7-docker.tar.xz
55 set -x
56 docker build \
57   --network=host \
58   --no-cache \
59   --force-rm \
60   --build-arg HTTP_PROXY="${http_proxy}" \
61   --build-arg HTTPS_PROXY="${https_proxy}" \
62   --build-arg NO_PROXY="${no_proxy}" \
63   --build-arg http_proxy="${http_proxy}" \
64   --build-arg https_proxy="${https_proxy}" \
65   --build-arg no_proxy="${no_proxy}" \
66   --build-arg KUBERNETES_VERSION="%{version}" \
67   --build-arg go_version="%{go_version}" \
68   --build-arg binaries="%{built_binaries_dir}" \
69   --tag kubernetes-builder:%{IMAGE_TAG} \
70   %{docker_build_dir}/kubernetes-builder
71
72 builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh kubernetes-builder:%{IMAGE_TAG})
73 mkdir -p %{binary_build_dir}
74 docker cp ${builder_container}:%{built_binaries_dir}/kubelet %{binary_build_dir}/
75 docker cp ${builder_container}:%{built_binaries_dir}/kubectl %{binary_build_dir}/
76 docker cp ${builder_container}:%{built_binaries_dir}/kube-apiserver %{binary_build_dir}/
77 docker cp ${builder_container}:%{built_binaries_dir}/kube-controller-manager %{binary_build_dir}/
78 docker cp ${builder_container}:%{built_binaries_dir}/kube-proxy %{binary_build_dir}/
79 docker cp ${builder_container}:%{built_binaries_dir}/kube-scheduler %{binary_build_dir}/
80 mkdir -p %{binary_build_dir}/cni
81 sync
82 docker rm -f ${builder_container}
83 docker rmi kubernetes-builder:%{IMAGE_TAG}
84
85 # Build hyperkube container image
86 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}/hyperkube/centos-7-docker.tar.xz
87 rsync -av %{binary_build_dir}/kube-apiserver %{docker_build_dir}/hyperkube/
88 rsync -av %{binary_build_dir}/kube-controller-manager %{docker_build_dir}/hyperkube/
89 rsync -av %{binary_build_dir}/kube-proxy %{docker_build_dir}/hyperkube/
90 rsync -av %{binary_build_dir}/kube-scheduler %{docker_build_dir}/hyperkube/
91 docker build \
92   --network=host \
93   --no-cache \
94   --force-rm \
95   --build-arg HTTP_PROXY="${http_proxy}" \
96   --build-arg HTTPS_PROXY="${https_proxy}" \
97   --build-arg NO_PROXY="${no_proxy}" \
98   --build-arg http_proxy="${http_proxy}" \
99   --build-arg https_proxy="${https_proxy}" \
100   --build-arg no_proxy="${no_proxy}" \
101   --build-arg ceph_version="%{ceph_version}" \
102   --tag hyperkube:%{IMAGE_TAG} \
103   %{docker_build_dir}/hyperkube
104 mkdir -p %{docker_save_dir}
105 docker save hyperkube:%{IMAGE_TAG} | xz -z -T2 > "%{docker_save_dir}/hyperkube:%{IMAGE_TAG}.tar"
106 docker rmi hyperkube:%{IMAGE_TAG}
107
108 # Build kubernetes pause container image
109 docker build \
110   --network=host \
111   --no-cache \
112   --force-rm \
113   --build-arg HTTP_PROXY="${http_proxy}" \
114   --build-arg HTTPS_PROXY="${https_proxy}" \
115   --build-arg NO_PROXY="${no_proxy}" \
116   --build-arg http_proxy="${http_proxy}" \
117   --build-arg https_proxy="${https_proxy}" \
118   --build-arg no_proxy="${no_proxy}" \
119   --build-arg KUBERNETESPAUSE_VERSION="%{KUBERNETESPAUSE_VERSION}" \
120   --tag kubernetespause:%{KUBERNETESPAUSE_VERSION} \
121   %{docker_build_dir}/kubernetespause
122 mkdir -p %{docker_save_dir}
123 docker save kubernetespause:%{KUBERNETESPAUSE_VERSION} | xz -z -T2 > "%{docker_save_dir}/kubernetespause:%{KUBERNETESPAUSE_VERSION}.tar"
124 docker rmi kubernetespause:%{KUBERNETESPAUSE_VERSION}
125
126 %install
127 mkdir -p %{buildroot}/%{_caas_container_tar_path}
128 rsync -av %{docker_save_dir}/* %{buildroot}/%{_caas_container_tar_path}/
129
130 mkdir -p %{buildroot}/%{_roles_path}
131 rsync -av ansible/roles/* %{buildroot}/%{_roles_path}/
132
133 mkdir -p %{buildroot}/%{_playbooks_path}/
134 rsync -av ansible/playbooks/* %{buildroot}/%{_playbooks_path}/
135
136 mkdir -p %{buildroot}/usr/bin/
137 install -D -m 0755 %{binary_build_dir}/kubectl %{buildroot}/usr/bin/kubectl
138 install -D -m 0755 %{binary_build_dir}/kubelet %{buildroot}/usr/bin/kubelet
139
140 mkdir -p %{buildroot}/%{_playbooks_path}/
141 rsync -av ansible/playbooks/* %{buildroot}/%{_playbooks_path}/
142
143 %files
144 %{_caas_container_tar_path}/*.tar
145 %{_roles_path}/
146 %{_playbooks_path}/
147 /usr/bin/kubectl
148 /usr/bin/kubelet
149
150 %preun
151
152 %post
153 mkdir -p %{_postconfig_path}
154 ln -s %{_playbooks_path}/bootstrap_kube_proxy.yaml          %{_postconfig_path}/
155 ln -s %{_playbooks_path}/bootstrap_kubelet.yaml             %{_postconfig_path}/
156 ln -s %{_playbooks_path}/kube_master.yaml                   %{_postconfig_path}/
157 ln -s %{_playbooks_path}/kube_secret_key_creation.yaml      %{_postconfig_path}/
158 ln -s %{_playbooks_path}/kube_secret_key_distribution.yaml  %{_postconfig_path}/
159 ln -s %{_playbooks_path}/kube_token_creation.yaml           %{_postconfig_path}/
160 ln -s %{_playbooks_path}/kube_token_distribution.yaml       %{_postconfig_path}/
161 ln -s %{_playbooks_path}/master_kube_proxy.yaml             %{_postconfig_path}/
162 ln -s %{_playbooks_path}/master_kubelet.yaml                %{_postconfig_path}/
163 ln -s %{_playbooks_path}/service_account_creation.yaml      %{_postconfig_path}/
164 ln -s %{_playbooks_path}/service_account_distribution.yaml  %{_postconfig_path}/
165 ln -s %{_playbooks_path}/set_nodes_label.yaml               %{_postconfig_path}/
166
167 %postun
168 if [ $1 -eq 0 ]; then
169   rm -f %{_postconfig_path}/bootstrap_kube_proxy.yaml
170   rm -f %{_postconfig_path}/bootstrap_kubelet.yaml
171   rm -f %{_postconfig_path}/kube_master.yaml
172   rm -f %{_postconfig_path}/kube_secret_key_creation.yaml
173   rm -f %{_postconfig_path}/kube_secret_key_distribution.yaml
174   rm -f %{_postconfig_path}/kube_token_creation.yaml
175   rm -f %{_postconfig_path}/kube_token_distribution.yaml
176   rm -f %{_postconfig_path}/master_kube_proxy.yaml
177   rm -f %{_postconfig_path}/master_kubelet.yaml
178   rm -f %{_postconfig_path}/service_account_creation.yaml
179   rm -f %{_postconfig_path}/service_account_distribution.yaml
180   rm -f %{_postconfig_path}/set_nodes_label.yaml
181 fi
182
183 %clean
184 rm -rf ${buildroot}