Skip to content

Commit 9a0c412

Browse files
committed
Add support for building a SLES rpm package
1 parent c8eb622 commit 9a0c412

3 files changed

Lines changed: 202 additions & 17 deletions

File tree

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ YAML_FILES+=$(shell find doc/examples -name "cloud-config*.txt" -type f )
88
CHANGELOG_VERSION=$(shell $(CWD)/tools/read-version)
99
CODE_VERSION=$(shell python -c "from cloudinit import version; print version.version_string()")
1010

11+
ifeq ($(distro),)
12+
distro = redhat
13+
endif
14+
1115
all: test check_version
1216

1317
pep8:
@@ -25,7 +29,7 @@ test:
2529
check_version:
2630
@if [ "$(CHANGELOG_VERSION)" != "$(CODE_VERSION)" ]; then \
2731
echo "Error: ChangeLog version $(CHANGELOG_VERSION)" \
28-
"not equal to code version $(CODE_VERSION)"; exit 2; \
32+
"not equal to code version $(CODE_VERSION)"; exit 2; \
2933
else true; fi
3034

3135
2to3:
@@ -37,9 +41,9 @@ clean:
3741

3842
yaml:
3943
@$(CWD)/tools/validate-yaml.py $(YAML_FILES)
40-
44+
4145
rpm:
42-
./packages/brpm
46+
./packages/brpm --distro $(distro)
4347

4448
deb:
4549
./packages/bddeb

packages/brpm

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,26 @@ from cloudinit import util
3434
# this is a translation of the 'requires'
3535
# file pypi package name to a redhat/fedora package name.
3636
PKG_MP = {
37-
'argparse': 'python-argparse',
38-
'boto': 'python-boto',
39-
'cheetah': 'python-cheetah',
40-
'configobj': 'python-configobj',
41-
'oauth': 'python-oauth',
42-
'prettytable': 'python-prettytable',
43-
'pyyaml': 'PyYAML',
44-
'requests': 'python-requests',
37+
'redhat': {
38+
'argparse': 'python-argparse',
39+
'boto': 'python-boto',
40+
'cheetah': 'python-cheetah',
41+
'configobj': 'python-configobj',
42+
'oauth': 'python-oauth',
43+
'prettytable': 'python-prettytable',
44+
'pyyaml': 'PyYAML',
45+
'requests': 'python-requests',
46+
},
47+
'suse': {
48+
'argparse': 'python-argparse',
49+
'boto': 'python-boto',
50+
'cheetah': 'python-cheetah',
51+
'configobj': 'python-configobj',
52+
'oauth': 'python-oauth',
53+
'prettytable': 'python-prettytable',
54+
'pyyaml': 'python-yaml',
55+
'requests': 'python-requests',
56+
}
4557
}
4658

4759
# Subdirectories of the ~/rpmbuild dir
@@ -120,7 +132,7 @@ def generate_spec_contents(args, tmpl_fn, top_dir, arc_fn):
120132
# Map to known packages
121133
requires = []
122134
for p in pkgs:
123-
tgt_pkg = PKG_MP.get(p)
135+
tgt_pkg = PKG_MP[args.distro].get(p)
124136
if not tgt_pkg:
125137
raise RuntimeError(("Do not know how to translate pypi dependency"
126138
" %r to a known package") % (p))
@@ -142,10 +154,11 @@ def generate_spec_contents(args, tmpl_fn, top_dir, arc_fn):
142154
missing_versions += 1
143155
if missing_versions == 1:
144156
# Must be using a new 'dev'/'trunk' release
145-
changelog_lines.append(format_change_line(datetime.now(), '??'))
157+
changelog_lines.append(format_change_line(datetime.now(),
158+
'??'))
146159
else:
147-
sys.stderr.write(("Changelog version line %s "
148-
"does not have a corresponding tag!\n") % (line))
160+
sys.stderr.write(("Changelog version line %s does not "
161+
"have a corresponding tag!\n") % (line))
149162
else:
150163
changelog_lines.append(header)
151164
else:
@@ -171,6 +184,10 @@ def generate_spec_contents(args, tmpl_fn, top_dir, arc_fn):
171184
def main():
172185

