Skip to content

operations.docker: add support for custom command#1625

Open
EricDriussi wants to merge 1 commit intopyinfra-dev:3.xfrom
EricDriussi:3.x
Open

operations.docker: add support for custom command#1625
EricDriussi wants to merge 1 commit intopyinfra-dev:3.xfrom
EricDriussi:3.x

Conversation

@EricDriussi
Copy link
Copy Markdown
Contributor

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)

Hi there! Noticed another thing missing from the docker container operation.
This adds support for custom commands to be run on container start.

Copy link
Copy Markdown
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @EricDriussi sorry for the delay - this looks great, a couple of minor tweaks to the arguments + fix for default / no argument.

restart_policy: str | None = None
auto_remove: bool = False
dns: list[str] = field(default_factory=list)
command: str = ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
command: str = ""
command: str | None = None

args.append("--dns {0}".format(dns))

args.append(self.image)
args.append(self.command)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.append(self.command)
if self.command:
args.append(self.command)

docker.container(
name="Run a custom command",
container="alpine",
command="sh -c 'echo Whatever you want",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
command="sh -c 'echo Whatever you want",
command="sh -c "echo Whatever you want",

restart_policy: str | None = None,
auto_remove: bool = False,
dns: list[str] | None = None,
command: str = "",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is a nicer default here

Suggested change
command: str = "",
command: str | None = None,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants