Skip to content

Commit

Permalink
Merge pull request #223 from consuldemocracy/install_specific_nodejs_…
Browse files Browse the repository at this point in the history
…version

Install specific nodejs version
  • Loading branch information
javierm authored Nov 23, 2023
2 parents f1ca8a4 + 59b8bbb commit ad38999
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 39 deletions.
1 change: 1 addition & 0 deletions app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
roles:
- folder_structure
- ruby
- nodejs
- rails
- email
- queue
Expand Down
2 changes: 1 addition & 1 deletion galaxy/yatesr.timezone/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
- include: timezone.yml
- include_tasks: timezone.yml
7 changes: 7 additions & 0 deletions group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ smtp_authentication: "plain"
#LetsEncrypt
#letsencrypt_email: "[email protected]"

# Node.js
fnm_dir: "{{ home_dir }}/.fnm"
fnm_command: "export PATH=\"{{ fnm_dir }}/:$PATH\" && eval \"$(fnm env)\""

# RVM
rvm_command: "source {{ home_dir }}/.rvm/scripts/rvm"

# Errbit
errbit: False
errbit_dir: "{{ home_dir }}/errbit"
Expand Down
16 changes: 8 additions & 8 deletions roles/errbit/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
executable: /bin/bash

- name: Install libv8-node for the right platform
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && gem install libv8-node --version '{{ libv8_version.stdout }}' --platform x86_64-linux-libc"
shell: "{{ rvm_command }} && gem install libv8-node --version '{{ libv8_version.stdout }}' --platform x86_64-linux-libc"
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash
Expand All @@ -48,13 +48,13 @@
executable: /bin/bash

- name: Install the mini_racer gem
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && gem install mini_racer --version '{{ mini_racer_version.stdout }}'"
shell: "{{ rvm_command }} && gem install mini_racer --version '{{ mini_racer_version.stdout }}'"
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash

- name: Install Errbit dependencies
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bundle install"
shell: "{{ rvm_command }} && bundle install"
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash
Expand All @@ -81,7 +81,7 @@
- when: not existing_secret_key_base.found
block:
- name: Generate secret key
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bin/rake secret"
shell: "{{ rvm_command }} && bin/rake secret"
register: secret_key_base
args:
chdir: "{{ errbit_dir }}"
Expand All @@ -93,13 +93,13 @@
line: "SECRET_KEY_BASE={{ secret_key_base.stdout }}"

- name: Setup Errbit
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && RAILS_ENV={{ env }} bin/rake errbit:bootstrap"
shell: "{{ rvm_command }} && RAILS_ENV={{ env }} bin/rake errbit:bootstrap"
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash

- name: Precompile Errbit assets
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && RAILS_ENV={{ env }} bin/rake assets:precompile"
shell: "{{ rvm_command }} && RAILS_ENV={{ env }} bin/rake assets:precompile"
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash
Expand All @@ -121,7 +121,7 @@
enabled: true

- name: Create app if it does not exist
shell: 'source /home/{{ deploy_user }}/.rvm/scripts/rvm && bin/rails runner -e {{ env }} "App.create(name: \"{{ domain }}\")"'
shell: '{{ rvm_command }} && bin/rails runner -e {{ env }} "App.create(name: \"{{ domain }}\")"'
args:
chdir: "{{ errbit_dir }}"
executable: /bin/bash
Expand All @@ -146,7 +146,7 @@
replace: ' errbit_host: "https://{{ errbit_domain }}"'

- name: Restart CONSUL DEMOCRACY
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && RAILS_ENV={{ env }} bin/rails restart"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bin/rails restart RAILS_ENV={{ env }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion roles/errbit/templates/errbit.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ After=mongodb.service network.target
Type=simple
WorkingDirectory={{ errbit_dir }}
Environment=RAILS_ENV={{ env }}
ExecStart=/bin/bash -lc 'source {{ home_dir }}/.rvm/scripts/rvm && bundle exec puma -C {{ errbit_dir }}/config/puma.default.rb -e {{ env }}'
ExecStart=/bin/bash -lc '{{ rvm_command }} && bundle exec puma -C {{ errbit_dir }}/config/puma.default.rb -e {{ env }}'
Restart=always
User={{ errbit_user }}
Group={{ errbit_group }}
Expand Down
2 changes: 1 addition & 1 deletion roles/folder_structure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
state: directory

