-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Clean docker hub tags | ||
|
||
on: delete | ||
|
||
jobs: | ||
clean: | ||
runs-on: ubuntu-18.04 | ||
name: Clean docker hub tags | ||
env: | ||
SUMMON_PROVIDER: /usr/local/bin/gopass | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: camptocamp/initialise-gopass-summon-action@v1 | ||
with: | ||
ci-gpg-private-key: ${{secrets.CI_GPG_PRIVATE_KEY}} | ||
github-gopass-ci-token: ${{secrets.GITHUB_GOPASS_CI_TOKEN}} | ||
- name: Clean docker hub tags | ||
run: | | ||
summon --yaml ' | ||
USERNAME: !var gs/ci/dockerhub/username | ||
PASSWORD: !var gs/ci/dockerhub/password | ||
' scripts/clean-dockerhub-tag |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
import requests | ||
|
||
|
||
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"]}), | ||
).json()["token"] | ||
|
||
with open(os.environ["GITHUB_EVENT_PATH"]) as event_file: | ||
ref = json.loads(event_file.read())["ref"] | ||
|
||
ref = ref.replace("/", "_") | ||
|
||
print("Delete image 'camptocamp/c2cwsgiutils:{}'.".format(ref)) | ||
|
||
response = requests.head( | ||
"https://hub.docker.com/v2/repositories/camptocamp/c2cwsgiutils/tags/{tag}/".format(tag=ref), | ||
headers={"Authorization": "JWT " + token}, | ||
) | ||
if response.status_code == 404: | ||
return | ||
if not response.ok: | ||
print("Error checking image 'camptocamp/c2cwsgiutils:{}' status.".format(ref)) | ||
print(response.text) | ||
sys.exit(2) | ||
|
||
response = requests.delete( | ||
"https://hub.docker.com/v2/repositories/camptocamp/c2cwsgiutils/tags/{tag}/".format(tag=ref), | ||
headers={"Authorization": "JWT " + token}, | ||
) | ||
if not response.ok: | ||
print("Error on deleting tag: " + ref) | ||
print(response.text) | ||
sys.exit(2) | ||
|
||
|
||
clean() |