Skip to content

Commit

Permalink
Merge pull request #750 from camptocamp/fix-publish2
Browse files Browse the repository at this point in the history
Fix the Docker publishing
  • Loading branch information
sbrunner authored Sep 29, 2022
2 parents 85eb45d + 4a700c0 commit 6c14822
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 38 deletions.
21 changes: 0 additions & 21 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,27 +270,6 @@ def get_config(branch: Optional[str] = None) -> c2cciutils.configuration.Configu
config.get("checks", {}).get("required_workflows", {}),
)

if config["publish"].get("docker", False):
assert isinstance(config["publish"]["docker"], dict)
config["publish"]["docker"].setdefault("latest", True)
for image in config["publish"]["docker"]["images"]:
merge(
{
"tags": ["{version}"],
"group": "default",
},
image,
)
if config["publish"].get("pypi", False):
assert isinstance(config["publish"]["pypi"], dict)
for package in config["publish"]["pypi"]["packages"]:
merge(
{
"group": "default",
},
package,
)

return validate_config(config, "ci/config.yaml")


Expand Down
56 changes: 45 additions & 11 deletions c2cciutils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
# Default value of the field path 'Publish Docker config repository'
DOCKER_REPOSITORY_DEFAULT = {
"github": {"server": "ghcr.io", "versions": ["version_tag", "version_branch", "rebuild"]},
"dockerhub": {"versions": ["version_tag", "version_branch", "rebuild", "feature_branch"]},
"dockerhub": {},
}


Expand Down Expand Up @@ -634,6 +634,22 @@
}


# Default value of the field path 'Publish Docker image group'
PUBLISH_DOCKER_IMAGE_GROUP_DEFAULT = "default"


# Default value of the field path 'Publish Docker image tags'
PUBLISH_DOCKER_IMAGE_TAGS_DEFAULT = ["{version}"]


# Default value of the field path 'Publish Docker config latest'
PUBLISH_DOCKER_LATEST_DEFAULT = True


# Default value of the field path 'Publish Docker repository versions'
PUBLISH_DOCKER_REPOSITORY_VERSIONS_DEFAULT = ["version_tag", "version_branch", "rebuild", "feature_branch"]


# Default value of the field path 'Publish google_calendar'
PUBLISH_GOOGLE_CALENDAR_DEFAULT: Dict[str, Any] = {}

Expand All @@ -642,6 +658,10 @@
PUBLISH_GOOGLE_CALENDAR_ON_DEFAULT = ["version_branch", "version_tag", "rebuild"]


# Default value of the field path 'publish pypi package group'
PUBLISH_PIP_PACKAGE_GROUP_DEFAULT = "default"


# Default value of the field path 'Publish pypi'
PUBLISH_PYPI_DEFAULT: Dict[str, Any] = {}

