mirror of
https://github.com/koodiklinikka/koodiklinikka.fi-api.git
synced 2026-02-25 12:56:56 +00:00
initial commit
This commit is contained in:
18
deploy/deploy.sh
Normal file
18
deploy/deploy.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
export ANSIBLE_SSH_ARGS="-o ForwardAgent=yes"
|
||||
|
||||
# Install dependencies
|
||||
if ! which pip > /dev/null; then
|
||||
echo "Installing pip (requires sudo password)"
|
||||
sudo apt-get install python-pip || sudo easy_install pip
|
||||
fi
|
||||
|
||||
if ! which ansible > /dev/null; then
|
||||
echo "Installing ansible (requires sudo password)"
|
||||
sudo pip install ansible
|
||||
fi
|
||||
|
||||
cd $(dirname $0)
|
||||
ansible-playbook deploy.yml -i hosts
|
||||
56
deploy/deploy.yml
Normal file
56
deploy/deploy.yml
Normal file
@@ -0,0 +1,56 @@
|
||||
---
|
||||
- name: Deploy API
|
||||
hosts: all:!localhost
|
||||
remote_user: "{{ service_user }}"
|
||||
gather_facts: no
|
||||
vars_files:
|
||||
- vars.yml
|
||||
tasks:
|
||||
- name: Deploy from git
|
||||
action: >
|
||||
git
|
||||
repo="{{ repository_url }}"
|
||||
dest="{{ projects_path }}"
|
||||
accept_hostkey=True
|
||||
notify: restart service
|
||||
|
||||
- name: Setup bot config
|
||||
copy: >
|
||||
src=/opt/web/config/api.json
|
||||
dest="{{ projects_path }}/config.json"
|
||||
owner=web
|
||||
group=web
|
||||
mode=0644
|
||||
notify: restart service
|
||||
|
||||
- name: Install NVM
|
||||
action: >
|
||||
git
|
||||
repo="https://github.com/creationix/nvm"
|
||||
dest="{{ nvm_path }}"
|
||||
|
||||
- name: Make sure Node.js is installed and properly aliased
|
||||
command: >
|
||||
bash -c "source {{ nvm_script }} && nvm install {{ nodejs_version }} && nvm alias {{ project_name }} {{ nodejs_version }}"
|
||||
register: nvm_result
|
||||
changed_when: >
|
||||
"already installed" not in nvm_result.stdout
|
||||
notify: restart service
|
||||
|
||||
- name: Install NPM dependencies and build assets
|
||||
command: >
|
||||
bash -c "source {{ nvm_script }} && nvm use {{ project_name }} && cd {{ projects_path }} && npm install"
|
||||
notify: restart service
|
||||
|
||||
- name: Setup Upstart config
|
||||
template: >
|
||||
src=templates/upstart.j2
|
||||
dest="/etc/init/{{ project_name }}.conf"
|
||||
mode=664
|
||||
notify: restart service
|
||||
|
||||
handlers:
|
||||
- name: restart service
|
||||
service: >
|
||||
name={{ project_name }}
|
||||
state=restarted
|
||||
1
deploy/hosts
Normal file
1
deploy/hosts
Normal file
@@ -0,0 +1 @@
|
||||
koodiklinikka.fi
|
||||
12
deploy/templates/upstart.j2
Normal file
12
deploy/templates/upstart.j2
Normal file
@@ -0,0 +1,12 @@
|
||||
description "koodiklinikka.fi API"
|
||||
author "Riku Rouvila <riku.rouvila@gmail.com>"
|
||||
|
||||
start on runlevel [2345]
|
||||
stop on runlevel [016]
|
||||
|
||||
respawn
|
||||
respawn limit 10 5
|
||||
env NODE_ENV=production
|
||||
exec su -s /bin/bash -c 'source {{ nvm_script }} && nvm use {{ project_name }} && cd {{ projects_path }} && exec "$0" "$@"' {{ service_user }} -- \
|
||||
node index.js \
|
||||
>> /var/log/{{ project_name }}.log 2>&1
|
||||
8
deploy/vars.yml
Normal file
8
deploy/vars.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
project_name: koodiklinikka.fi-api
|
||||
projects_path: /opt/web/koodiklinikka.fi-api
|
||||
repository_url: git@github.com:koodiklinikka/koodiklinikka.fi-api.git
|
||||
service_user: web
|
||||
nvm_path: /opt/web/nvm
|
||||
nvm_script: /opt/web/nvm/nvm.sh
|
||||
nodejs_version: v0.10.25
|
||||
Reference in New Issue
Block a user