Skip to content

Commit

Permalink
enhancement sidecar container update_image
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanuduplo committed Feb 5, 2025
1 parent 43bb4a3 commit 930d8ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Added enhancements to the start/stop service to select all services or specific ones.
- Added enhancement to update_image service to also update the sidecar container image.

## [0.2.44] - 2025-01-22

Expand Down
16 changes: 11 additions & 5 deletions src/duplo_resource/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,38 +222,44 @@ def update_replicas(self,
@Command()
def update_image(self,
name: args.NAME,
container: args.CONTAINER = None,
image: args.IMAGE = None,
container: args.CONTAINER = None,
container_image: args.CONTAINER_IMAGE = None,
wait: args.WAIT = False) -> dict:
"""Update the image of a service.
Update the image of a service.
Usage: Basic CLI Use
```sh
duploctl service update_image <service-name> <image-name>
duploctl service update_image <service-name> --container <side-car-container> <image-name>
duploctl service update_image <service-name> <service-image>
duploctl service update_image <service-name> --container <side-car-container> --container-image <container-image>
```
Args:
name: The name of the service to update.
image: The new image to use for the service.
container: The name of the sidecar container to update image.
container_image: The new image of the sidecar container to update.
wait: Whether to wait for the update to complete.
Returns:
message: Success message
"""
if (image and (container or container_image)) or (not image and (container is None or container_image is None)):
return {"error": "Provide either <service-image> OR both --container <container-name> and --container-image <container-image>, but not both."}

service = self.find(name)
data = {}

if container:
if container and container_image:
other_docker_config = loads(service["Template"]["OtherDockerConfig"])
additional_containers = other_docker_config.get("additionalContainers", [])

container_found = False
for c in additional_containers:
if c["name"] == container:
c["image"] = image
c["image"] = container_image
container_found = True
break

Expand Down
4 changes: 4 additions & 0 deletions src/duplocloud/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
help='The resource name')

IMAGE = Arg("image",
nargs='?',
help='The image to use')

S3BUCKET = Arg("bucket",
Expand All @@ -170,6 +171,9 @@
CONTAINER = Arg("container", "--container", "-C",
help='The side-car container name')

CONTAINER_IMAGE = Arg("container-image", "--container-image",
help='The side-car container image')

EXTERNAL_PORT = Arg("external-port", "--external-port",
help='The external port')

Expand Down

0 comments on commit 930d8ea

Please sign in to comment.