Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ansible): playbook for staring the api #552

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/play-oldeworld--api-1-updateazagent.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Initialize Olde World Cluster - API
- name: Update Olde World Cluster - API
hosts: '{{ variable_host | default("null") }}'
become: true
become_user: freecodecamp
Expand Down
103 changes: 103 additions & 0 deletions ansible/play-oldeworld--api-3-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
- name: Setup Olde World Cluster - API
hosts: '{{ variable_host | default("null") }}'
gather_facts: false
vars:
api_env: '{{ variable_api_env | default("stg") }}'
tasks:
- name: Clone the Git Repository
git:
name: https://github.com/freeCodeCamp/freeCodeCamp.git
dest: /home/freecodecamp/freeCodeCamp
clone: true
update: false
single_branch: true
version: 'prod-{{ api_env == "stg" | ternary("staging", "current") }}'

- name: Copy the .env file
copy:
src: '{{ playbook_dir }}/files/api/.env'
dest: /home/freecodecamp/freeCodeCamp/.env
owner: freecodecamp
group: freecodecamp
mode: 0644
- name: Get the Node.js version
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
node -v
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash
register: node_version_output

- name: Set the Node.js version fact
set_fact:
node_version: '{{ node_version_output.stdout }}'

- name: Install Global Dependencies
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
npm i -g pnpm
npm i -g pm2
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash

- name: Setup PM2 & Logrotate
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
pm2 install pm2-logrotate
sudo env PATH=$PATH:/home/freecodecamp/.nvm/versions/node/{{ node_version }}/bin /home/freecodecamp/.nvm/versions/node/{{ node_version }}/lib/node_modules/pm2/bin/pm2 startup systemd -u freecodecamp --hp /home/freecodecamp
pm2 save
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash
register: pm2_setup_output

- name: Install Dependencies
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
pnpm install
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash

- name: Build the server
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
pnpm prebuild
pnpm build:curriculum
pnpm build:server
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash

- name: Start the server
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
pnpm start:server
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash

- name: Save the running process
shell:
cmd: |
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ]
printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
pm2 save
chdir: /home/freecodecamp/freeCodeCamp
executable: /bin/bash
4 changes: 2 additions & 2 deletions ansible/roles/nginx/tasks/config-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

- name: Copy the SSL certificates directory from the local machine
copy:
src: "{{ playbook_dir }}/files/ssl"
src: "{{ playbook_dir }}/files/nginx/ssl"
dest: /etc/nginx/
directory_mode: yes
owner: root
Expand All @@ -45,7 +45,7 @@

- name: Copy the Upstream configs directory from the local machine
copy:
src: "{{ playbook_dir }}/files/configs/upstreams.conf"
src: "{{ playbook_dir }}/files/nginx/configs/upstreams.conf"
dest: /etc/nginx/configs/
owner: root
group: root
Expand Down
Loading