- name: Create first release
shell: "git archive 2.0.1 | /usr/bin/env tar -x -f - -C {{ first_release_dir }}"
shell: "git archive e0aee199e487 | /usr/bin/env tar -x -f - -C {{ first_release_dir }}"
args:
chdir: "{{ consul_dir }}/repo"

Expand Down
30 changes: 30 additions & 0 deletions roles/nodejs/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Install fnm
shell: |
curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir "{{ fnm_dir }}"
args:
chdir: "{{ home_dir }}"
executable: /bin/bash
creates: "{{ fnm_dir }}/fnm"

- name: Read Node.js version
shell: "cat .node-version"
args:
chdir: "{{ release_dir }}"
register: node_version

- name: Install nodejs via fnm
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm install {{ node_version.stdout }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
register: fnm_install_result
until: "fnm_install_result is not failed"
retries: 10
delay: 10

- name: Install Node packages
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec npm install --production"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
2 changes: 1 addition & 1 deletion roles/puma/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
when: puma_process.stat.exists == True

- name: Start puma
shell: "source {{ home_dir }}/.rvm/scripts/rvm && bundle exec puma -C {{ release_dir }}/config/puma/{{ env }}.rb -e {{ env }} -d"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bundle exec puma -C {{ release_dir }}/config/puma/{{ env }}.rb -e {{ env }} -d"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion roles/queue/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Start DelayedJobs queue
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && RAILS_ENV={{ env }} bin/delayed_job -m -n 2 restart"
shell: "{{ fnm_command }} && {{ rvm_command }} && RAILS_ENV={{ env }} fnm exec bin/delayed_job -m -n 2 restart"
args:
executable: /bin/bash
chdir: "{{ release_dir }}"
16 changes: 8 additions & 8 deletions roles/rails/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Configure Bundler path
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bundle config --local path {{ shared_dir }}/bundle"
shell: "{{ rvm_command }} && bundle config --local path {{ shared_dir }}/bundle"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash

- name: Configure Bundler environments
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bundle config --local without development:test"
shell: "{{ rvm_command }} && bundle config --local without development:test"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
Expand All @@ -26,7 +26,7 @@
when: not usr_bin_mkdir.stat.exists

- name: Install gems (this may take a few minutes)
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bundle install"
shell: "{{ rvm_command }} && bundle install"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
Expand Down Expand Up @@ -60,7 +60,7 @@
replace: '{{ env }}:\n # secret_key_base: ""\n server_name: "{{ server_hostname }}"'

- name: Generate secret key
shell: "source {{ home_dir }}/.rvm/scripts/rvm && bin/rake secret RAILS_ENV={{ env }}"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bin/rake secret RAILS_ENV={{ env }}"
register: secret_key_base
args:
chdir: "{{ release_dir }}"
Expand All @@ -80,25 +80,25 @@
when: domain is not defined

- name: Create Database
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bin/rake db:migrate RAILS_ENV={{ env }}"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bin/rake db:migrate RAILS_ENV={{ env }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash

- name: Load configuration seeds
shell: "source /home/{{ deploy_user}}/.rvm/scripts/rvm && bin/rake db:seed RAILS_ENV={{ env }}"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bin/rake db:seed RAILS_ENV={{ env }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash

- name: Precompile assets
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bin/rake assets:precompile RAILS_ENV={{ env }}"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bin/rake assets:precompile RAILS_ENV={{ env }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash

- name: Update crontab with whenever
shell: "source /home/{{ deploy_user }}/.rvm/scripts/rvm && bundle exec whenever --update-crontab {{ app_name }} --set environment={{ env }}"
shell: "{{ fnm_command }} && {{ rvm_command }} && fnm exec bundle exec whenever --update-crontab {{ app_name }} --set environment={{ env }}"
args:
chdir: "{{ release_dir }}"
executable: /bin/bash
18 changes: 1 addition & 17 deletions roles/system/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,10 @@
apt:
name: apt-transport-https

- name: Add Node key
become: yes
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present

- name: Get distribution codename
shell: lsb_release -c --short
register: distro_codename

- name: Add Node repository
become: true
apt_repository:
repo: "deb https://deb.nodesource.com/node_10.x {{ distro_codename.stdout }} main"
state: present

- name: Remove apache server
become: true
apt:
name: apache2
state: absent

- include: tools.yml
- include_tasks: tools.yml
1 change: 0 additions & 1 deletion roles/system/tasks/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
- libffi-dev
- curl
- libcurl4-openssl-dev
- nodejs
- libpq-dev
- imagemagick
- ruby-dev
Expand Down

0 comments on commit ad38999

Please sign in to comment.