mirror of
https://github.com/koodiklinikka/playbooks.git
synced 2026-01-26 03:03:59 +00:00
57 lines
1.9 KiB
YAML
57 lines
1.9 KiB
YAML
---
|
|
|
|
- name: Deploy client from git
|
|
remote_user: "{{ koodiklinikka_tohtori_user }}"
|
|
action: >
|
|
git
|
|
repo="{{ koodiklinikka_tohtori_client_repo }}"
|
|
dest="{{ koodiklinikka_tohtori_app_path }}"
|
|
accept_hostkey=True
|
|
sudo: no
|
|
register: gitclone
|
|
|
|
- name: get previous container
|
|
shell: docker images|grep {{ koodiklinikka_tohtori_container_name }}|grep latest| awk '{print $3}'
|
|
register: current_image_sha
|
|
|
|
- name: Build {{ koodiklinikka_tohtori_container_name }}
|
|
shell: ./build_docker /opt
|
|
args:
|
|
chdir: "{{ koodiklinikka_tohtori_app_path}}/script"
|
|
sudo: yes
|
|
when: gitclone.changed
|
|
register: container
|
|
|
|
- name: tag previous version
|
|
shell: docker tag -f {{ current_image_sha.stdout }} {{ koodiklinikka_tohtori_container_name }}:old
|
|
when: container is defined and container.changed and current_image_sha.stdout != ""
|
|
|
|
- name: get running container
|
|
shell: docker ps |grep {{ koodiklinikka_tohtori_container_name }}| awk '{print $1}'
|
|
register: current_container_id
|
|
|
|
- name: kill old version
|
|
shell: docker stop {{ koodiklinikka_tohtori_container_name }}
|
|
when: container is defined and container.changed and current_container_id.stdout != ""
|
|
|
|
- name: get old containers
|
|
shell: docker ps -a|grep Exited| awk '{print $1}'
|
|
register: old_containers
|
|
|
|
- name: clean old containers
|
|
shell: docker rm $(docker ps -a|grep Exited| awk '{print $1}')
|
|
when: old_containers.stdout != ""
|
|
|
|
- name: Start the container
|
|
shell: docker run --restart=always -d --name {{ koodiklinikka_tohtori_container_name }} {{ koodiklinikka_tohtori_container_name }}:latest
|
|
when: container is defined and container.changed
|
|
|
|
- name: get old images
|
|
shell: docker images | grep "^<none>" | awk '{print $3}'
|
|
register: old_images
|
|
|
|
- name: clean untagged (old) images
|
|
shell: docker rmi $(docker images -a | grep "^<none>" | awk '{print $3}')
|
|
when: old_images.stdout != ""
|
|
ignore_errors: yes
|