Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish the tag latest #210

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ versions:
The config is like this:

```yaml
latest: True
images:
- name: # The base name of the image we want to publish
repository:
Expand All @@ -143,4 +144,7 @@ repository:
# and publish them with `c2cciutils-publish --group=<group>`
```

By default the last line of the `SECURITY.md` file will be published (`docker`) with the tag
`latest`. Set `latest` to `False` to disable it.

With the `c2cciutils-clean` the images on Docker hub for `feature_branch` will be removed on branch removing.
1 change: 1 addition & 0 deletions c2cciutils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class Publish(TypedDict, total=False):
#
# The configuration used to publish on Docker
class PublishDockerConfig(TypedDict, total=False):
latest: bool
images: List["PublishDockerImage"]
repository: Dict[str, "PublishDockerRepository"]

Expand Down
45 changes: 34 additions & 11 deletions c2cciutils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

import c2cciutils
import c2cciutils.configuration


Expand Down Expand Up @@ -208,7 +207,7 @@ def main_calendar() -> None:
Run the calendar main function.
"""
parser = argparse.ArgumentParser(
description="Interact with google API for the docker publishing calendar"
description="Interact with google API for the Docker publishing calendar"
)
parser.add_argument(
"--refresh-gopass-credentials",
Expand Down Expand Up @@ -292,9 +291,10 @@ def docker(
image_config: c2cciutils.configuration.PublishDockerImage,
tag_src: str,
tag_dst: str,
latest: bool,
) -> bool:
"""
Publish to a docker registry.
Publish to a Docker registry.

config is like:
server: # The server fqdn
Expand All @@ -308,6 +308,7 @@ def docker(
image_config: The image config
tag_src: The source tag (usually latest)
tag_dst: The tag used for publication
latest: Publish also the tag latest
"""

print("::group::Publishing {}:{} to {}".format(image_config["name"], tag_dst, name))
Expand All @@ -316,38 +317,60 @@ def docker(

try:
if "server" in config:
subprocess.check_call(
subprocess.run(
[
"docker",
"tag",
"{}:{}".format(image_config["name"], tag_src),
"{}/{}:{}".format(config["server"], image_config["name"], tag_dst),
]
],
check=True,
)
subprocess.check_call(
subprocess.run(
[
"docker",
"push",
"{}/{}:{}".format(config["server"], image_config["name"], tag_dst),
]
],
check=True,
)
if latest:
subprocess.run(
[
"docker",
"push",
"{}/{}:{}".format(config["server"], image_config["name"], tag_src),
],
check=True,
)
else:
if tag_src != tag_dst:
subprocess.check_call(
subprocess.run(
[
"docker",
"tag",
"{}:{}".format(image_config["name"], tag_src),
"{}:{}".format(image_config["name"], tag_dst),
]
],
check=True,
)
subprocess.check_call(
subprocess.run(
[
"docker",
"push",
"{}:{}".format(image_config["name"], tag_dst),
]
],
check=True,
)
if latest:
subprocess.run(
[
"docker",
"push",
"{}:{}".format(image_config["name"], tag_src),
],
check=True,
)
print("::endgroup::")
except subprocess.CalledProcessError as exception:
print(f"Error: {exception}")
Expand Down
5 changes: 5 additions & 0 deletions c2cciutils/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@
"description": "The configuration used to publish on Docker",
"type": "object",
"properties": {
"latest": {
"description": "Publish the latest version on tag latest",
"default": true,
"type": "boolean"
},
"images": {
"description": "List of images to be published",
"type": "array",
Expand Down
13 changes: 12 additions & 1 deletion c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import c2cciutils.configuration
import c2cciutils.publish
import c2cciutils.security
from c2cciutils.publish import GoogleCalendar


Expand Down Expand Up @@ -169,6 +170,14 @@ def main() -> None:
if config.get("publish", {}).get("google_calendar", False)
else {},
)

latest = False
if os.path.exists("SECURITY.md") and docker_config["latest"] is True:
with open("SECURITY.md") as security_file:
security = c2cciutils.security.Security(security_file.read())
version_index = security.headers.index("Version")
latest = security.data[-1][version_index] == version

for image_conf in docker_config.get("images", []):
if image_conf.get("group", "") == args.group:
for tag_config in image_conf.get("tags", []):
Expand All @@ -183,7 +192,9 @@ def main() -> None:
)
)
else:
success &= c2cciutils.publish.docker(conf, name, image_conf, tag_src, tag_dst)
success &= c2cciutils.publish.docker(
conf, name, image_conf, tag_src, tag_dst, latest
)
if version_type in google_calendar_config.get("on", []):
if not google_calendar:
google_calendar = GoogleCalendar()
Expand Down