aboutsummaryrefslogtreecommitdiff
path: root/ansible/deploy.yaml
blob: 5c4813a51d51821c6714ed1c967a5c987fb4c889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
- name: Deploy to production
  hosts: all
  remote_user: root
  become: true
  become_user: "{{ username }}"

  vars:
    app_dir: "/home/{{ username }}/invoice"
    nvm_sh_dir: "/home/{{ username }}/.nvm/nvm.sh"

  tasks:
    - name: Checkout repo
      git:
        repo: "{{ git_repo }}"
        dest: "{{ app_dir }}"
        version: main
        force: true

    - name: Install deps
      shell: |
        . {{ nvm_sh_dir }}
        npm install
      args:
        executable: /bin/bash
        chdir: "{{ app_dir }}"

    - name: Build nextjs server
      shell: |
        . {{ nvm_sh_dir }}
        npm run build
      args:
        executable: /bin/bash
        chdir: "{{ app_dir }}"

    - name: Sync .next/static
      shell: |
        rsync -avP {{ app_dir }}/.next/static {{ app_dir }}/.next/standalone/.next/

    - name: Sync public dir
      shell: |
        rsync -avP {{ app_dir }}/public {{ app_dir }}/.next/standalone/

    - name: Start/restart pm2 process
      shell: |
        . {{ nvm_sh_dir }}
        pm2 restart invoice-app || pm2 start server.js --name invoice-app
      args:
        executable: /bin/bash
        chdir: "{{ app_dir }}/.next/standalone"