Skip to content

Commit

Permalink
Added update script for docker (#31)
Browse files Browse the repository at this point in the history
Fixed also some version mismatches in docker summaries
  • Loading branch information
miguelfc authored Apr 2, 2017
1 parent 5855245 commit c8ce2b0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 4 deletions.
112 changes: 112 additions & 0 deletions docker/update_docker_hub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"""Utility script to update docker hub descriptions using the Rest API.
Usage:
update_docker_hub.py update --username=<username> --password=<password> [--image=<image>]
update_docker_hub.py (-h | --help)
update_docker_hub.py --version
Options:
-h --help Show this screen.
--version Show version.
--username=<username> Docker Hub username
--password=<password> Docker Hub password
--image=<image> Image name to update
"""
from docopt import docopt
import pycurl
import sys
import os
import glob
import certifi
import json
import io
from io import BytesIO
from urllib.parse import urlencode


short_desc_name = "README-short.txt"
full_desc_name = "README.md"
docker_subpath = "src/main/docker"

if __name__ == '__main__':
arguments = docopt(__doc__, version='1.0')
# print(arguments)

update = arguments['update']

if (update):
username = arguments['--username']
password = arguments['--password']
image = arguments['--image']

images_to_update = []

if (image):
images_to_update.append(image)
else:
for full_dir_path in glob.glob("../marble-*"):
image_name = os.path.basename(full_dir_path)
if (os.path.isdir(os.path.join(full_dir_path, docker_subpath))):
images_to_update.append(image_name)

buffer = BytesIO()
c = pycurl.Curl()
post_data = {'username': username, 'password': password}
postfields = urlencode(post_data)
c.setopt(c.POSTFIELDS, postfields)
c.setopt(pycurl.CAINFO, certifi.where())
c.setopt(c.URL, 'https://hub.docker.com/v2/users/login/')
c.setopt(c.WRITEDATA, buffer)
print("Getting Token...")
c.perform()
status = c.getinfo(c.RESPONSE_CODE)
c.close()

if (status != 200):
sys.exit("Wrong response code received: <" + str(status) + ">")
token_dict = json.loads(buffer.getvalue())
token = token_dict['token']
#print(token)

for image in images_to_update:
docker_path = os.path.join("../", image, docker_subpath)
short_desc = os.path.join(docker_path, short_desc_name)
full_desc = os.path.join(docker_path, full_desc_name)

if (os.path.isfile(short_desc) and os.path.isfile(full_desc)):
with io.open(short_desc,'r',encoding='utf8') as f:
short_desc_content = f.read()
with io.open(full_desc,'r',encoding='utf8') as f:
full_desc_content = f.read()

buffer = BytesIO()
c = pycurl.Curl()
post_data = {}
post_data['description'] = short_desc_content
post_data['full_description'] = full_desc_content
postfields = urlencode(post_data)

c.setopt(c.POSTFIELDS, postfields)
c.setopt(pycurl.CAINFO, certifi.where())
c.setopt(pycurl.CUSTOMREQUEST, "PATCH")
c.setopt(pycurl.HTTPHEADER, ['Authorization: JWT ' + token])
c.setopt(
c.URL, 'https://hub.docker.com/v2/repositories/miguelfc/' + image + "/")
c.setopt(c.WRITEDATA, buffer)
print("Updating description for image <" + image + ">...")
c.perform()
status = c.getinfo(c.RESPONSE_CODE)
c.close()
if (status == 404):
#print (buffer.getvalue())
print("Image not found on Docker Hub: <" + str(status) + ">")
elif (status != 200):
#print (buffer.getvalue())
sys.exit("Wrong response code received: <" + str(status) + ">")

else:
print ("WARNING: Image " + image +
" doesn't have the required description files. Skipping.")

print ("Done.")
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h3>How is this project licensed?</h3>
</div>
<div class="col-sm-6">
<h3>* I'm trying to access the demo but it seems down.</h3>
</p>
<p>Please <a href="https://github.com/miguelfc/marble/issues/new">open an issue</a> on github to let me know.</p>
</div>
</div>
</div> <!-- /container -->
Expand Down
4 changes: 2 additions & 2 deletions marble-preprocessor-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.marble</groupId>
<artifactId>marble-preprocessor-simple</artifactId>
<version>1.0.0-RELEASE</version>
<version>1.0.1-RELEASE</version>
<packaging>jar</packaging>

<parent>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>org.marble</groupId>
<artifactId>marble-model</artifactId>
<version>1.0.0-RELEASE</version>
<version>1.0.1-RELEASE</version>
</dependency>

<dependency>
Expand Down
3 changes: 2 additions & 1 deletion marble-preprocessor-simple/src/main/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Supported tags and respective `Dockerfile` links

- [`1.0.0-RELEASE`, `latest`]
- [`1.0.1-RELEASE`, `latest`]
- [`1.0.0-RELEASE`]

# What is Marble?

Expand Down

0 comments on commit c8ce2b0

Please sign in to comment.