Skip to content

Commit

Permalink
πŸŽ› Add heroku deployment configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
andreffs18 committed Apr 13, 2020
1 parent 8800791 commit 462b27a
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
heroku buildpacks:clear
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-nginx.git
heroku buildpacks:add --index 2 heroku/python
heroku buildpacks:add --index 3 https://github.com/heroku/heroku-buildpack-nodejs#v170
# Just print buildpacks configuration
heroku buildpacks
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: honcho start -f santosbot.Procfile
8 changes: 8 additions & 0 deletions backend/heroku.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Install poetry with specific version
pip install "poetry==1.0.5"
# Project initialization without creating virtalenv
poetry config virtualenvs.create false
poetry install $([ "$ENVIRONMENT" = 'production' ] && echo "--no-dev") --no-interaction --no-ansi
# Run project
uvicorn api:app --port 8888 --host 0.0.0.0
4 changes: 4 additions & 0 deletions bot/heroku.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Install bot requirements
pip install --no-cache-dir -r requirements.txt
python main.py
56 changes: 56 additions & 0 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
daemon off;
# Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
use epoll;
accept_mutex on;
worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
}

http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;

server_tokens off;

log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;

include mime.types;
default_type application/octet-stream;
sendfile on;

# Must read the body in 5 seconds.
client_body_timeout <%= ENV['NGINX_CLIENT_BODY_TIMEOUT'] || 5 %>;

server {
listen <%= ENV["PORT"] %>;
server_name _;
keepalive_timeout 5;
client_max_body_size <%= ENV['NGINX_CLIENT_MAX_BODY_SIZE'] || 1 %>M;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# Proxy pass ExpressJS Server.
proxy_pass http://127.0.0.1:8080;
}

# Proxy pass to Backend service
location /api/ {
proxy_pass http://127.0.0.1:8888/;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_set_header X-Forwarded-Host $server_name;
}
}
}
4 changes: 4 additions & 0 deletions frontend/heroku.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "Installing npm packages..."
npm install
echo "Done!"
13 changes: 10 additions & 3 deletions frontend/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const path = require("path");
const fs = require("fs");

const express = require("express");
const serveStatic = require("serve-static");
const path = require("path");

const app = express();

Expand All @@ -12,6 +14,11 @@ app.get(/.*/, function(req, res) {
res.sendFile(path.join(__dirname, "/dist/index.html"));
});

const port = process.env.PORT || 8080;
app.listen(port);
const port = 8080;
app.listen(port, () => {
if (process.env.DYNO) {
console.log("Running on Heroku!");
fs.openSync("/tmp/app-initialized", "w");
}
});
console.log(`Server is listening on port: ${port}`);
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "ahah, fooled you heroku πŸ™ƒ",
"version": "0.1.0"
}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ahah, fooled you heroku πŸ™ƒ
honcho
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.7.2
3 changes: 3 additions & 0 deletions santosbot.Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
frontend: cd frontend && ./heroku.sh && cd .. && bin/start-nginx node frontend/server.js
backend: cd backend && ./heroku.sh
bot: cd bot && ./heroku.sh

0 comments on commit 462b27a

Please sign in to comment.