I
I
Iceforest2021-03-15 17:05:56
npm
Iceforest, 2021-03-15 17:05:56

How to speed up building npm packages?

Good afternoon, when building a server using ansible, there is an installation step npm install in the yaml file. This step takes a lot of time and resources. Is there any way to speed up the build?

- hosts: frontend_servers

  vars:
    project_path: /var/www
    repositiry: ссылка на репозиторий


  tasks:

    - name: "Yarn | GPG"
      apt_key:
        url: https://dl.yarnpkg.com/debian/pubkey.gpg
        state: present

    - name: "Yarn | Ensure Debian sources list file exists"
      file:
        path: /etc/apt/sources.list.d/yarn.list
        owner: root
        mode: 0644
        state: touch

    - name: "Yarn | Ensure Debian package is in sources list"
      lineinfile:
        dest: /etc/apt/sources.list.d/yarn.list
        regexp: 'deb http://dl.yarnpkg.com/debian/ stable main'
        line: 'deb http://dl.yarnpkg.com/debian/ stable main'
        state: present

    - name: "Yarn | Update APT cache"
      apt:
        update_cache: yes

    - name: Install the packages YARN, NPM, NodeJS, Nginx
      apt: 
        pkg: 
          - yarn
          - npm
          - nodejs

    - name: Remove Nginx
      apt:
        name: nginx
        state: absent

    - name: Stop service Nginx
      ansible.builtin.systemd:
        name: nginx
        state: stopped

    - name: Delete the html file 
      file:
        path: "{{ project_path }}/html"
        state: absent

    - name: Set some variable
      set_fact:
        release_path: "{{ project_path }}/releases/{{ lookup('pipe','date +%Y%m%d%H%M%S') }}"
        current_path: "{{ project_path }}/html"
      tags: start_yarn

    - name: Create project path
      file:
        dest={{ project_path }}
        mode=0755
        recurse=yes
        state=directory

    - name: Retrieve current release folder
      command: readlink -f html
      register: current_release_path
      ignore_errors: yes
      args:
        chdir: "{{ project_path }}"

    - name: Create Release folder
      file:
        dest={{ release_path }}
        mode=0755
        recurse=yes
        state=directory

    - name: Clone the repository
      git:
        repo: "{{ repositiry }}"
        dest: "{{ release_path }}"


    - name: Add IP address of instance to main site 
      replace:
        path: "{{ release_path }}/src/App.js"
        regexp: 'Test of revert'
        replace: '{{ ansible_default_ipv4.address }}'
        backup: yes

    - name: Install packages based on package.json.
      npm:
        path: "{{ release_path }}"

    - name: npm install
      command: "npm install"
      args:
        chdir: "{{ release_path }}"


    - name: Start application
      command: "nohup yarn start &"
      args:
        chdir: "{{ release_path }}"
      environment:
        PORT: 80
      async: 1000
      poll: 0
      tags: start_yarn

I build using the command ansible-playbook -b reactjs.yaml -vv

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Iceforest, 2021-03-17
@Iceforest

npm заменил на yarn

- name: yarn install
command: "yarn install"
args:
chdir: "{{ release_path }}"

Пума Тайланд, 2021-03-16
@opium

так он это делает один раз долго потом уже все пакеты стоят

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question