Add task to clean up older deployed versions

This commit is contained in:
Emi Matchu 2021-11-02 19:02:36 -07:00
parent edd983c97a
commit fb5b0fe611

View file

@ -16,10 +16,14 @@
cmd: yarn build cmd: yarn build
when: not skip_build when: not skip_build
- name: Generate a version number from the current timestamp - name: Generate a version name from the current timestamp
command: date '+%Y-%m-%dT%H:%M:%S' command: date '+%Y-%m-%dT%H:%M:%S'
register: new_app_version register: new_app_version
- name: Print out the new version name
debug:
msg: "Deploying new version: {{ new_app_version.stdout }}"
- name: Save new remote folder path to a variable - name: Save new remote folder path to a variable
set_fact: set_fact:
remote_app_root: "/srv/impress-2020/versions/{{ new_app_version.stdout }}" remote_app_root: "/srv/impress-2020/versions/{{ new_app_version.stdout }}"
@ -51,3 +55,16 @@
command: command:
chdir: "{{ remote_app_root }}" chdir: "{{ remote_app_root }}"
cmd: yarn install cmd: yarn install
- name: Find older versions to clean up
# Print out all but the last 5 versions
command:
chdir: /srv/impress-2020/versions
cmd: bash -c 'ls | head -n -5'
register: versions_to_clean_up
- name: Clean up older versions
file:
path: "/srv/impress-2020/versions/{{ item }}"
state: absent
with_items: "{{ versions_to_clean_up.stdout_lines }}"