Skip to content

Commit 56f13c0

Browse files
authored
Merge pull request #17 from ggatward/puppet-fixes
Add artifactory push support
2 parents 302970f + c74f377 commit 56f13c0

4 files changed

Lines changed: 77 additions & 6 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ optional arguments:
276276
This script allows users with an offline puppet-forge-server (rubygem) instance to
277277
perform a special export of puppetforge modules from the Satellite puppet-forge
278278
repository (-r) in the directory structure required by the puppet-forge-server
279-
application. After exporting, the modules are copied via rsync to the puppet-forge-server.
279+
application. After exporting, the modules are copied to the puppet-forge-server. The format
280+
of the export is controlled with the type (-t) flag, as either 'puppet-forge-server' for the
281+
rubygem based server, or 'artifiactory' for JFrog Artifiactory puppet server format.
280282
The puppet-forge-server hostname can be defined in the config.yml, or overridden with
281283
(-s), as can the module path (-m) on the remote server (default is /opt/puppet-forge/modules).
282284
The user performing the rsync will be the user that is running the script, unless
@@ -285,7 +287,9 @@ overridden with (-u).
285287
The config.yml block that defines the puppet-forge-server hostname is:
286288
```
287289
puppet-forge-server:
290+
servertype: puppet-forge-server
288291
hostname: puppetforge.example.org
292+
modulepath: /opt/puppet-forge/modules
289293
```
290294

291295
```
@@ -297,6 +301,7 @@ optional arguments:
297301
-h, --help show this help message and exit
298302
-o ORG, --org ORG Organization (Uses default if not specified)
299303
-r REPO, --repo REPO Puppetforge repository label
304+
-t TYPE, --type TYPE Puppetforge server type (puppet-forge-server|artifiactory)
300305
-s SERVER, --server SERVER
301306
puppet-forge-server hostname
302307
-m MODULEPATH, --modulepath MODULEPATH
@@ -309,7 +314,7 @@ optional arguments:
309314
```
310315
./push_puppetforge.py -r Puppet_Forge
311316
./push_puppetforge.py -r Puppet_Forge -u fred
312-
./push_puppetforge.py -r Puppet_Forge -s test.example.org -m /opt/tmp
317+
./push_puppetforge.py -r Puppet_Forge -s test.example.org -m /opt/tmp -t artifiactory
313318
```
314319

315320

config/config.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ cleanup:
4545
keep: 3
4646

4747
puppet-forge-server:
48+
servertype: puppet-forge-server
4849
hostname: puppetforge.example.org
50+
modulepath: /opt/puppet-forge/modules

helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@
5959
PROMOTEBATCH = CONFIG['promotion']['batch']
6060
else:
6161
PROMOTEBATCH = 255
62+
if 'servertype' in CONFIG['puppet-forge-server']:
63+
PFMETHOD = CONFIG['puppet-forge-server']['servertype']
64+
else:
65+
PFMETHOD = 'puppet-forge-server'
6266
if 'hostname' in CONFIG['puppet-forge-server']:
6367
PFSERVER = CONFIG['puppet-forge-server']['hostname']
68+
if 'modulepath' in CONFIG['puppet-forge-server']:
69+
PFMODPATH = CONFIG['puppet-forge-server']['modulepath']
6470

6571
# 'Global' Satellite 6 parameters
6672
# Satellite API

push_puppetforge.py

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@ def copy_to_pfserver(export_dir, pfserver, pfmodpath, pfuser):
9999
os.system('rsync -avrzc ' + export_dir + '/* ' + target)
100100

101101

102+
def splitext(path):
103+
"""
104+
Method to split the exported filename into author-module-version parts
105+
"""
106+
for ext in ['.tar.gz']:
107+
if path.endswith(ext):
108+
return path[:-len(ext)], path[-len(ext):]
109+
return os.path.splitext(path)
110+
111+
112+
def postModule(moduleTar, moduleInputDir, pfserver, pfmodpath)
113+
"""
114+
Function to push puppet modules using curl to Artifiactory repository
115+
"""
116+
# Remove module's extension (.tar.gz)
117+
puppetModuleNameNoExt = splitext(moduleTar)[0]
118+
119+
# Remove the path from the module
120+
puppetModuleName = puppetModuleNameNoExt.split('/')[-1]
121+
122+
# Split the module name into the required parts
123+
puppetModuleNameList = puppetModuleName.split('-')
124+
author = puppetModuleNameList[0]
125+
moduleName = puppetModuleNameList[1]
126+
version = puppetModuleNameList[2]
127+
128+
url = "http://" + pfserver + pfmodpath + "/" + author + "/" + moduleName + "/" + moduleTar
129+
fileName = moduleInputDir + "/" + moduleTar
130+
131+
# Put the files using curl (need to clean this up)
132+
subprocess.call(['curl', '-XPUT', url, '-T', fileName])
133+
134+
102135
def main(args):
103136
"""
104137
Main Routine
@@ -121,6 +154,7 @@ def main(args):
121154
parser.add_argument('-o', '--org', help='Organization (Uses default if not specified)',
122155
required=False)
123156
parser.add_argument('-r', '--repo', help='Puppetforge repo label', required=False)
157+
parser.add_argument('-t', '--type', help='Puppetforge server type (puppet-forge-server|artifiactory)', required=False)
124158
parser.add_argument('-s', '--server', help='puppet-forge-server hostname', required=False)
125159
parser.add_argument('-m', '--modulepath', help='path to puppet-forge-server modules',
126160
required=False)
@@ -134,6 +168,16 @@ def main(args):
134168
else:
135169
org_name = helpers.ORG_NAME
136170

171+
# Define the type of puppet-forge server
172+
if args.type:
173+
pftype = args.type
174+
else:
175+
if not helpers.PFMETHOD:
176+
print "Puppet forge server type not specified"
177+
sys.exit(1)
178+
else:
179+
pftype = helpers.PFMETHOD
180+
137181
# Define the puppet-forge-server hostname
138182
if args.server:
139183
pfserver = args.server
@@ -148,7 +192,11 @@ def main(args):
148192
if args.modulepath:
149193
modpath = args.modulepath
150194
else:
151-
modpath = '/opt/puppet-forge/modules'
195+
if not.helpers.PFMODPATH:
196+
print "Puppet forge module path not defined"
197+
sys.exit(1)
198+
else:
199+
modpath = helpers.PFMODPATH
152200

153201
# Set the username to use to push modules
154202
if args.user:
@@ -206,10 +254,20 @@ def main(args):
206254
# Define the location of our exported data.
207255
export_dir = helpers.EXPORTDIR + "/puppetforge"
208256

209-
# Now we can copy the content to the puppet-forge-server instance
210-
os.chdir(script_dir)
211-
copy_to_pfserver(export_dir, pfserver, modpath, pfuser)
257+
if (pftype == 'puppet-forge-server'):
258+
# Method for posting to puppet-forge-server
259+
os.chdir(script_dir)
260+
copy_to_pfserver(export_dir, pfserver, modpath, pfuser)
261+
262+
elif (pftype == 'artifactory'):
263+
# Method for posting to Artifactory repository
264+
for module in os.listdir(export_dir):
265+
print("Posing: " + module)
266+
postModule(module, export_dir, pfserver, modpath)
212267

268+
else:
269+
print("Unknown puppet-forge server type defined")
270+
sys.exit(1)
213271

214272
# And we're done!
215273
print helpers.GREEN + "Puppet Forge export complete.\n" + helpers.ENDC

0 commit comments

Comments
 (0)