Skip to content

Instantly share code, notes, and snippets.

@Kmaschta
Created December 12, 2017 16:49
Show Gist options
  • Save Kmaschta/0920c6a7781cdf15c37a51b370e4fb66 to your computer and use it in GitHub Desktop.
Save Kmaschta/0920c6a7781cdf15c37a51b370e4fb66 to your computer and use it in GitHub Desktop.
Artifact deployment example
.PHONY: build
TAG ?=
SERVER ?= staging-server
install:
npm install
start:
node --require reify server.js
build:
mkdir -p build
zip 'build/$(shell git log -1 --pretty="%h").zip' Makefile package.json -R . '*.js' -R . '*.json'
deploy:
scp build/$(TAG).zip $(SERVER):/data/www/deployment-example/
ssh $(SERVER) " \
cd /data/www/deployment-example/ \
unzip $(TAG).zip -d $(TAG)/ && rm $(TAG).zip \ # unzip the code in a folder
cd current/ && make stop \ # stop the current server
cd ../ && rm current/ && ln -s $(TAG)/ current/ \ # move the symbolic link to the new version
cd current/ && make start \ # restart the server
"
echo 'Deployed $(TAG) version to $(SERVER)'
{
"name": "deployment-example",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"dependencies": {
"axios": "~0.17.1",
"express": "~4.16.2",
"reify": "~0.13.0"
}
}
import uuid from 'uuid';
import axios from 'axios';
import express from 'express';
const port = process.env.NODE_PORT || 3000;
const baseURL = process.env.PROXY_HOST || 'http://perdu.com/';
const client = axios.create({ baseURL });
const app = express();
app.get('/', (req, res) => {
const requestOptions = {
url: req.path,
method: req.method.toLowerCase(),
headers: { 'X-Random': uuid.v4() },
};
return client(requestOptions).then(response => res.send(response.data));
});
app.listen(port);
console.log(`Proxy is running on port ${port}. Press Ctrl+C to stop.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment