-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unholy
committed
Aug 4, 2022
1 parent
16e704f
commit ffdb6de
Showing
61 changed files
with
1,587 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.circleci/ansible/roles/configure-prometheus-node-exporter/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.