From 622f7f9db16d3d1a95e8c82c1c203740b5f34aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D1=8E=D1=82=D1=80=D1=8E=D0=BC=D0=BE=D0=B2=20=D0=A1?= =?UTF-8?q?=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9C=D0=B8=D1=85=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 13 May 2024 20:51:15 +0000 Subject: [PATCH] Feat/deploy --- nginx.conf.j2 | 43 ++++++++++++------------- playbook.yaml | 2 +- tsm_labs/tasks/main.yml | 69 +++++++++++++++++++++++++++++++---------- tsm_labs/vars/main.yml | 7 +++++ 4 files changed, 82 insertions(+), 39 deletions(-) diff --git a/nginx.conf.j2 b/nginx.conf.j2 index a13df89..47de8b2 100644 --- a/nginx.conf.j2 +++ b/nginx.conf.j2 @@ -1,38 +1,39 @@ -user  {{ nginx_user }}; -worker_processes  2048; -worker_priority     -1; +user {{ nginx_user }}; +worker_processes 2048; +worker_priority -1; -error_log  /var/log/nginx/error.log warn; -pid        /var/run/nginx.pid; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; events { - worker_connections  auto; + worker_connections auto; } http { - include       /etc/nginx/mime.types; - default_type  application/octet-stream; - log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; - access_log  /var/log/nginx/access.log  main; + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; - keepalive_timeout  65; - reset_timedout_connection  on; - client_body_timeout        35; - send_timeout               30; + keepalive_timeout 65; + reset_timedout_connection on; + client_body_timeout 35; + send_timeout 30; gzip on; - gzip_min_length     1000; + gzip_min_length 1000; gzip_vary on; - gzip_proxied        expired no-cache no-store private auth; - gzip_types          text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    gzip_disable        "msie6"; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; + gzip_disable "msie6"; types_hash_max_size 2048; client_max_body_size 512m; - proxy_buffer_size   64k; - proxy_buffers   4 64k; - proxy_busy_buffers_size   64k; + proxy_buffer_size 64k; + proxy_buffers 4 64k; + proxy_busy_buffers_size 64k; server_names_hash_bucket_size 64; include /etc/nginx/modules-enabled/*.conf; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; -} +} \ No newline at end of file diff --git a/playbook.yaml b/playbook.yaml index be93689..c74e3b4 100644 --- a/playbook.yaml +++ b/playbook.yaml @@ -3,4 +3,4 @@ hosts: node become: true roles: - - role: ./tsm_labs + - role: tsm_labs diff --git a/tsm_labs/tasks/main.yml b/tsm_labs/tasks/main.yml index c0ad22f..83d7356 100644 --- a/tsm_labs/tasks/main.yml +++ b/tsm_labs/tasks/main.yml @@ -1,24 +1,28 @@ --- - name: Update all packages Ubuntu when: ansible_os_family == 'Debian' + run_once: true ansible.builtin.apt: update_cache: true upgrade: true - name: Update all packages CentOS when: ansible_os_family == 'RedHat' + run_once: true ansible.builtin.yum: name: "*" state: latest - name: Install EPEL repo when: ansible_os_family == 'RedHat' + run_once: true ansible.builtin.yum: name: - epel-release state: present - name: Install git 'RedHat' + run_once: true when: ansible_os_family == 'RedHat' ansible.builtin.yum: name: @@ -26,8 +30,9 @@ state: present - name: Install NodeJS-18 FRONTEND - when: "'node1' in inventory_hostname" + when: ansible_os_family == 'Debian' become: true + run_once: true block: - name: Скачивание ключа ansible.builtin.get_url: @@ -49,35 +54,66 @@ ansible.builtin.git: repo: https://gitlab.resds.ru/itt/sample-project.git dest: /src/sample-project - +- name: Deploy FRONTEND + when: "'node1' in inventory_hostname" + become: true + block: + - name: Установка pm2 + community.general.npm: + name: "pm2" + global: true + state: present + become: true - name: Установка пакетов community.general.npm: path: /src/sample-project/notes-app/ state: present - - name: Пуск проекта FRONTEND - command: npm start - args: + become: true + - name: Delete old pm2 process + ansible.builtin.shell: + cmd: pm2 delete Front || true + chdir: /src/sample-project/notes-app/ + - name: Start pm2 process + ansible.builtin.shell: + cmd: pm2 start npm --name "Front" -- start chdir: /src/sample-project/notes-app/ -- name: Install NodeJS-18 BACKEND - when: "'node2' in inventory_hostname" +- name: Install NodeJS-18 Redhat + when: ansible_os_family == 'RedHat' become: true + run_once: true block: - - name: Копирование проекта - ansible.builtin.git: - repo: https://gitlab.resds.ru/itt/sample-project.git - dest: /src/sample-project - name: Установка Node.js & npm BACKEND ansible.builtin.yum: name: - nodejs - npm + +- name: Deploy BACKEND + when: "'node2' in inventory_hostname" + become: true + block: + - name: Копирование проекта + ansible.builtin.git: + repo: https://gitlab.resds.ru/itt/sample-project.git + dest: /src/sample-project + single_branch: true + version: main - name: Установка пакетов в директорию /src/sample-project/notes-backend/ - npm: - path: /src/sample-project/notes-backend/ - - name: Пуск проекта BACKEND - command: npm start - args: + community.general.npm: + path: /src/sample-project/notes-backend/ + - name: Установка pm2 + community.general.npm: + name: pm2 + global: true + state: present + - name: Delete old pm2 process + ansible.builtin.shell: + cmd: /usr/local/bin/pm2 delete Backend || true + chdir: /src/sample-project/notes-backend/ + - name: Start pm2 process + ansible.builtin.shell: + cmd: /usr/local/bin/pm2 start npm --name "Backend" -- start chdir: /src/sample-project/notes-backend/ - name: Install nginx 'Ubuntu' when: ansible_os_family == 'Debian' @@ -95,4 +131,3 @@ group: root mode: "0644" notify: Reload nginx service - diff --git a/tsm_labs/vars/main.yml b/tsm_labs/vars/main.yml index ab4cf0a..6e54ff1 100644 --- a/tsm_labs/vars/main.yml +++ b/tsm_labs/vars/main.yml @@ -2,3 +2,10 @@ worker_connections: 512 gzip_min_length: 1000 client_max_body_size: 512m + +nodejs_version: 18.x +nodejs_rpm_path: '{{ "pub_" + nodejs_version if nodejs_version != "0.10" else "pub" }}' +nodejs_rpm_key: rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL +nodejs_rpm_url: rpm.nodesource.com/{{ nodejs_rpm_path }}/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version + }}-1.noarch.rpm +nodejs_repo_name: nodesource