Skip to content

Commit

Permalink
final test
Browse files Browse the repository at this point in the history
  • Loading branch information
unholy committed Aug 4, 2022
1 parent 16e704f commit ffdb6de
Show file tree
Hide file tree
Showing 61 changed files with 1,587 additions and 398 deletions.
37 changes: 23 additions & 14 deletions .circleci/ansible/configure-server.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
---

- name: "configuration play."
- name: 'configuration play.'
hosts: web
user: ubuntu
become: true
become_method: sudo
become_user: root
become_user: root
gather_facts: false
vars:
ansible_python_interpreter: /usr/bin/python3
ansible_host_key_checking: false
ansible_stdout_callback: yaml
- ansible_python_interpreter: /usr/bin/python3
- ansible_host_key_checking: false
- ansible_stdout_callback: yaml

pre_tasks:
- name: "wait 600 seconds for target connection to become reachable/usable."
- name: 'wait 600 seconds for target connection to become reachable/usable.'
wait_for_connection:
timeout: 600

- name: "install python for Ansible."
become: true
raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3)
changed_when: false
- name: 'install python for Ansible.'
apt:
name: python3
state: latest
update_cache: yes

- setup:
environment:
- NODE_ENV: production
- ENVIRONMENT: production
- TYPEORM_CONNECTION: "{{ lookup('env', 'TYPEORM_CONNECTION')}}"
- TYPEORM_ENTITIES: "{{ lookup('env', 'TYPEORM_ENTITIES')}}"
- TYPEORM_HOST: "{{ lookup('env', 'TYPEORM_HOST')}}"
- TYPEORM_PORT: "{{ lookup('env', 'TYPEORM_PORT')}}"
- TYPEORM_USERNAME: "{{ lookup('env', 'TYPEORM_USERNAME')}}"
- TYPEORM_PASSWORD: "{{ lookup('env', 'TYPEORM_PASSWORD')}}"
- TYPEORM_DATABASE: "{{ lookup('env', 'TYPEORM_DATABASE')}}"
- TYPEORM_MIGRATIONS: "{{ lookup('env', 'TYPEORM_MIGRATIONS')}}"
- TYPEORM_MIGRATIONS_DIR: "{{ lookup('env', 'TYPEORM_MIGRATIONS_DIR')}}"

roles:
- configure-server
- configure-prometheus-node-exporter
48 changes: 17 additions & 31 deletions .circleci/ansible/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
---
- name: "deployment play."
- name: 'configuration play.'
hosts: web
remote_user: ubuntu
user: ubuntu
gather_facts: false
vars:
ansible_python_interpreter: /usr/bin/python3
ansible_host_key_checking: false
ansible_stdout_callback: yaml

- ansible_python_interpreter: /usr/bin/python3
- ansible_host_key_checking: false
- ansible_stdout_callback: yaml
environment:
NODE_ENV: production
VERSION: "1"
TYPEORM_CONNECTION: "{{ lookup('env', 'TYPEORM_CONNECTION') }}"
TYPEORM_MIGRATIONS_DIR: "{{ lookup('env', 'TYPEORM_MIGRATIONS_DIR') }}"
TYPEORM_ENTITIES: "{{ lookup('env', 'TYPEORM_ENTITIES') }}"
TYPEORM_MIGRATIONS: "{{ lookup('env', 'TYPEORM_MIGRATIONS') }}"
TYPEORM_HOST: "{{ lookup('env', 'TYPEORM_HOST') }}"
TYPEORM_PORT: "{{ lookup('env', 'TYPEORM_PORT') }}"
TYPEORM_USERNAME: "{{ lookup('env', 'TYPEORM_USERNAME') }}"
TYPEORM_PASSWORD: "{{ lookup('env', 'TYPEORM_PASSWORD') }}"
TYPEORM_DATABASE: "{{ lookup('env', 'TYPEORM_DATABASE') }}"

pre_tasks:
- name: "wait 600 seconds for target connection to become reachable/usable."
wait_for_connection:
timeout: 600

- name: "install python for Ansible."
become: true
raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3)
changed_when: false

- setup:

