Last active
May 18, 2020 12:20
-
-
Save richbruce/b217f1e359fd445e12b670c35be40113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Gets most recent version from dockerhub then creates and pushes the next version tag to dockerhub | |
''' | |
import requests as rq | |
import os | |
# import json | |
import subprocess | |
DOCKER_TOKEN = os.getenv('DOCKER_TOKEN') | |
DOCKER_USERNAME = os.getenv('DOCKER_USERNAME') | |
DOCKER_IMAGE_NAME = os.getenv('DOCKER_IMAGE_NAME') | |
# headers = {'Content-Type: application/json'} | |
creds = {"username": DOCKER_USERNAME, "password": DOCKER_TOKEN} | |
response = rq.post('https://hub.docker.com/v2/users/login', json=creds) | |
token = response.json()['token'] | |
header = {"Authorization": f"JWT {token}"} | |
tags = rq.get( | |
'https://registry.hub.docker.com/v2/repositories/richbruce/base_api/tags', headers=header) | |
jtags = tags.json() | |
# fjtags = json.dumps(jtags, indent=2) | |
# print(fjtags) | |
tag_names = [float(tag['name'].replace('v', '')) | |
for tag in jtags['results'] if tag['name'] != 'testing'] | |
tag_names.sort(reverse=True) | |
latest_version = tag_names[0] | |
new_version = str(round(latest_version + .01, 2)) | |
subprocess.run( | |
f'docker tag {DOCKER_USERNAME}/{DOCKER_IMAGE_NAME}:testing {DOCKER_USERNAME}/{DOCKER_IMAGE_NAME}:v{new_version}', shell=True) | |
subprocess.run( | |
f'docker push {DOCKER_USERNAME}/{DOCKER_IMAGE_NAME}:v{new_version}', shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment