Skip to content

Commit

Permalink
modules should be self contained
Browse files Browse the repository at this point in the history
  • Loading branch information
rkmax committed Oct 18, 2017
1 parent 689fc57 commit 6935803
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/ec2-postgresql/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_instance" "nginx_node" {
}

provisioner "file" {
source = "${path.module}/../provision/"
source = "${path.module}/provision/"
destination = "/home/ubuntu/provision/"
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/ec2/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_instance" "nginx_node" {
}

provisioner "file" {
source = "${path.module}/../provision/"
source = "${path.module}/provision/"
destination = "/home/ubuntu/provision/"
}

Expand Down
8 changes: 8 additions & 0 deletions modules/ec2/provision/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');

const app = express();

app.get('/', (req, res) => {
res.send(`<h1>Dummy app</h1><p>Response from PID: ${process.pid}. Hit F5 many times!</p>`);
});
app.listen(3000, () => console.log('Listening on port 3000!'));
14 changes: 14 additions & 0 deletions modules/ec2/provision/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "sample-app",
"version": "0.0.1",
"main": "index.js",
"author": {
"name": "Julian Reyes",
"email": "jreyes@bixlabs.com",
"url": "https://twitter.com/rokemaster"
},
"dependencies": {
"express": "^4.15.4"
},
"private": true
}
14 changes: 14 additions & 0 deletions modules/ec2/provision/install_dummy_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# This loads nvm
export NVM_DIR="$HOME/.nvm"
\. "$NVM_DIR/nvm.sh"

cp -r $HOME/provision/app $HOME/
cp -r $HOME/provision/pm2.json $HOME/app-pm2.json
npm i -g pm2

cd $HOME/app
npm i

pm2 start $HOME/app-pm2.json
9 changes: 9 additions & 0 deletions modules/ec2/provision/install_nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e
export DEBIAN_FRONTEND=noninteractive

sudo apt-get install -y nginx
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s $HOME/provision/nginx_app.conf /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
20 changes: 20 additions & 0 deletions modules/ec2/provision/install_nvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

function latest_version() {
curl -s https://api.github.com/repos/creationix/nvm/releases/latest \
| grep 'tag_name' \
| cut -d '"' -f 4
}

function install_version() {
curl "https://raw.githubusercontent.com/creationix/nvm/${1}/install.sh" \
| bash
}

install_version `latest_version`

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

nvm install 8.4.0
7 changes: 7 additions & 0 deletions modules/ec2/provision/install_ubuntu_build_essential.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e
export DEBIAN_FRONTEND=noninteractive

sudo apt-get update
sudo apt-get install -y build-essential libssl-dev
18 changes: 18 additions & 0 deletions modules/ec2/provision/nginx_app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
upstream app {
server 127.0.0.1:3000;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

server_name _;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://app;
}
}
10 changes: 10 additions & 0 deletions modules/ec2/provision/pm2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "dummy-app",
"cwd": "/home/ubuntu/app",
"script": "index.js",
"env": {
"NODE_ENV": "production"
},
"instances": 2,
"exec_mode": "cluster"
}

0 comments on commit 6935803

Please sign in to comment.