173186
parser = argparse.ArgumentParser()
187+
parser.add_argument("-d", "--distro", dest="distro",
188+
help="select distro (default: %(default)s)",
189+
metavar="DISTRO", default='redhat',
190+
choices=('redhat', 'suse'))
174191
parser.add_argument("-b", "--boot", dest="boot",
175192
help="select boot type (default: %(default)s)",
176193
metavar="TYPE", default='sysvinit',
@@ -218,7 +235,7 @@ def main():
218235

219236
# Form the spec file to be used
220237
tmpl_fn = util.abs_join(find_root(), 'packages',
221-
'redhat', 'cloud-init.spec.in')
238+
args.distro, 'cloud-init.spec.in')
222239
contents = generate_spec_contents(args, tmpl_fn, root_dir,
223240
os.path.basename(archive_fn))
224241
spec_fn = util.abs_join(root_dir, 'cloud-init.spec')
@@ -236,14 +253,16 @@ def main():
236253
globs = []
237254
globs.extend(glob.glob("%s/*.rpm" %
238255
(util.abs_join(root_dir, 'RPMS', 'noarch'))))
256+
globs.extend(glob.glob("%s/*.rpm" %
257+
(util.abs_join(root_dir, 'RPMS', 'x86_64'))))
239258
globs.extend(glob.glob("%s/*.rpm" %
240259
(util.abs_join(root_dir, 'RPMS'))))
241260
globs.extend(glob.glob("%s/*.rpm" %
242261
(util.abs_join(root_dir, 'SRPMS'))))
243262
for rpm_fn in globs:
244263
tgt_fn = util.abs_join(os.getcwd(), os.path.basename(rpm_fn))
245264
shutil.move(rpm_fn, tgt_fn)
246-
print("Wrote out redhat package %r" % (tgt_fn))
265+
print("Wrote out %s package %r" % (args.distro, tgt_fn))
247266

248267
return 0
249268

