9c6cf3b6299d86cdf39cfb1ed8612ebf1427295d
[ta/caas-etcd.git] / caas-etcd.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 etcd
16 %define RPM_NAME caas-%{COMPONENT}
17 %define RPM_MAJOR_VERSION 3.4.0
18 %define RPM_MINOR_VERSION 2
19 %define go_version 1.12.10
20 %define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
21 %define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
22 %define docker_save_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save
23
24 Name:           %{RPM_NAME}
25 Version:        %{RPM_MAJOR_VERSION}
26 Release:        %{RPM_MINOR_VERSION}%{?dist}
27 Summary:        Containers as a Service %{COMPONENT} component
28 License:        %{_platform_license} and MIT license and BSD and Apache License and Lesser General Public License
29 URL:            https://github.com/etcd-io/etcd
30 BuildArch:      %{_arch}
31 Vendor:         %{_platform_vendor} and etcd-io/etcd unmodified
32 Source0:        %{name}-%{version}.tar.gz
33
34 Requires: docker-ce >= 18.09.2, rsync
35 BuildRequires: docker-ce-cli >= 18.09.2, xz
36
37 %description
38 This rpm contains the %{COMPONENT} container for CaaS subsystem.
39 This container contains the %{COMPONENT} service.
40
41 %prep
42 %autosetup
43
44 %build
45 docker build \
46   --network=host \
47   --no-cache \
48   --force-rm \
49   --build-arg HTTP_PROXY="${http_proxy}" \
50   --build-arg HTTPS_PROXY="${https_proxy}" \
51   --build-arg NO_PROXY="${no_proxy}" \
52   --build-arg http_proxy="${http_proxy}" \
53   --build-arg https_proxy="${https_proxy}" \
54   --build-arg no_proxy="${no_proxy}" \
55   --build-arg ETCD_VERSION="%{version}" \
56   --build-arg go_version="%{go_version}" \
57   --tag %{COMPONENT}:%{IMAGE_TAG} \
58   %{docker_build_dir}/%{COMPONENT}/
59 mkdir -p %{docker_save_dir}/
60 docker save %{COMPONENT}:%{IMAGE_TAG} | xz -z -T2 > %{docker_save_dir}/%{COMPONENT}:%{IMAGE_TAG}.tar
61 docker rmi %{COMPONENT}:%{IMAGE_TAG}
62
63 %install
64 mkdir -p %{buildroot}/%{_caas_container_tar_path}
65 rsync -av %{docker_save_dir}/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/
66
67 mkdir -p %{buildroot}/%{_roles_path}
68 rsync -av ansible/roles/* %{buildroot}/%{_roles_path}/
69
70 install -D ansible/playbooks/etcd.yaml %{buildroot}/%{_playbooks_path}/etcd.yaml
71
72 %files
73 %{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar
74 %{_roles_path}/etcd
75 %{_playbooks_path}/etcd.yaml
76
77 %preun
78
79 %post
80 mkdir -p %{_postconfig_path}
81 ln -s %{_playbooks_path}/etcd.yaml %{_postconfig_path}/
82
83 %postun
84 if [ $1 -eq 0 ]; then
85   rm -f %{_postconfig_path}/etcd.yaml
86 fi
87
88 %clean
89 rm -rf ${buildroot}