Skip to content

Commit

Permalink
Merge pull request #56 from camptocamp/less-error
Browse files Browse the repository at this point in the history
No error on removing unexisting tag
  • Loading branch information
sbrunner authored Mar 9, 2020
2 parents e33ba32 + f05dc61 commit 8df5ce1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions ci/clean-dockerhub-tag
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@

import json
import os
import re
import subprocess
import sys

import requests


def clean(tag_=lambda tag: tag):
def clean():
token = requests.post(
"https://hub.docker.com/v2/users/login/",
headers={"Content-Type": "application/json"},
data=json.dumps(
{"username": os.environ["USERNAME"], "password": os.environ["PASSWORD"]}
),
data=json.dumps({"username": os.environ["USERNAME"], "password": os.environ["PASSWORD"]}),
).json()["token"]

with open(os.environ["GITHUB_EVENT_PATH"]) as event_file:
ref = json.loads(event_file.read())["ref"]
ref = json.loads(event_file.read())["ref"].replace("/", "_")

print("Delete image 'camptocamp/mapserver:{}'.".format(ref))

response = requests.head(
"https://hub.docker.com/v2/repositories/camptocamp/mapserver/tags/{tag}/".format(tag=ref),
headers={"Authorization": "JWT " + token},
)
if response.status_code == 404:
return
if not response.ok:
print("Error checking image 'camptocamp/mapserver:{}' status.".format(ref))
print(response.text)
sys.exit(2)

response = requests.delete(
"https://hub.docker.com/v2/repositories/camptocamp/mapserver/tags/{tag}/".format(tag=ref,),
"https://hub.docker.com/v2/repositories/camptocamp/mapserver/tags/{tag}/".format(tag=ref),
headers={"Authorization": "JWT " + token,},
)
if not response.ok:
Expand Down

0 comments on commit 8df5ce1

Please sign in to comment.