
Prologue
J'ai récemment découvert un PaaS "de poche" similaire à Heroku avec un nom assez évident - Dokku. J'ai été très attiré par la possibilité d'ajouter simplement un certificat à l'application et de vhost hors de la boîte, j'ai donc décidé de transférer mes images de docker vers Dokku. C'est vrai, j'ai été déçu qu'à Dokku il n'y ait pas d'équipes comme 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---
- 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