From 5074cfb9b227934ebaa849c16794800363dbd272 Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Wed, 9 Nov 2022 19:54:52 +0100 Subject: [PATCH] =?UTF-8?q?[EVO]=20R=C3=A9cup=C3=A9rer=20la=20derni=C3=A8r?= =?UTF-8?q?e=20version=20de=20production?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ansible/run.yml | 97 ++++++++++++++++++++++++++++++++---------------- .drone.yml | 15 +++++++- README.md | 4 +- 3 files changed, 81 insertions(+), 35 deletions(-) diff --git a/.ansible/run.yml b/.ansible/run.yml index 88abb5d..672192a 100644 --- a/.ansible/run.yml +++ b/.ansible/run.yml @@ -2,7 +2,6 @@ - hosts: all gather_facts: false - connection: local tags: - check_targets - deploy @@ -17,7 +16,6 @@ - hosts: all gather_facts: false - connection: local tags: check_targets tasks: - name: Attendre que le port SSH soit ouvert @@ -96,6 +94,41 @@ vars: release_id: "{{ make_release.json.id }}" +- hosts: all + gather_facts: false + tags: deploy_nginx + roles: + - name: nginx + +- hosts: all + gather_facts: false + tags: deploy + tasks: + - name: Déployer l'application + ansible.posix.synchronize: + src: "{{ playbook_dir }}/{{ app_name }}" + dest: /var/www + archive: true + delete: true + tags: deploy + become: true + +- hosts: all + gather_facts: false + tags: clean_cache + tasks: + - name: Vider le cache de l'application + ansible.builtin.file: + path: /var/cache/nginx/{{ app_name }} + state: absent + become: true + diff: false + +- hosts: 127.0.0.1 + gather_facts: false + connection: local + tags: clean_releases + tasks: - name: Lister les pré-version ansible.builtin.uri: url: "{{ gitea_api_base_url }}/repos/{{ gitea_api_repository }}/releases?pre-release=true" @@ -118,36 +151,38 @@ label: "{{ item.name }}" loop: "{{ get_releases.json[3:] }}" -- hosts: all +- hosts: 127.0.0.1 gather_facts: false connection: local - tags: deploy_nginx - roles: - - name: nginx - -- hosts: all - gather_facts: false - connection: local - tags: deploy + tags: clean_tags tasks: - - name: Déployer l'application - ansible.posix.synchronize: - src: "{{ playbook_dir }}/{{ app_name }}" - dest: /var/www - archive: true - delete: true - tags: deploy - become: true - diff: false + - name: Lister les version + ansible.builtin.uri: + url: "{{ gitea_api_base_url }}/repos/{{ gitea_api_repository }}/releases" + method: GET + headers: + Content-Type: application/json + register: get_releases -- hosts: all - gather_facts: false - connection: local - tags: clean_cache - tasks: - - name: Vider le cache de l'application - ansible.builtin.file: - path: /var/cache/nginx/{{ app_name }} - state: absent - become: true - diff: false + - name: Lister les étiquettes + ansible.builtin.uri: + url: "{{ gitea_api_base_url }}/repos/{{ gitea_api_repository }}/tags" + method: GET + headers: + Content-Type: application/json + register: get_tags + + - name: Supprimer les étiquettes n'ayant pas de version + ansible.builtin.uri: + url: "{{ gitea_api_base_url }}/repos/{{ gitea_api_repository }}/tags/{{ item }}" + method: DELETE + headers: + Content-Type: application/json + status_code: 204 + when: + - get_releases.json | length > 0 + - item | length > 0 + loop: "{{ releases_by_name | symmetric_difference(tags_by_name) }}" + vars: + releases_by_name: "{{ get_releases.json | map(attribute='name') }}" + tags_by_name: "{{ get_tags.json | map(attribute='name') }}" diff --git a/.drone.yml b/.drone.yml index dc277c9..e385a8a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,7 +30,6 @@ steps: - name: ansible-galaxy commands: - - sed -i 's#ssh://gitea@git.ykn.fr:12393#https://gitea.ykn.fr#g' .ansible/requirements.yml - ansible-galaxy install -r .ansible/requirements.yml -p .ansible/roles - name: ansible-playbook/check @@ -69,8 +68,20 @@ steps: commands: - ansible-playbook .ansible/run.yml --tags deploy --limit 'ykn-www-2245.nyx.ykn.local' - - name: ansible-playbook/cache + - name: ansible-playbook/clean_cache environment: ANSIBLE_CONFIG: .ansible/configuration/ansible.cfg commands: - ansible-playbook .ansible/run.yml --tags clean_cache --limit 'nyx_rproxies' + + - name: ansible-playbook/clean_releases + environment: + ANSIBLE_CONFIG: .ansible/configuration/ansible.cfg + commands: + - ansible-playbook .ansible/run.yml --tags clean_releases + + - name: ansible-playbook/clean_tags + environment: + ANSIBLE_CONFIG: .ansible/configuration/ansible.cfg + commands: + - ansible-playbook .ansible/run.yml --tags clean_tags diff --git a/README.md b/README.md index 3edfbf7..1a9f777 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# role_modele +# www.ykn.fr -Modèle \ No newline at end of file +Contient une version figée de la pipeline [Drone CI](https://www.drone.io/) et du playbook [Ansible](https://fr.wikipedia.org/wiki/Ansible_(logiciel)).