dokku / ansible-dokku

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

Add dokku_deploy module #53

Closed decentral1se closed 4 years ago

decentral1se commented 4 years ago

Will aim to get to it if no one else does :sun_with_face:

decentral1se commented 4 years ago

Oh wait, it appears that "dokku clone" does this?

Is this the intended interface for deploying an application?

EDIT: Trying to clone again gives "unchanged" status, so I can't re-deploy the app with this approach?

josegonzalez commented 4 years ago

What exactly are you trying to do?

decentral1se commented 4 years ago

I have a VPS with Dokku configured and I'm creating and deploying a new Keycloak.org instance with Ansible and the Dokku library modules. The final task is "dokku deploy keycloak" where I re-deploy the application to get the mounts in place with the LE certificates.

- hosts: foobar
  tasks:
    - name: Create the Keycloak Dokku application
      dokku_app:
        app: keycloak
      become: true
      become_user: dokku

    - name: Configure the environment
      dokku_config:
        app: keycloak
        config:
          DB_VENDOR: h2
          KEYCLOAK_USER: foo
          KEYCLOAK_PASSWORD:  foo
          PROXY_ADDRESS_FORWARDING: "true"
          DOKKU_LETSENCRYPT_SERVER: staging
      become: true
      become_user: dokku

    - name: Clone the application onto the Dokku host
      dokku_clone:
        app: keycloak
        repository: git@gitlab.com:foo/keycloak.git
      become: true
      become_user: dokku

    - name: Remove default ports proxying
      dokku_ports:
        app: keycloak
        mappings:
          - http:80:5000
        state: absent
      become: true
      become_user: dokku

    - name: Set default HTTP ports proxying for Keycloak
      dokku_ports:
        app: keycloak
        mappings:
          - http:80:8080
        state: present
      become: true
      become_user: dokku

    - name: Setup LE certificates
      shell: dokku letsencrypt keycloak
      args:
        creates: /home/dokku/keycloak/letsencrypt/
      become: true
      become_user: dokku

    - name: Mount LE certificates into the Keycloak container
      dokku_storage:
        app: keycloak
        mounts:
          - "/home/dokku/keycloak/letsencrypt/certs/current/key.pem:/etc/x509/https/tls.key"
          - "/home/dokku/keycloak/letsencrypt/certs/current/cert.pem:/etc/x509/https/tls.crt"
      become: true
      become_user: dokku

    - name: Deploy the application
      shell: dokku deploy keycloak
      become: true
      become_user: dokku
decentral1se commented 4 years ago
    - name: Deploy the application
      shell: dokku deploy keycloak
      become: true
      become_user: dokku

Could be:

- name: Deploy the application
  dokku_deploy:
    app: keycloak
    force: True

Where force makes sure it re-deploys if the app is already deployed. Without force you will get a idempotent task which does nothing.

josegonzalez commented 4 years ago

How would the dokku_deploy resource know an app is deployed?

decentral1se commented 4 years ago

You need to dokku_clone from a Git repo first and then you have it ready to dokku_deploy?

josegonzalez commented 4 years ago

I mean when you don't set force, shouldn't it deploy if it can deploy?

decentral1se commented 4 years ago

If you mount storage then you just want to deploy not flick a config knob as a hack so that it will re-deploy?

josegonzalez commented 4 years ago

I guess what I'm saying is that there isn't a good way to make the module idempotent, so it should just always trigger a deploy if used.

decentral1se commented 4 years ago

Ah right yep, agreed.

decentral1se commented 4 years ago

Looking back at this, I think it's probably just fine to run a command: ... invocation and leave it at that since we know that it will always not be idempotent. I'm gonna close this off.