mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #3301 from dokku/copy-packages
Add ability to sync packages to a new version of ubuntu
This commit is contained in:
51
contrib/copy-packages
Normal file
51
contrib/copy-packages
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python2.7
|
||||
import os
|
||||
import requests
|
||||
import shutil
|
||||
import subprocess
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
PACKAGECLOUD_API_TOKEN = os.getenv('DOKKU_PACKAGECLOUD_API_TOKEN')
|
||||
|
||||
|
||||
def download_file(filename, url):
|
||||
r = requests.get(url, stream=True)
|
||||
with open(filename, 'wb') as f:
|
||||
shutil.copyfileobj(r.raw, f)
|
||||
|
||||
|
||||
def upload_file(filename):
|
||||
versions = [
|
||||
"bionic",
|
||||
]
|
||||
cmd_template = "package_cloud push dokku/dokku/ubuntu/{0} {1}"
|
||||
for version in versions:
|
||||
cmd = cmd_template.format(version, filename)
|
||||
subprocess.call(cmd, shell=True)
|
||||
|
||||
|
||||
def main():
|
||||
auth = HTTPBasicAuth(PACKAGECLOUD_API_TOKEN, '')
|
||||
base = requests.get('https://packagecloud.io/api/v1/repos/dokku/dokku/packages/deb/ubuntu/trusty.json',
|
||||
auth=auth)
|
||||
data = base.json()
|
||||
urls = []
|
||||
for package in data:
|
||||
urls.append(package['versions_url'])
|
||||
|
||||
download_urls = {}
|
||||
for url in urls:
|
||||
base = requests.get('https://packagecloud.io{0}'.format(url),
|
||||
auth=auth)
|
||||
data = base.json()
|
||||
for version in data:
|
||||
download_urls['downloads/' + version['filename']] = version['download_url']
|
||||
|
||||
for filename, download_url in download_urls.items():
|
||||
print "downloading", filename
|
||||
download_file(filename, download_url)
|
||||
upload_file(filename)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user