Changes to support configurable repository for Debian / Ubuntu

This commit is contained in:
David Murphy 2015-09-25 14:17:21 -06:00
parent 44b246bf93
commit 63407fd2a9

View file

@ -52,9 +52,28 @@ def _get_build_env(env):
return env_override
def _get_repo_env(env):
def _get_repo_options_env(env):
'''
Get repo environment overrides dictionary to use in repo process
Get repo environment overrides dictionary to use in repo options process
env
A dictionary of variables to define the repository options
Example:
.. code-block:: yaml
- env:
- OPTIONS : 'ask-passphrase'
.. warning::
The above illustrates a common PyYAML pitfall, that **yes**,
**no**, **on**, **off**, **true**, and **false** are all loaded as
boolean ``True`` and ``False`` values, and must be enclosed in
quotes to be used as strings. More info on this (and other) PyYAML
idiosyncrasies can be found :doc:`here
</topics/troubleshooting/yaml_idiosyncrasies>`.
'''
env_options = ''
if env is None:
@ -64,10 +83,96 @@ def _get_repo_env(env):
'\'env\' must be a Python dictionary'
)
for key, value in env.items():
env_options += '{0}\n'.format(value)
if key == 'OPTIONS':
env_options += '{0}\n'.format(value)
return env_options
def _get_repo_dists_env(env):
'''
Get repo environment overrides dictionary to use in repo distributions process
env
A dictionary of variables to define the repository distributions
Example:
.. code-block:: yaml
- env:
- ORIGIN : 'jessie'
- LABEL : 'salt debian'
- SUITE : 'main'
- VERSION : '8.1'
- CODENAME : 'jessie'
- ARCHS : 'amd64 i386 source'
- COMPONENTS : 'main'
- DESCRIPTION : 'SaltStack Debian package repo'
.. warning::
The above illustrates a common PyYAML pitfall, that **yes**,
**no**, **on**, **off**, **true**, and **false** are all loaded as
boolean ``True`` and ``False`` values, and must be enclosed in
quotes to be used as strings. More info on this (and other) PyYAML
idiosyncrasies can be found :doc:`here
</topics/troubleshooting/yaml_idiosyncrasies>`.
'''
# env key with tuple of control information for handling input env dictionary
# 0 | M - Mandatory, O - Optional, I - Ignore
# 1 | 'text string for repo field'
# 2 | 'default value'
dflts_dict = {
'OPTIONS': ('I', '', 'processed by _get_repo_options_env'),
'ORIGIN': ('O', 'Origin', 'SaltStack'),
'LABEL': ('O', 'Label', 'salt_debian'),
'SUITE': ('O', 'Suite', 'stable'),
'VERSION': ('O', 'Version', '8.1'),
'CODENAME': ('M', 'Codename', 'jessie'),
'ARCHS': ('M', 'Architectures', 'i386 amd64 source'),
'COMPONENTS': ('M', 'Components', 'main'),
'DESCRIPTION': ('O', 'Description', 'SaltStack debian package repo'),
}
env_dists = ''
codename = ''
dflts_keys = list(dflts_dict.keys())
if env is None:
for key, value in dflts_dict.items():
if dflts_dict[key][0] == 'M':
env_dists += '{0}: {1}\n'.format(dflts_dict[key][1], dflts_dict[key][2])
if key == 'CODENAME':
codename = dflts_dict[key][2]
return (codename, env_dists)
if not isinstance(env, dict):
raise SaltInvocationError(
'\'env\' must be a Python dictionary'
)
env_man_seen = []
for key, value in env.items():
if key in dflts_keys:
if dflts_dict[key][0] == 'M':
env_man_seen.append(key)
if key == 'CODENAME':
codename = value
if dflts_dict[key][0] != 'I':
env_dists += '{0}: {1}\n'.format(dflts_dict[key][1], value)
else:
env_dists += '{0}: {1}\n'.format(key, value)
## ensure mandatories are included
env_keys = list(env.keys())
for key in env_keys:
if key in dflts_keys and dflts_dict[key][0] == 'M' and key not in env_man_seen:
env_dists += '{0}: {1}\n'.format(dflts_dict[key][1], dflts_dict[key][2])
if key == 'CODENAME':
codename = value
return (codename, env_dists)
def _create_pbuilders(env):
'''
Create the .pbuilder family of files in user's home directory
@ -90,72 +195,13 @@ def _create_pbuilders(env):
idiosyncrasies can be found :doc:`here
</topics/troubleshooting/yaml_idiosyncrasies>`.
'''
hook_text = '''#!/bin/sh
set -e
cat > "/etc/apt/preferences" << EOF
Package: python-alabaster
Pin: release a=testing
Pin-Priority: 950
Package: python-sphinx
Pin: release a=testing
Pin-Priority: 900
Package: sphinx-common
Pin: release a=testing
Pin-Priority: 900
Package: *
Pin: release a=jessie-backports
Pin-Priority: 750
Package: *
Pin: release a=stable
Pin-Priority: 700
Package: *
Pin: release a=testing
Pin-Priority: 650
Package: *
Pin: release a=unstable
Pin-Priority: 600
Package: *
Pin: release a=experimental
Pin-Priority: 550
EOF
'''
pbldrc_text = '''DIST="jessie"
if [ -n "${DIST}" ]; then
TMPDIR=/tmp
BASETGZ="`dirname $BASETGZ`/$DIST-base.tgz"
DISTRIBUTION=$DIST
APTCACHE="/var/cache/pbuilder/$DIST/aptcache"
fi
HOOKDIR="${HOME}/.pbuilder-hooks"
OTHERMIRROR="deb http://ftp.us.debian.org/debian/ stable main contrib non-free | deb http://ftp.us.debian.org/debian/ testing main contrib non-free | deb http://ftp.us.debian.org/debian/ unstable main contrib non-free"
'''
home = os.path.expanduser('~')
pbuilder_hooksdir = os.path.join(home, '.pbuilder-hooks')
if not os.path.isdir(pbuilder_hooksdir):
os.makedirs(pbuilder_hooksdir)
g05hook = os.path.join(pbuilder_hooksdir, 'G05apt-preferences')
with salt.utils.fopen(g05hook, 'w') as fow:
fow.write('{0}'.format(hook_text))
cmd = 'chmod 755 {0}'.format(g05hook)
__salt__['cmd.run'](cmd)
pbuilderrc = os.path.join(home, '.pbuilderrc')
with salt.utils.fopen(pbuilderrc, 'w') as fow:
fow.write('{0}'.format(pbldrc_text))
if not os.path.isfile(pbuilderrc):
raise SaltInvocationError(
'pbuilderrc environment is incorrectly setup'
)
env_overrides = _get_build_env(env)
if env_overrides and not env_overrides.isspace():
@ -342,37 +388,29 @@ def make_repo(repodir, keyid=None, env=None):
salt '*' pkgbuild.make_repo /var/www/html/
'''
repocfg_text = '''Origin: SaltStack
Label: salt_debian
Suite: unstable
Codename: jessie
Architectures: i386 amd64 source
Components: contrib
Description: SaltStack debian package repo
Pull: jessie
'''
repoconf = os.path.join(repodir, 'conf')
if not os.path.isdir(repoconf):
os.makedirs(repoconf)
codename, repocfg_dists = _get_repo_dists_env(env)
repoconfdist = os.path.join(repoconf, 'distributions')
with salt.utils.fopen(repoconfdist, 'w') as fow:
fow.write('{0}'.format(repocfg_text))
fow.write('{0}'.format(repocfg_dists))
if keyid is not None:
with salt.utils.fopen(repoconfdist, 'a') as fow:
fow.write('SignWith: {0}\n'.format(keyid))
repocfg_opts = _get_repo_env(env)
repocfg_opts = _get_repo_options_env(env)
repoconfopts = os.path.join(repoconf, 'options')
with salt.utils.fopen(repoconfopts, 'w') as fow:
fow.write('{0}'.format(repocfg_opts))
for debfile in os.listdir(repodir):
if debfile.endswith('.changes'):
cmd = 'reprepro -Vb . include jessie {0}'.format(os.path.join(repodir, debfile))
cmd = 'reprepro -Vb . include {0} {1}'.format(codename, os.path.join(repodir, debfile))
__salt__['cmd.run'](cmd, cwd=repodir)
if debfile.endswith('.deb'):
cmd = 'reprepro -Vb . includedeb jessie {0}'.format(os.path.join(repodir, debfile))
cmd = 'reprepro -Vb . includedeb {0} {1}'.format(codename, os.path.join(repodir, debfile))
__salt__['cmd.run'](cmd, cwd=repodir)