ΠΡΠΎΠ»ΠΎΠ³
ΠΠ΅Π΄Π°Π²Π½ΠΎ Ρ ΡΠ·Π½Π°Π» ΠΎ "ΠΊΠ°ΡΠΌΠ°Π½Π½ΠΎΠΌ" PaaS ΠΏΠΎΡ ΠΎΠΆΠ΅ΠΌ Π½Π° Heroku Ρ Π΄ΠΎΠ²ΠΎΠ»ΡΠ½ΠΎ ΠΎΡΠ΅Π²ΠΈΠ΄Π½ΡΠΌ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ΠΌ β Dokku. ΠΡΠ΅Π½Ρ ΠΏΡΠΈΠ²Π»Π΅ΠΊΠ»Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΠΏΡΠΎΡΡΠΎΠ³ΠΎ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ° ΠΊ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΈ vhost ΠΈΠ· ΠΊΠΎΡΠΎΠ±ΠΊΠΈ, ΠΏΠΎΡΡΠΎΠΌΡ Ρ ΡΠ΅ΡΠΈΠ» ΠΏΠ΅ΡΠ΅Π½Π΅ΡΡΠΈ ΡΠ²ΠΎΠΈ docker ΠΎΠ±ΡΠ°Π·Ρ Π½Π° Dokku. ΠΡΠ°Π²Π΄Π°, Ρ Π±ΡΠ» ΡΠ°Π·ΠΎΡΠ°ΡΠΎΠ²Π°Π½ ΡΠ΅ΠΌ, ΡΡΠΎ Π² Dokku Π½Π΅Ρ ΠΊΠΎΠΌΠ°Π½Π΄ ΠΏΠΎΠ΄ΠΎΠ±Π½ΡΡ Heroku
dokku container:push
dokku container:release
// ΠΡΠ΅Π½Ρ Π±ΡΠ»ΠΎ Π±Ρ ΡΠ΄ΠΎΠ±Π½ΠΎ, Π½ΠΎ Π΅ΡΠ΅ Π½Π΅Ρ :(
Π‘ΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ ΠΊΠΎΠΌΠ°Π½Π΄Π° tags
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
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com