Switch to a A/B model

This commit is contained in:
Michcio 2022-09-04 00:14:51 +02:00
parent 0b0fd447f2
commit f572008805

View file

@ -9,11 +9,21 @@
deploys_root: /var/lib/misskey/deploys deploys_root: /var/lib/misskey/deploys
config_yml: /var/lib/misskey/default.yml config_yml: /var/lib/misskey/default.yml
tasks: tasks:
- name: Generate deploy dir name - name: Checking which environment is currently prod
ansible.builtin.stat:
path: "{{ deploys_root }}/current"
get_attributes: false
get_checksum: false
get_mime: false
follow: false
register: previous_current
become: true
become_user: "{{ user }}"
- name: Picking staging environment that is not currently prod
ansible.builtin.set_fact: ansible.builtin.set_fact:
deploy_dir: "{{ deploys_root }}/{{ ansible_date_time.iso8601_basic_short }}" deploy_dir: "{{ deploys_root }}/{{ previous_current.stat.lnk_source.endswith('sunrise') | ternary('sunset', 'sunrise') }}"
run_once: true run_once: true
- name: Print the generated deployment name - name: Print the chosen deployment directory
ansible.builtin.debug: ansible.builtin.debug:
var: deploy_dir var: deploy_dir
run_once: true run_once: true
@ -27,8 +37,6 @@
ansible.builtin.file: ansible.builtin.file:
path: "{{ deploy_dir }}" path: "{{ deploy_dir }}"
state: directory state: directory
mode: '0755'
recurse: true
- name: Clone source repository - name: Clone source repository
ansible.builtin.git: ansible.builtin.git:
repo: "{{ source_repository }}" repo: "{{ source_repository }}"
@ -39,10 +47,6 @@
dest: "{{ deploy_dir }}/.config/default.yml" dest: "{{ deploy_dir }}/.config/default.yml"
src: "{{ config_yml }}" src: "{{ config_yml }}"
state: link state: link
- name: Reflink copy previous node_modules
ansible.builtin.command: cp -r --reflink "{{ deploys_root }}/current/node_modules" "{{ deploy_dir }}/node_modules"
args:
creates: "{{ deploy_dir }}/node_modules"
- name: Install Yarn dependencies - name: Install Yarn dependencies
ansible.builtin.command: yarn install ansible.builtin.command: yarn install
changed_when: true changed_when: true
@ -55,18 +59,12 @@
chdir: "{{ deploy_dir }}" chdir: "{{ deploy_dir }}"
- name: Deploy - name: Deploy
block: block:
- name: Note down previous deploy
become: true
become_user: "{{ user }}"
ansible.builtin.command: readlink "{{ deploys_root }}/current"
changed_when: true
register: previous_shell
- name: Link previous deploy - name: Link previous deploy
become: true become: true
become_user: "{{ user }}" become_user: "{{ user }}"
ansible.builtin.file: ansible.builtin.file:
dest: "{{ deploys_root }}/previous" dest: "{{ deploys_root }}/previous"
src: "{{ previous_shell.stdout }}" src: "{{ previous_current.stat.lnk_source }}"
state: link state: link
force: true force: true
- name: Link new deploy - name: Link new deploy