Expand Down Expand Up @@ -722,6 +742,8 @@
PublishDockerConfig = TypedDict(
"PublishDockerConfig",
{
# Publish Docker latest
#
# Publish the latest version on tag latest
#
# default: True
Expand All @@ -733,12 +755,7 @@
# The repository where we should publish the images
#
# default:
# dockerhub:
# versions:
# - version_tag
# - version_branch
# - rebuild
# - feature_branch
# dockerhub: {}
# github:
# server: ghcr.io
# versions:
Expand All @@ -762,11 +779,20 @@
PublishDockerImage = TypedDict(
"PublishDockerImage",
{
# Publish Docker image group
#
# The image is in the group, should be used with the --group option of c2cciutils-publish script
#
# default: default
"group": str,
# The image name
"name": str,
# publish docker image tags
#
# The tag name, will be formatted with the version=<the version>, the image with version=latest should be present when we call the c2cciutils-publish script
#
# default:
# - '{version}'
"tags": List[str],
},
total=False,
Expand All @@ -779,7 +805,15 @@
{
# The server URL
"server": str,
# Publish Docker repository versions
#
# The kind or version that should be published, tag, branch or value of the --version argument of the c2cciutils-publish script
#
# default:
# - version_tag
# - version_branch
# - rebuild
# - feature_branch
"versions": List[str],
},
total=False,
Expand Down Expand Up @@ -870,7 +904,11 @@
PublishPypiPackage = TypedDict(
"PublishPypiPackage",
{
# Publish pip package group
#
# The image is in the group, should be used with the --group option of c2cciutils-publish script
#
# default: default
"group": str,
# The path of the pypi package
"path": str,
Expand Down Expand Up @@ -1086,10 +1124,6 @@
_PUBLISH_DOCKER_CONFIG_DISPATCH_DEFAULT: Dict[str, Any] = {}


# Default value of the field path 'Publish Docker config latest'
_PUBLISH_DOCKER_CONFIG_LATEST_DEFAULT = True


_PrintVersionsVersionsItem = TypedDict(
"_PrintVersionsVersionsItem",
{
Expand Down
11 changes: 10 additions & 1 deletion c2cciutils/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
"properties": {
"latest": {
"description": "Publish the latest version on tag latest",
"title": "Publish Docker latest",
"default": true,
"type": "boolean"
},
Expand All @@ -513,6 +514,8 @@
"properties": {
"group": {
"description": "The image is in the group, should be used with the --group option of c2cciutils-publish script",
"title": "Publish Docker image group",
"default": "default",
"type": "string"
},
"name": {
Expand All @@ -521,7 +524,9 @@
},
"tags": {
"description": "The tag name, will be formatted with the version=<the version>, the image with version=latest should be present when we call the c2cciutils-publish script",
"title": "publish docker image tags",
"type": "array",
"default": ["{version}"],
"items": {
"type": "string"
}
Expand All @@ -537,7 +542,7 @@
"server": "ghcr.io",
"versions": ["version_tag", "version_branch", "rebuild"]
},
"dockerhub": { "versions": ["version_tag", "version_branch", "rebuild", "feature_branch"] }
"dockerhub": {}
},
"type": "object",
"additionalProperties": {
Expand All @@ -550,7 +555,9 @@
},
"versions": {
"description": "The kind or version that should be published, tag, branch or value of the --version argument of the c2cciutils-publish script",
"title": "Publish Docker repository versions",
"type": "array",
"default": ["version_tag", "version_branch", "rebuild", "feature_branch"],
"items": {
"type": "string"
}
Expand Down Expand Up @@ -632,6 +639,8 @@
"properties": {
"group": {
"description": "The image is in the group, should be used with the --group option of c2cciutils-publish script",
"title": "Publish pip package group",
"default": "default",
"type": "string"
},
"path": {
Expand Down
23 changes: 18 additions & 5 deletions c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def main() -> None:
)
if pypi_config:
for package in pypi_config["packages"]:
if package.get("group") == args.group:
if package.get("group", c2cciutils.configuration.PUBLISH_PIP_PACKAGE_GROUP_DEFAULT) == args.group:
publish = version_type in pypi_config.get("versions", [])
if args.dry_run:
print(
Expand Down Expand Up @@ -193,16 +193,24 @@ def main() -> None:
headers=c2cciutils.add_authorization_header({}),
timeout=int(os.environ.get("C2CCIUTILS_TIMEOUT", "30")),
)
if security_response.ok and docker_config["latest"] is True:
if (
security_response.ok
and docker_config.get("latest", c2cciutils.configuration.PUBLISH_DOCKER_LATEST_DEFAULT) is True
):
security = c2cciutils.security.Security(security_response.text)
version_index = security.headers.index("Version")
latest = security.data[-1][version_index] == version

images_src: Set[str] = set()
images_full: List[str] = []
for image_conf in docker_config.get("images", []):
if image_conf.get("group", "") == args.group:
for tag_config in image_conf.get("tags", []):
if (
image_conf.get("group", c2cciutils.configuration.PUBLISH_DOCKER_IMAGE_GROUP_DEFAULT)
== args.group
):
for tag_config in image_conf.get(
"tags", c2cciutils.configuration.PUBLISH_DOCKER_IMAGE_TAGS_DEFAULT
):
tag_src = tag_config.format(version="latest")
images_src.add(f"{image_conf['name']}:{tag_src}")
tag_dst = tag_config.format(version=version)
Expand All @@ -213,7 +221,9 @@ def main() -> None:
c2cciutils.configuration.DOCKER_REPOSITORY_DEFAULT,
),
).items():
if version_type in conf.get("versions", []):
if version_type in conf.get(
"versions", c2cciutils.configuration.PUBLISH_DOCKER_REPOSITORY_VERSIONS_DEFAULT
):
if args.dry_run:
print(
f"Publishing {image_conf['name']}:{tag_dst} to {name}, "
Expand Down Expand Up @@ -242,6 +252,9 @@ def main() -> None:

google_calendar.create_event(summary, description)

if args.dry_run:
sys.exit(0)

dispatch_config = docker_config.get("dispatch", {})
if dispatch_config and images_full:
dispatch(
Expand Down

0 comments on commit 6c14822

Please sign in to comment.