dokku / ansible-dokku

Ansible modules for installing and configuring Dokku
MIT License
176 stars 44 forks source link

dokku_image: fails when the image is already up to date #156

Closed blockloop closed 1 year ago

blockloop commented 1 year ago

Description of problem

dokku_image does not appear to be idempotent like dokku_app. If you run an ansible play with dokku_image twice then it fails

How reproducible

Every time

Steps to Reproduce

  1. Create a playbook with dokku_image
  2. Run the playbook. The dokku app will be created
  3. Run the playbook again. The dokku_image step will fail if the image hasn't been updated.
    - name: create app
      ignore_errors: true
      dokku_image:
        app: myapp
        image: docker.io/nginx:latest

The problem I think is that the dokku git:from-image command exits with a code of 1 if the image is already up to date

$ dokku git:from-image nginx docker.io/nginx:latest
... pulls image... does update ...
$ echo $?
0
$ dokku git:from-image nginx docker.io/nginx:latest
latest: Pulling from library/nginx
Digest: sha256:46f742f044110785c00a2a64c35e6ca6869ad1ffc3e47ac625b2d5b31c3f2e3d
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
-----> Updating git repository with specified build context
 !     No changes detected, skipping git commit
 !     Call 'ps:rebuild' on app to rebuild the app from existing source
$ echo $?
1

Maybe dokku shouldn't exit 1 when the image is already up to date, but either way it halts the ansible playbook

blockloop commented 1 year ago

Temporary work around

- name: create app
  failed_when: "'error' in image_pull.meta and 'No changes detected, skipping git commit' not in image_pull.meta.error"
  register: image_pull
  dokku_image:
    app: &app nginx
    image: docker.io/nginx