Skip to content

Commit c96b164

Browse files
committed
Fix support for GitHub Envs, allow multiple tags
1 parent acba00a commit c96b164

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

.github/workflows/retag.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
description: "The new tag to apply to the image, example: v1.0.0"
1616
required: true
1717
type: string
18+
environment:
19+
description: "The GitHub Environment to use"
20+
required: true
21+
type: string
1822
secrets:
1923
password:
2024
description: "The password to use for the container registry"
@@ -23,6 +27,7 @@ on:
2327
jobs:
2428
retag:
2529
runs-on: ubuntu-latest
30+
environment: ${{ github.event.inputs.environment }}
2631
steps:
2732
- uses: actions/setup-python@v5
2833
with:

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ tagbot \
1111
--username example \
1212
--password password \
1313
--source example.azurecr.io/debian:latest \
14-
--tag v1.0.0
14+
--tags v1.0.0,1.0.0
1515
```
1616

17-
This would add an additional tag of `v1.0.0` to `example.azurecr.io/debian:latest`. The container image can then be pulled with either `example.azurecr.io/debian:latest`, or `example.azurecr.io/debian:v1.0.0`
17+
This would add an additional tag of `v1.0.0` to `example.azurecr.io/debian:latest`. The container image can then be pulled with either `example.azurecr.io/debian:latest`, `example.azurecr.io/debian:v1.0.0`, or `example.azurecr.io/debian:1.0.0`
1818

1919
### GitHub Actions Usage
2020

@@ -27,19 +27,17 @@ on:
2727

2828
jobs:
2929
release:
30-
name: release
30+
uses: binkhq/tagbot/.github/workflows/retag.yaml@master
31+
with:
32+
username: example
33+
source: example.azurecr.io/${{ github.event.repository.name }}:${{ github.ref_name }}
34+
tags: ${{ matrix.environment }}-v1.0.0,${{ matrix.environment }}
35+
envirnment: ${{ matrix.environment }}
36+
secrets:
37+
password: ${{ secrets.ACR_BINKCORE_PASSWORD }}
3138
strategy:
3239
matrix:
3340
environment: [staging, production]
34-
environment:
35-
name: ${{ matrix.environment }}
36-
uses: binkhq/tagbot/.github/workflows/retag.yaml@master
37-
with:
38-
username: example
39-
source: example.azurecr.io/${{ github.event.repository.name }}:${{ github.ref_name }}
40-
tag: v1.0.0
41-
secrets:
42-
password: ${{ secrets.ACR_PASSWORD }}
4341
```
4442
4543
## FAQ

container_tagbot/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77
from loguru import logger as log
88

99

10-
def tagbot(username: str, password: str, source: str, new_tag: str) -> None:
10+
def tagbot(username: str, password: str, source: str, new_tags: str) -> None:
1111
"""Tag a container image in a registry.
1212
1313
Args:
1414
----
1515
username (str): Username for Container Registry
1616
password (str): Password for Container Registry
1717
source (str): Source Container Image and Tag
18-
new_tag (str): New Container Image Tag
18+
new_tags (str): New Container Image Tags, comma seperated
1919
2020
Returns:
2121
-------
2222
None
2323
"""
2424
registry, image, tag = re.split("[:/]", source)
2525

26-
log.info(f"Tagging {registry}/{image}:{tag} to {registry}/{image}:{new_tag}")
27-
2826
try:
2927
source_image = requests.get(
3028
f"https://{registry}/v2/{image}/manifests/{tag}",
@@ -41,24 +39,26 @@ def tagbot(username: str, password: str, source: str, new_tag: str) -> None:
4139
except requests.exceptions.HTTPError:
4240
log.exception(source_image.text)
4341

44-
try:
45-
dest_image = requests.put(
46-
f"https://{registry}/v2/{image}/manifests/{new_tag}",
47-
headers={"Content-Type": source_image.headers["Content-Type"]},
48-
auth=(username, password),
49-
data=source_image.text,
50-
timeout=30,
51-
)
52-
dest_image.raise_for_status()
53-
except requests.exceptions.HTTPError:
54-
log.exception(dest_image.text)
42+
for new_tag in new_tags.split(","):
43+
log.info(f"Tagging {registry}/{image}:{tag} to {registry}/{image}:{new_tag}")
44+
try:
45+
dest_image = requests.put(
46+
f"https://{registry}/v2/{image}/manifests/{new_tag}",
47+
headers={"Content-Type": source_image.headers["Content-Type"]},
48+
auth=(username, password),
49+
data=source_image.text,
50+
timeout=30,
51+
)
52+
dest_image.raise_for_status()
53+
except requests.exceptions.HTTPError:
54+
log.exception(dest_image.text)
5555

5656

5757
@click.command()
5858
@click.option("--username", "-u", required=True, help="Username for Container Registry")
5959
@click.option("--password", "-p", required=True, help="Password for Container Registry")
6060
@click.option("--source", "-s", required=True, help="Source Container Image")
61-
@click.option("--tag", "-t", required=True, help="New Container Image Tag")
62-
def cli(username: str, password: str, source: str, tag: str) -> None:
61+
@click.option("--tags", "-t", required=True, help="New Container Image Tags, comma seperated")
62+
def cli(username: str, password: str, source: str, tags: str) -> None:
6363
"""Tagbot: Tag a container image in a registry."""
64-
tagbot(username=username, password=password, source=source, new_tag=tag)
64+
tagbot(username=username, password=password, source=source, new_tags=tags)

0 commit comments

Comments
 (0)