mirror of
https://github.com/koodiklinikka/playbooks.git
synced 2026-01-26 03:03:59 +00:00
remove duplication from deploy
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy api
|
- name: Deploy api
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/koodiklinikka.fi-api/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/koodiklinikka.fi-api/tasks/main.yml
|
- { include: roles/deploy/tasks/deploy.yml,
|
||||||
|
container_name: koodiklinikka.fi-api,
|
||||||
|
repository_url: 'git@github.com:koodiklinikka/koodiklinikka.fi-api.git',
|
||||||
|
port: 9000,
|
||||||
|
app_path: /opt/web/koodiklinikka.fi-api,
|
||||||
|
user: web }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy front
|
- name: Deploy front
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/koodiklinikka.fi-front/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/koodiklinikka.fi-front/tasks/main.yml
|
- { include: roles/deploy/tasks/deploy.yml,
|
||||||
|
container_name: koodiklinikka.fi-front,
|
||||||
|
repository_url: 'git@github.com:koodiklinikka/koodiklinikka.fi.git',
|
||||||
|
port: 8000,
|
||||||
|
app_path: /opt/web/koodiklinikka.fi-front,
|
||||||
|
user: web }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy tohtori
|
- name: Deploy tohtori
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/tohtori/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/tohtori/tasks/build.yml
|
- { include: roles/deploy/tasks/deploy.yml,
|
||||||
|
container_name: tohtori,
|
||||||
|
repository_url: 'git@github.com:koodiklinikka/tohtori.git',
|
||||||
|
port: 6666,
|
||||||
|
app_path: /opt/tohtori/tohtori,
|
||||||
|
user: web }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy client from git
|
- name: Deploy client from git
|
||||||
remote_user: "{{ koodiklinikka_user }}"
|
remote_user: "{{ user }}"
|
||||||
action: >
|
action: >
|
||||||
git
|
git
|
||||||
repo="{{ koodiklinikka_repository_url }}"
|
repo="{{ repository_url }}"
|
||||||
dest="{{ koodiklinikka_app_path }}"
|
dest="{{ app_path }}"
|
||||||
accept_hostkey=True
|
accept_hostkey=True
|
||||||
sudo: no
|
sudo: no
|
||||||
register: gitclone
|
register: gitclone
|
||||||
|
|
||||||
- name: get previous container
|
- name: get previous container
|
||||||
shell: docker images|grep {{ koodiklinikka_container_name }}|grep latest| awk '{print $3}'
|
shell: docker images|grep {{ container_name }}|grep latest| awk '{print $3}'
|
||||||
register: current_image_sha
|
register: current_image_sha
|
||||||
|
|
||||||
- name: Build {{ koodiklinikka_container_name }}
|
- name: Build {{ container_name }}
|
||||||
shell: ./build_docker
|
shell: ./build_docker
|
||||||
args:
|
args:
|
||||||
chdir: "{{ koodiklinikka_app_path}}"
|
chdir: "{{ app_path}}"
|
||||||
sudo: yes
|
sudo: yes
|
||||||
when: gitclone.changed
|
when: gitclone.changed
|
||||||
register: container
|
register: container
|
||||||
|
|
||||||
- name: tag previous version
|
- name: tag previous version
|
||||||
shell: docker tag -f {{ current_image_sha.stdout }} {{ koodiklinikka_container_name }}:old
|
shell: docker tag -f {{ current_image_sha.stdout }} {{ container_name }}:old
|
||||||
when: container is defined and container.changed and current_image_sha.stdout != ""
|
when: container is defined and container.changed and current_image_sha.stdout != ""
|
||||||
|
|
||||||
- name: get running container
|
- name: get running container
|
||||||
shell: docker ps |grep {{ koodiklinikka_container_name }}| awk '{print $1}'
|
shell: docker ps |grep {{ container_name }}| awk '{print $1}'
|
||||||
register: current_container_id
|
register: current_container_id
|
||||||
|
|
||||||
- name: kill old version
|
- name: kill old version
|
||||||
shell: docker stop {{ koodiklinikka_container_name }}
|
shell: docker stop {{ container_name }}
|
||||||
when: container is defined and container.changed and current_container_id.stdout != ""
|
when: container is defined and container.changed and current_container_id.stdout != ""
|
||||||
|
|
||||||
- name: get old containers
|
- name: get old containers
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
when: old_containers.stdout != ""
|
when: old_containers.stdout != ""
|
||||||
|
|
||||||
- name: Start the container
|
- name: Start the container
|
||||||
shell: docker run --restart=always -p 127.0.0.1:{{ koodiklinikka_port }}:{{ koodiklinikka_port }} -d --name {{ koodiklinikka_container_name }} {{ koodiklinikka_container_name }}:latest
|
shell: docker run --restart=always -p 127.0.0.1:{{ port }}:{{ port }} -d --name {{ container_name }} {{ container_name }}:latest
|
||||||
when: container is defined and container.changed
|
when: container is defined and container.changed
|
||||||
|
|
||||||
- name: get old images
|
- name: get old images
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: get running container
|
- name: get running container
|
||||||
shell: docker ps -a|grep {{ koodiklinikka_container_name }}|grep latest| awk '{print $1}'
|
shell: docker ps -a|grep {{ container_name }}|grep latest| awk '{print $1}'
|
||||||
register: current_container_id
|
register: current_container_id
|
||||||
|
|
||||||
- name: kill old version
|
- name: kill old version
|
||||||
shell: docker stop {{ koodiklinikka_container_name }}
|
shell: docker stop {{ container_name }}
|
||||||
when: current_container_id != ""
|
when: current_container_id != ""
|
||||||
|
|
||||||
- name: get old containers
|
- name: get old containers
|
||||||
@@ -17,5 +17,5 @@
|
|||||||
when: old_containers.stdout != ""
|
when: old_containers.stdout != ""
|
||||||
|
|
||||||
- name: Start the container
|
- name: Start the container
|
||||||
shell: docker run -d --name {{ koodiklinikka_container_name }} {{ koodiklinikka_container_name }}:old
|
shell: docker run -d --name {{ container_name }} {{ container_name }}:old
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
koodiklinikka_api_container_name: koodiklinikka.fi-api
|
|
||||||
koodiklinikka_api_repository_url: git@github.com:koodiklinikka/koodiklinikka.fi-api.git
|
|
||||||
koodiklinikka_api_port: 9000
|
|
||||||
|
|
||||||
koodiklinikka_api_app_path: /opt/web/koodiklinikka.fi-api
|
|
||||||
koodiklinikka_api_user: web
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Deploy client from git
|
|
||||||
remote_user: "{{ koodiklinikka_api_user }}"
|
|
||||||
action: >
|
|
||||||
git
|
|
||||||
repo="{{ koodiklinikka_api_repository_url }}"
|
|
||||||
dest="{{ koodiklinikka_api_app_path }}"
|
|
||||||
accept_hostkey=True
|
|
||||||
sudo: no
|
|
||||||
register: gitclone
|
|
||||||
|
|
||||||
- name: get previous container
|
|
||||||
shell: docker images|grep {{ koodiklinikka_api_container_name }}|grep latest| awk '{print $3}'
|
|
||||||
register: current_image_sha
|
|
||||||
|
|
||||||
- name: Build {{ koodiklinikka_api_container_name }}
|
|
||||||
shell: ./build_docker /opt
|
|
||||||
args:
|
|
||||||
chdir: "{{ koodiklinikka_api_app_path}}"
|
|
||||||
sudo: yes
|
|
||||||
when: gitclone.changed
|
|
||||||
register: container
|
|
||||||
|
|
||||||
- name: tag previous version
|
|
||||||
shell: docker tag -f {{ current_image_sha.stdout }} {{ koodiklinikka_api_container_name }}:old
|
|
||||||
when: container is defined and container.changed and current_image_sha.stdout != ""
|
|
||||||
|
|
||||||
- name: get running container
|
|
||||||
shell: docker ps |grep {{ koodiklinikka_api_container_name }}| awk '{print $1}'
|
|
||||||
register: current_container_id
|
|
||||||
|
|
||||||
- name: kill old version
|
|
||||||
shell: docker stop {{ koodiklinikka_api_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 -p 127.0.0.1:{{ koodiklinikka_api_port }}:{{ koodiklinikka_api_port }} -d --name {{ koodiklinikka_api_container_name }} {{ koodiklinikka_api_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
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: get running container
|
|
||||||
shell: docker ps -a|grep {{ koodiklinikka_api_container_name }}|grep latest| awk '{print $1}'
|
|
||||||
register: current_container_id
|
|
||||||
|
|
||||||
- name: kill old version
|
|
||||||
shell: docker stop {{ koodiklinikka_api_container_name }}
|
|
||||||
when: current_container_id != ""
|
|
||||||
|
|
||||||
- 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 -d --name {{ koodiklinikka_api_container_name }} {{ koodiklinikka_api_container_name }}:old
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
koodiklinikka_container_name: koodiklinikka.fi-front
|
|
||||||
koodiklinikka_repository_url: git@github.com:koodiklinikka/koodiklinikka.fi.git
|
|
||||||
koodiklinikka_port: 8000
|
|
||||||
|
|
||||||
koodiklinikka_app_path: /opt/web/koodiklinikka.fi-front
|
|
||||||
koodiklinikka_nvm_script: /opt/web/nvm/nvm.sh
|
|
||||||
koodiklinikka_user: web
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
koodiklinikka_tohtori_project_name: tohtori
|
|
||||||
koodiklinikka_tohtori_client_repo: git@github.com:koodiklinikka/tohtori.git
|
|
||||||
koodiklinikka_tohtori_user: web
|
|
||||||
koodiklinikka_tohtori_app_path: /opt/tohtori/tohtori
|
|
||||||
|
|
||||||
koodiklinikka_tohtori_container_name: tohtori_bot
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- 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
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
- include: tohtori_user.yml
|
|
||||||
- include: build.yml
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: get running container
|
|
||||||
shell: docker ps -a|grep {{ koodiklinikka_tohtori_container_name }}|grep latest| awk '{print $1}'
|
|
||||||
register: current_container_id
|
|
||||||
|
|
||||||
- name: kill old version
|
|
||||||
shell: docker stop {{ koodiklinikka_tohtori_container_name }}
|
|
||||||
when: current_container_id != ""
|
|
||||||
|
|
||||||
- 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 -d --name {{ koodiklinikka_tohtori_container_name }} {{ koodiklinikka_tohtori_container_name }}:old
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Create tohtori user
|
|
||||||
sudo: true
|
|
||||||
user: name=tohtori home=/opt/tohtori password=$1$U7pTMako$SY19s1PIxdD2NCFgM0LQr0
|
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Rollback api
|
- name: Rollback api
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/koodiklinikka.fi-api/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/koodiklinikka.fi-api/tasks/rollback.yml
|
- { include: roles/deploy/tasks/rollback.yml,
|
||||||
|
container_name: koodiklinikka.fi-api
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Rollback front
|
- name: Rollback front
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/koodiklinikka.fi-front/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/koodiklinikka.fi-front/tasks/rollback.yml
|
- { include: roles/deploy/tasks/rollback.yml,
|
||||||
|
container_name: koodiklinikka.fi-front
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Rollback tohtori
|
- name: Rollback tohtori
|
||||||
hosts: application
|
hosts: application
|
||||||
vars_files:
|
|
||||||
- roles/tohtori/defaults/main.yml
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: roles/tohtori/tasks/rollback.yml
|
- { include: roles/deploy/tasks/rollback.yml,
|
||||||
|
container_name: tohtori
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user