Implemente la imagen de Docker en Dokku con Ansible

imagen


Prólogo


Recientemente me enteré de un PaaS "de bolsillo" similar a Heroku con un nombre bastante obvio: Dokku. Me atrajo mucho la posibilidad de simplemente agregar un certificado a la aplicación y vhost fuera de la caja, así que decidí transferir mis imágenes de Docker a Dokku. Es cierto, me decepcionó que en Dokku no hay equipos como Heroku


dokku container:push
dokku container:release
//    ,    :(

tags , . , image .


tags:create <app> <tag>                        # Add tag to latest running app image
tags:deploy <app> <tag>                        # Deploy tagged app image
tags:destroy <app> <tag>                       # Remove app image tag

Ansible , . dokku, , .


Playbook


playbook , , dokku. Gitlab . .


push-image.dokku.yml


push-image.dokku.yml
---
  - name: "DEPLOY APP '{{ appname }}' TO DOKKU"
    hosts: dokku_hosts
    remote_user: root
    gather_facts: false
    vars:
      tarname: "{{ appname }}__{{ image }}.tar"
      upload_dir: "/usr/local/src"
      upload_path: "{{ upload_dir }}/{{ tarname }}"
      apptag: "{{ upload_tag | default('latest') }}"
      dokku_image: "dokku/{{ appname }}:{{ apptag }}"

    tasks:
      - name: "Archive '{{ image }}' to upload"
        register: env
        delegate_to: localhost
        shell: 
          cmd: docker image save -o "./{{ tarname }}" {{ image }}

      - name: "Upload image '{{ image }}' to dokku at '{{ inventory_hostname }}'"
        register: upload
        copy:
          src: "./{{ tarname }}"
          dest: "{{ upload_path }}"

      - name: "Log - Upload result"
        debug:
          var: upload.dest

      - name: "Restore uploaded docker image"
        register: restore
        shell:
          cmd: docker image load -i "{{ upload_path }}"

      - name: "Log - Restore image"
        debug:
          var: restore.stdout_lines

      - name: "Retag image to '{{ dokku_image }}'"
        shell: 
          cmd: docker tag "{{ image }}" "{{ dokku_image }}"

      - name: "Create dokku tag for '{{ dokku_image }}'"
        shell: 
          cmd: dokku tags:create "{{ appname }}" "{{ apptag }}"

      - name: "Release '{{ appname }}'"
        register: release
        shell: 
          cmd: dokku tags:deploy "{{ appname }}" "{{ apptag }}"  

      - name: "Log - Release"
        debug:
          var: release.stdout_lines  

ansible dokku



ansible-playbook push-image.dokku.yml -i some_inventory -e "appname=DOKKU_APP_NAME image=DOCKER_IMAGE"

some_inventory


[dokku_hosts]
your.domain.example

All Articles