- NODE_ENV: production
- ENVIRONMENT: production
- TYPEORM_CONNECTION: "{{ lookup('env', 'TYPEORM_CONNECTION')}}"
- TYPEORM_ENTITIES: "{{ lookup('env', 'TYPEORM_ENTITIES')}}"
- TYPEORM_HOST: "{{ lookup('env', 'TYPEORM_HOST')}}"
- TYPEORM_PORT: "{{ lookup('env', 'TYPEORM_PORT')}}"
- TYPEORM_USERNAME: "{{ lookup('env', 'TYPEORM_USERNAME')}}"
- TYPEORM_PASSWORD: "{{ lookup('env', 'TYPEORM_PASSWORD')}}"
- TYPEORM_DATABASE: "{{ lookup('env', 'TYPEORM_DATABASE')}}"
- TYPEORM_MIGRATIONS: "{{ lookup('env', 'TYPEORM_MIGRATIONS')}}"
- TYPEORM_MIGRATIONS_DIR: "{{ lookup('env', 'TYPEORM_MIGRATIONS_DIR')}}"
roles:
- deploy
- deploy
4 changes: 3 additions & 1 deletion .circleci/ansible/node-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
hosts: web
user: ubuntu
become: true
become_method: sudo
become_user: root
gather_facts: false
vars:
- ansible_python_interpreter: /usr/bin/python3
- ansible_host_key_checking: false
- ansible_stdout_callback: yaml
roles:
- configure-prometheus-node-exporter
- configure-prometheus-node-exporter
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- name: "install node exporter."
unarchive:
src: https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
src: https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
dest: /tmp
remote_src: yes

- name: "move binary to /usr/local/bin."
become: true
copy:
src: /tmp/node_exporter-1.3.1.linux-amd64/node_exporter
src: /tmp/node_exporter-0.17.0.linux-amd64/node_exporter
dest: /usr/local/bin/node_exporter
remote_src: yes
mode: '0777'
Expand Down
34 changes: 21 additions & 13 deletions .circleci/ansible/roles/configure-server/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
- name: "Install Node.js 13"
become: true
shell: |
# Install Node.js LTS version as our base Node.js version
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
# Use n version manager to use Node.js v13.8.0
sudo npm install --global n
sudo n 13.8.0
- name: "Install PM2 Globally"
- name: 'update and upgrade packages.' # sudo apt upgrade
become: yes
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400
- name: remove unneeded deps # sudo apt autoremove
become: yes
apt:
autoremove: yes
- name: install deps # sudo apt install nodejs npm
become: yes
apt:
name: ['nodejs', 'npm']
state: latest
update_cache: yes
- name: install pm2 # sudo npm install pm2 -g
become: yes
npm:
name: pm2
global: yes
global: yes
state: latest
production: yes
59 changes: 31 additions & 28 deletions .circleci/ansible/roles/deploy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
---
- name: "Creates backend app directory"
file:
path: ~/backend-app
state: directory

- name: "Unarchive backend files"
- name: 'update and upgrade packages.'
become: yes
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400
- name: remove unneeded deps
become: yes
apt:
autoremove: yes
- name: install deps
become: yes
apt:
name: ['nodejs', 'npm']
state: latest
update_cache: yes
- name: install pm2
become: yes
npm:
name: pm2
global: yes
state: latest
production: yes
- name: extract artifact
become: yes
unarchive:
src: artifact.tar.gz
dest: ~/backend-app

- name: "Installing Node Dependencies"
shell: |
cd ~/backend-app
npm i
- name: "Executing Node app with PM2"
shell: |
cd ~/backend-app/dist
pm2 stop default
pm2 start main.js
register: execute_node

- name: print message
debug:
msg: "{{ execute_node.stdout_lines }}"
src: files/artifact.tar.gz
dest: .

- name: "Configure pm2 to start as service"
- name: start app
become: yes
shell: |
sudo su -c "env PATH=$PATH:/usr/local/bin pm2 startup systemd -u ubuntu --hp /home/ubuntu"
pm2 save
pm2 delete all
pm2 start npm -- start
Loading

0 comments on commit ffdb6de

Please sign in to comment.