Skip to content

Commit

Permalink
Fix reading existing dokku docker options (#146)
Browse files Browse the repository at this point in the history
* Fix reading existing dokku docker options

* Add test for dokku_docker_options
  • Loading branch information
erikvdv1 authored Oct 17, 2022
1 parent 7edd059 commit fb8174f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
22 changes: 9 additions & 13 deletions library/dokku_docker_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ansible.module_utils.dokku_utils import subprocess_check_output
import pipes
import subprocess
import re

DOCUMENTATION = """
---
Expand Down Expand Up @@ -57,22 +58,17 @@


def dokku_docker_options(data):
options = {"build": [], "deploy": [], "run": []}
command = "dokku --quiet docker-options {0}".format(data["app"])
options = {"build": "", "deploy": "", "run": ""}
command = "dokku --quiet docker-options:report {0}".format(data["app"])
output, error = subprocess_check_output(command)
if error is None:
_type = "build"
for line in output:
if line == "Build options:":
_type = "build"
continue
elif line == "Deploy options:":
_type = "deploy"
continue
elif line == "Run options:":
_type = "run"
continue
options[_type].append(line)
match = re.match(
"Docker options (?P<type>build|deploy|run):(?P<options>.+)",
line.strip(),
)
if match:
options[match.group("type")] = match.group("options").strip()
return options, error


Expand Down
52 changes: 52 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,55 @@
msg: |-
checks were not enabled in output of 'dokku checks':
{{ dokku_checks.stdout }}
# Testing dokku_docker_options
- name: Set docker build options
dokku_docker_options:
app: example-app
phase: build
option: "--pull"

- name: Get docker-options output # noqa 301
command: dokku docker-options:report example-app
register: dokku_docker_options

- name: Check that the docker options were set
assert:
that:
- "'--pull' in dokku_docker_options.stdout"
msg: |-
docker option '--pull' was not set in output of 'dokku docker-options':
{{ dokku_docker_options.stdout }}
- name: Set docker build options that already exist # noqa 301
dokku_docker_options:
app: example-app
phase: build
option: "--pull"
register: existing_docker_options

- name: Check that setting existing docker options did not change anything
assert:
that:
- not existing_docker_options.changed
msg: |
Setting existing docker options resulted in changed status
- name: Remove docker build options
dokku_docker_options:
app: example-app
phase: build
option: "--pull"
state: absent

- name: Get docker-options output # noqa 301
command: dokku docker-options:report example-app
register: dokku_docker_options

- name: Check that the docker options were removed
assert:
that:
- "'--pull' not in dokku_docker_options.stdout"
msg: |-
docker option '--pull' was not removed in output of 'dokku docker-options':
{{ dokku_docker_options.stdout }}

0 comments on commit fb8174f

Please sign in to comment.