2021-11-02 16:29:52 -07:00
|
|
|
---
|
2021-11-02 18:47:13 -07:00
|
|
|
- name: Deploy impress-2020 from the current local version
|
2021-11-02 16:29:52 -07:00
|
|
|
hosts: webserver
|
2021-11-02 18:47:13 -07:00
|
|
|
vars:
|
|
|
|
skip_build: no # Can override this by running `yarn deploy-skip-build`
|
|
|
|
local_app_root: "{{ playbook_dir }}/../.."
|
2021-11-02 16:29:52 -07:00
|
|
|
tasks:
|
2021-11-02 18:47:13 -07:00
|
|
|
# For our deployment, our server resources are more constrained than our
|
|
|
|
# dev machine, and builds are an expensive uncommon RAM & CPU spike. Let's
|
|
|
|
# use our local machine for it! (I found that, running remotely, 2GB RAM
|
|
|
|
# was not enough to build impress-2020 😅)
|
|
|
|
- name: Run `yarn build` locally to build the current version
|
|
|
|
delegate_to: localhost
|
2021-11-02 16:29:52 -07:00
|
|
|
command:
|
2021-11-02 18:47:13 -07:00
|
|
|
chdir: "{{ local_app_root }}"
|
|
|
|
cmd: yarn build
|
|
|
|
when: not skip_build
|
|
|
|
|
2021-11-02 19:02:36 -07:00
|
|
|
- name: Generate a version name from the current timestamp
|
2021-11-02 21:14:47 -07:00
|
|
|
command: date '+%Y-%m-%d-%s'
|
2021-11-02 18:47:13 -07:00
|
|
|
register: new_app_version
|
|
|
|
|
2021-11-02 19:02:36 -07:00
|
|
|
- name: Print out the new version name
|
|
|
|
debug:
|
|
|
|
msg: "Deploying new version: {{ new_app_version.stdout }}"
|
|
|
|
|
2021-11-02 18:47:13 -07:00
|
|
|
- name: Save new remote folder path to a variable
|
|
|
|
set_fact:
|
|
|
|
remote_app_root: "/srv/impress-2020/versions/{{ new_app_version.stdout }}"
|
|
|
|
|
|
|
|
- name: Create new remote folder for the new version
|
|
|
|
file:
|
|
|
|
path: "{{ remote_app_root }}"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Copy local app's source files to new remote folder
|
|
|
|
ansible.posix.synchronize:
|
|
|
|
src: "{{ local_app_root }}"
|
|
|
|
dest: "{{ remote_app_root }}"
|
|
|
|
rsync_opts:
|
|
|
|
- "--exclude=.git"
|
|
|
|
- "--filter=':- .gitignore'"
|
|
|
|
|
|
|
|
- name: Copy local app's build files to new remote folder
|
|
|
|
ansible.posix.synchronize:
|
|
|
|
src: "{{ local_app_root }}/build"
|
|
|
|
dest: "{{ remote_app_root }}/build"
|
|
|
|
|
|
|
|
- name: Copy local app's .env secrets file to new remote folder
|
2021-11-02 16:45:07 -07:00
|
|
|
copy:
|
2021-11-02 18:47:13 -07:00
|
|
|
src: "{{ local_app_root }}/.env"
|
|
|
|
dest: "{{ remote_app_root }}"
|
|
|
|
|
|
|
|
- name: Run `yarn install` to install dependencies remotely
|
2021-11-02 16:45:07 -07:00
|
|
|
command:
|
2021-11-02 18:47:13 -07:00
|
|
|
chdir: "{{ remote_app_root }}"
|
|
|
|
cmd: yarn install
|
2021-11-02 19:02:36 -07:00
|
|
|
|
|
|
|
- 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 }}"
|