-
Notifications
You must be signed in to change notification settings - Fork 9
v2.1 Add ability to version installations of docker-ce and docker-ce-cli #5
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,25 @@ | |
| from pyinfra.operations import apt, dnf, files, yum | ||
|
|
||
|
|
||
| def _apt_install(): | ||
| DEFAULTS = { | ||
| "docker_version": None, | ||
| } | ||
|
|
||
|
|
||
| def get_pkgs_to_install(): | ||
| docker_packages = [ | ||
| "docker-ce", | ||
| "docker-ce-cli", | ||
| "docker-ce-rootless-extras", | ||
| ] | ||
| if not host.data.docker_version: | ||
| return docker_packages | ||
|
|
||
| return [f"{pkg}={host.data.docker_version}" for pkg in docker_packages] | ||
|
||
|
|
||
|
|
||
|
|
||
| def _apt_install(packages): | ||
| apt.packages( | ||
| name="Install apt requirements to use HTTPS", | ||
| packages=["apt-transport-https", "ca-certificates"], | ||
|
|
@@ -40,12 +58,13 @@ def _apt_install(): | |
|
|
||
| apt.packages( | ||
| name="Install Docker via apt", | ||
| packages="docker-ce", | ||
| packages=packages, | ||
| update=add_apt_repo.changed, # update if we added the repo | ||
| allow_downgrades=True, | ||
| ) | ||
|
|
||
|
|
||
| def _yum_or_dnf_install(yum_or_dnf): | ||
| def _yum_or_dnf_install(yum_or_dnf, packages): | ||
| yum_or_dnf.repo( | ||
| name="Add the Docker yum repo", | ||
| src="https://download.docker.com/linux/centos/docker-ce.repo", | ||
|
|
@@ -60,12 +79,12 @@ def _yum_or_dnf_install(yum_or_dnf): | |
|
|
||
| yum_or_dnf.packages( | ||
| name="Install Docker via yum", | ||
| packages=["docker-ce"], | ||
| packages=packages, | ||
| extra_install_args=extra_install_args, | ||
| ) | ||
|
|
||
|
|
||
| @deploy("Deploy Docker") | ||
| @deploy("Deploy Docker", data_defaults=DEFAULTS) | ||
| def deploy_docker(config=None): | ||
| """ | ||
| Install Docker on the target machine. | ||
|
|
@@ -74,11 +93,13 @@ def deploy_docker(config=None): | |
| config: filename or dict of JSON data | ||
| """ | ||
|
|
||
| packages = get_pkgs_to_install() | ||
| if host.get_fact(DebPackages): | ||
| _apt_install() | ||
| _apt_install(packages) | ||
| elif host.get_fact(RpmPackages): | ||
| _yum_or_dnf_install( | ||
| dnf if host.get_fact(Which, command="dnf") else yum, | ||
| packages, | ||
| ) | ||
| else: | ||
| raise DeployError( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.