cfb8c6de18b16709b643ff9502944fc402c68a8c
[ta/caas-kubedns.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 kubedns
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 1.15.4
18 %define RPM_MINOR_VERSION 3
19 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
20 %define go_version 1.12.9
21
22 Name:           %{RPM_NAME}
23 Version:        %{RPM_MAJOR_VERSION}
24 Release:        %{RPM_MINOR_VERSION}%{?dist}
25 Summary:        Containers as a Service Kube DNS component
26 License:        %{_platform_license} and Apache License and GNU Lesser General Public License v3.0 only and BSD 3-clause New or Revised License and MIT License and Common Development and Distribution License and BSD and GNU General Public License v2.0 only
27 URL:            https://github.com/kubernetes/dns
28 BuildArch:      x86_64
29 Vendor:         %{_platform_vendor} and Kubernetes DNS service unmodified
30 Source0:        %{name}-%{version}.tar.gz
31
32 Requires: docker-ce >= 18.09.2, rsync
33 BuildRequires: docker-ce-cli >= 18.09.2, xz
34
35 %description
36 This RPM contains the kubedns container image, and related deployment artifacts for the CaaS subsystem.
37
38 %prep
39 %autosetup
40
41 %build
42 # Building the container
43 docker build \
44   --network=host \
45   --no-cache \
46   --force-rm \
47   --build-arg HTTP_PROXY="${http_proxy}" \
48   --build-arg HTTPS_PROXY="${https_proxy}" \
49   --build-arg NO_PROXY="${no_proxy}" \
50   --build-arg http_proxy="${http_proxy}" \
51   --build-arg https_proxy="${https_proxy}" \
52   --build-arg no_proxy="${no_proxy}" \
53   --build-arg KUBEDNS_VERSION="%{RPM_MAJOR_VERSION}" \
54   --build-arg go_version="%{go_version}" \
55   --tag %{COMPONENT}:%{IMAGE_TAG} \
56   %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT}/
57
58 # Creating a new folder for the container tar file
59 mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/
60
61 # Save the container
62 docker save %{COMPONENT}:%{IMAGE_TAG} | xz -z -T2 > %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar
63
64 # Remove docker image
65 docker rmi -f %{COMPONENT}:%{IMAGE_TAG}
66
67 %install
68 mkdir -p %{buildroot}/%{_caas_container_tar_path}/
69 rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
70
71 mkdir -p %{buildroot}/%{_playbooks_path}/
72 rsync -av ansible/playbooks/kubedns.yaml %{buildroot}/%{_playbooks_path}/
73
74 mkdir -p %{buildroot}/%{_roles_path}/
75 rsync -av ansible/roles/kubedns %{buildroot}/%{_roles_path}/
76
77 %files
78 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
79 %{_playbooks_path}/kubedns.yaml
80 %{_roles_path}/kubedns
81
82 %preun
83
84 %post
85 mkdir -p %{_postconfig_path}/
86 ln -sf %{_playbooks_path}/kubedns.yaml %{_postconfig_path}/
87
88 %postun
89 if [ $1 -eq 0 ]; then
90     rm -f %{_postconfig_path}/kubedns.yaml
91 fi
92
93 %clean
94 rm -rf ${buildroot}