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