Sebarkan Gambar Docker ke Dokku dengan Ansible

gambar


Prolog


Saya baru-baru ini belajar tentang PaaS "saku" yang mirip dengan Heroku dengan nama yang cukup jelas - Dokku. Saya sangat tertarik dengan kemampuan untuk hanya menambahkan sertifikat ke aplikasi dan vhost di luar kotak, jadi saya memutuskan untuk mentransfer gambar buruh pelabuhan saya ke Dokku. Benar, saya kecewa karena di Dokku tidak ada tim seperti 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