packages/suse/cloud-init.spec.in

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
## This is a cheetah template
2+
3+
# See: http://www.zarb.org/~jasonc/macros.php
4+
# Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets
5+
# Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html
6+
7+
#for $d in $defines
8+
%define ${d}
9+
#end for
10+
11+
Name: cloud-init
12+
Version: ${version}
13+
Release: ${release}${subrelease}%{?dist}
14+
Summary: Cloud instance init scripts
15+
16+
Group: System/Management
17+
License: GPLv3
18+
URL: http://launchpad.net/cloud-init
19+
20+
Source0: ${archive_name}
21+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
22+
23+
%if 0%{?suse_version} && 0%{?suse_version} <= 1110
24+
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
25+
%else
26+
BuildArch: noarch
27+
%endif
28+
29+
BuildRequires: fdupes
30+
BuildRequires: filesystem
31+
BuildRequires: python-devel
32+
BuildRequires: python-setuptools
33+
BuildRequires: python-cheetah
34+
35+
%if 0%{?suse_version} && 0%{?suse_version} <= 1210
36+
%define initsys sysvinit
37+
%else
38+
%define initsys systemd
39+
%endif
40+
41+
# System util packages needed
42+
Requires: iproute2
43+
Requires: e2fsprogs
44+
Requires: net-tools
45+
Requires: procps
46+
47+
# Install pypi 'dynamic' requirements
48+
#for $r in $requires
49+
Requires: ${r}
50+
#end for
51+
52+
# Custom patches
53+
#set $size = 0
54+
#for $p in $patches
55+
Patch${size}: $p
56+
#set $size += 1
57+
#end for
58+
59+
%description
60+
Cloud-init is a set of init scripts for cloud instances. Cloud instances
61+
need special scripts to run during initialization to retrieve and install
62+
ssh keys and to let the user run various scripts.
63+
64+
%prep
65+
%setup -q -n %{name}-%{version}~${release}
66+
67+
# Custom patches activation
68+
#set $size = 0
69+
#for $p in $patches
70+
%patch${size} -p1
71+
#set $size += 1
72+
#end for
73+
74+
%build
75+
%{__python} setup.py build
76+
77+
%install
78+
%{__python} setup.py install \
79+
--skip-build --root=%{buildroot} --prefix=%{_prefix} \
80+
--record-rpm=INSTALLED_FILES --install-lib=%{python_sitelib} \
81+
--init-system=%{initsys}
82+
83+
# Remove non-SUSE templates
84+
rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.debian.*
85+
rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.redhat.*
86+
rm %{buildroot}/%{_sysconfdir}/cloud/templates/*.ubuntu.*
87+
88+
# Remove cloud-init tests
89+
rm -r %{buildroot}/%{python_sitelib}/tests
90+
91+
# Move sysvinit scripts to the correct place and create symbolic links
92+
%if %{initsys} == sysvinit
93+
mkdir -p %{buildroot}/%{_initddir}
94+
mv %{buildroot}%{_sysconfdir}/rc.d/init.d/* %{buildroot}%{_initddir}/
95+
rmdir %{buildroot}%{_sysconfdir}/rc.d/init.d
96+
rmdir %{buildroot}%{_sysconfdir}/rc.d
97+
98+
mkdir -p %{buildroot}/%{_sbindir}
99+
pushd %{buildroot}/%{_initddir}
100+
for file in * ; do
101+
ln -s %{_initddir}/\${file} %{buildroot}/%{_sbindir}/rc\${file}
102+
done
103+
popd
104+
%endif
105+
106+
# Move documentation
107+
mkdir -p %{buildroot}/%{_defaultdocdir}
108+
mv %{buildroot}/usr/share/doc/cloud-init %{buildroot}/%{_defaultdocdir}
109+
for doc in TODO LICENSE ChangeLog Requires ; do
110+
cp \${doc} %{buildroot}/%{_defaultdocdir}/cloud-init
111+
done
112+
113+
# Remove duplicate files
114+
%if 0%{?suse_version}
115+
%fdupes %{buildroot}/%{python_sitelib}
116+
%endif
117+
118+
mkdir -p %{buildroot}/var/lib/cloud
119+
120+
%postun
121+
%insserv_cleanup
122+
123+
%files
124+
125+
# Sysvinit scripts
126+
%if %{initsys} == sysvinit
127+
%attr(0755, root, root) %{_initddir}/cloud-config
128+
%attr(0755, root, root) %{_initddir}/cloud-final
129+
%attr(0755, root, root) %{_initddir}/cloud-init-local
130+
%attr(0755, root, root) %{_initddir}/cloud-init
131+
132+
%{_sbindir}/rccloud-*
133+
%endif
134+
135+
# Program binaries
136+
%{_bindir}/cloud-init*
137+
138+
# There doesn't seem to be an agreed upon place for these
139+
# although it appears the standard says /usr/lib but rpmbuild
140+
# will try /usr/lib64 ??
141+
/usr/lib/%{name}/uncloud-init
142+
/usr/lib/%{name}/write-ssh-key-fingerprints
143+
144+
# Docs
145+
%doc %{_defaultdocdir}/cloud-init/*
146+
147+
# Configs
148+
%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg
149+
%dir %{_sysconfdir}/cloud/cloud.cfg.d
150+
%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/*.cfg
151+
%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/README
152+
%dir %{_sysconfdir}/cloud/templates
153+
%config(noreplace) %{_sysconfdir}/cloud/templates/*
154+
155+
# Python code is here...
156+
%{python_sitelib}/*
157+
158+
/var/lib/cloud
159+
160+
%changelog
161+
162+
${changelog}

0 commit comments

Comments
 (0)