BREAKING CHANGE(scope): change scope to @pushrocks

This commit is contained in:
Philipp Kunz 2018-08-10 23:10:48 +02:00
parent 381227406b
commit 9b043d0e0d
17 changed files with 1368 additions and 345 deletions

View File

@ -10,7 +10,7 @@ before_script:
testSTABLE:
stage: test
script:
- npmci test stable
- npmci npm test stable
only:
- tags
tags:
@ -20,7 +20,7 @@ release:
stage: release
environment: npmjs-com_registry
script:
- npmci publish
- npmci npm publish
only:
- tags
tags:

View File

@ -1,27 +1,30 @@
# smartnginx
control nginx from node, TypeScript ready
## Status
[![build status](https://gitlab.com/pushrocks/smartnginx/badges/master/build.svg)](https://gitlab.com/pushrocks/smartnginx/commits/master)
## Features
* easy reverse configuration
* automatic letsencrypt DNS01 challenge based ssl cert generation
* automatic nginx process handling zero-downtime config reloading
* works in Docker environements
- easy reverse configuration
- automatic letsencrypt DNS01 challenge based ssl cert generation
- automatic nginx process handling zero-downtime config reloading
- works in Docker environements
## Usage
We recommend the use of TypeScript! :)
```typescript
import * as smartnginx from "smartnginx";
myNginxConfig = new smartnginx.NginxConfig();
myNginxZone = new smartnginx.NginxZone({
zoneName:"some.example.com",
type:"reverseProxy",
destination:"192.192.192.192" // some destination IP
import * as smartnginx from 'smartnginx';
const smartnginxInstance = new smartnginx.SmartNginx();
myNginxHost = new smartnginx.NginxHost({
hostName: 'some.example.com',
type: 'reverseProxy',
destination: '192.192.192.192' // some destination IP
});
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
```
```

1073
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{
"name": "smartnginx",
"name": "@pushrocks/smartnginx",
"version": "1.0.6",
"description": "control nginx from node, TypeScript ready",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)",
"cleanTest": "(rm -r nginxconfig)"
"test": "tstest test/",
"cleanTest": "(rm -r nginxconfig) && npm run test",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -22,19 +23,18 @@
},
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
"dependencies": {
"@types/q": "0.x.x",
"@types/shelljs": "0.x.x",
"beautylog": "^5.0.20",
"cert": "^1.0.7",
"q": "^1.4.1",
"shelljs": "^0.7.3",
"smartfile": "^4.0.13",
"smartstring": "^2.0.15"
"@pushrocks/smartfile": "^6.0.6",
"@pushrocks/smartlog": "^2.0.1",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartshell": "^2.0.6",
"@pushrocks/smartstring": "^3.0.0"
},
"devDependencies": {
"npmts-g": "^5.2.8",
"qenv": "^1.0.8",
"should": "^10.0.0",
"typings-test": "^1.0.1"
}
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.1.12",
"@gitzone/tstest": "^1.0.13",
"@pushrocks/tapbundle": "^3.0.5",
"qenv": "^1.1.7"
},
"private": true
}

View File

@ -1,3 +1 @@
vars:
- CF_EMAIL
- CF_KEY

2
test/test.d.ts vendored
View File

@ -1,2 +0,0 @@
import "typings-test";
import "should";

View File

@ -1,61 +0,0 @@
"use strict";
require("typings-test");
const path = require("path");
require("should");
const qenv_1 = require("qenv");
const smartnginx = require("../dist/index");
// setup environment
let testQenv = new qenv_1.Qenv(process.cwd(), path.join(process.cwd(), ".nogit"));
describe("smartnginx", function () {
let testNginxConfig;
let testNginxZone01;
let testNginxZone02;
describe("NginxZone", function () {
it(`"new NginxZone()" should produce an instance of NginxConfig`, function () {
testNginxZone01 = new smartnginx.NginxHost({
hostName: "test100.bleu.de",
type: smartnginx.hostTypes.reverseProxy,
destination: "192.192.192.191"
});
testNginxZone02 = new smartnginx.NginxHost({
hostName: "test102.bleu.de",
type: smartnginx.hostTypes.reverseProxy,
destination: "192.192.192.192"
});
testNginxZone01.should.be.instanceof(smartnginx.NginxHost);
console.log(testNginxZone01.configString);
});
});
describe("NginxConfig", function () {
this.timeout(10000);
it(`"new NginxConfig()" should produce an instance of NginxConfig`, function () {
testNginxConfig = new smartnginx.NginxConfig({
cfEmail: process.env.CF_EMAIL,
cfKey: process.env.CF_KEY,
testMode: true
});
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
});
describe(".addZone()", function () {
it("should add a zone to NginxConfig Object", function () {
testNginxConfig.addHost(testNginxZone01);
testNginxConfig.addHost(testNginxZone02);
});
});
describe(".deploy()", function () {
this.timeout(600000);
it("should deploy a config from an instance", function (done) {
testNginxConfig.deploy()
.then(() => {
done();
});
});
});
describe(".stop", function () {
it("should end the process", function () {
testNginxConfig.nginxProcess.stop();
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQix1QkFBbUIsTUFBTSxDQUFDLENBQUE7QUFDMUIsTUFBWSxVQUFVLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFFNUMsb0JBQW9CO0FBQ3BCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxRQUFRLENBQUMsQ0FBQyxDQUFDO0FBQ3pFLFFBQVEsQ0FBQyxZQUFZLEVBQUM7SUFDbEIsSUFBSSxlQUFzQyxDQUFDO0lBQzNDLElBQUksZUFBb0MsQ0FBQztJQUN6QyxJQUFJLGVBQW9DLENBQUM7SUFDekMsUUFBUSxDQUFDLFdBQVcsRUFBQztRQUNqQixFQUFFLENBQUMsNkRBQTZELEVBQUM7WUFDN0QsZUFBZSxHQUFHLElBQUksVUFBVSxDQUFDLFNBQVMsQ0FBQztnQkFDdkMsUUFBUSxFQUFDLGlCQUFpQjtnQkFDMUIsSUFBSSxFQUFDLFVBQVUsQ0FBQyxTQUFTLENBQUMsWUFBWTtnQkFDdEMsV0FBVyxFQUFDLGlCQUFpQjthQUNoQyxDQUFDLENBQUM7WUFDSCxlQUFlLEdBQUcsSUFBSSxVQUFVLENBQUMsU0FBUyxDQUFDO2dCQUN2QyxRQUFRLEVBQUMsaUJBQWlCO2dCQUMxQixJQUFJLEVBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxZQUFZO2dCQUN0QyxXQUFXLEVBQUMsaUJBQWlCO2FBQ2hDLENBQUMsQ0FBQztZQUNILGVBQWUsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLENBQUM7WUFDM0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMsWUFBWSxDQUFDLENBQUM7UUFDOUMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQztJQUNILFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FBQztRQUNwQixFQUFFLENBQUMsK0RBQStELEVBQUM7WUFDL0QsZUFBZSxHQUFHLElBQUksVUFBVSxDQUFDLFdBQVcsQ0FBQztnQkFDekMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUTtnQkFDN0IsS0FBSyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTTtnQkFDekIsUUFBUSxFQUFDLElBQUk7YUFDaEIsQ0FBQyxDQUFDO1lBQ0gsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNqRSxDQUFDLENBQUMsQ0FBQztRQUNILFFBQVEsQ0FBQyxZQUFZLEVBQUM7WUFDbEIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO2dCQUN6QyxlQUFlLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO2dCQUN6QyxlQUFlLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1lBQzdDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsV0FBVyxFQUFDO1lBQ2pCLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7WUFDckIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDLFVBQVMsSUFBSTtnQkFDdEQsZUFBZSxDQUFDLE1BQU0sRUFBRTtxQkFDbkIsSUFBSSxDQUFDO29CQUNGLElBQUksRUFBRSxDQUFDO2dCQUNYLENBQUMsQ0FBQyxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztRQUNILFFBQVEsQ0FBQyxPQUFPLEVBQUM7WUFDYixFQUFFLENBQUMsd0JBQXdCLEVBQUM7Z0JBQ3hCLGVBQWUsQ0FBQyxZQUFZLENBQUMsSUFBSSxFQUFFLENBQUM7WUFDeEMsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -1,60 +1,45 @@
import "typings-test";
import path = require("path");
import "should";
import {Qenv} from "qenv";
import * as smartnginx from "../dist/index";
import { tap, expect } from '@pushrocks/tapbundle';
import path = require('path');
// setup environment
let testQenv = new Qenv(process.cwd(),path.join(process.cwd(),".nogit"));
describe("smartnginx",function(){
let testNginxConfig:smartnginx.NginxConfig;
let testNginxZone01:smartnginx.NginxHost;
let testNginxZone02:smartnginx.NginxHost;
describe("NginxZone",function(){
it(`"new NginxZone()" should produce an instance of NginxConfig`,function(){
testNginxZone01 = new smartnginx.NginxHost({
hostName:"test100.bleu.de",
type:smartnginx.hostTypes.reverseProxy,
destination:"192.192.192.191"
});
testNginxZone02 = new smartnginx.NginxHost({
hostName:"test102.bleu.de",
type:smartnginx.hostTypes.reverseProxy,
destination:"192.192.192.192"
});
testNginxZone01.should.be.instanceof(smartnginx.NginxHost);
console.log(testNginxZone01.configString);
});
});
describe("NginxConfig",function(){
this.timeout(10000);
it(`"new NginxConfig()" should produce an instance of NginxConfig`,function(){
testNginxConfig = new smartnginx.NginxConfig({
cfEmail: process.env.CF_EMAIL,
cfKey: process.env.CF_KEY,
testMode:true
});
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
});
describe(".addZone()",function(){
it("should add a zone to NginxConfig Object",function(){
testNginxConfig.addHost(testNginxZone01);
testNginxConfig.addHost(testNginxZone02);
})
});
describe(".deploy()",function(){
this.timeout(600000);
it("should deploy a config from an instance",function(done){
testNginxConfig.deploy()
.then(() => {
done();
});
})
});
describe(".stop",function(){
it("should end the process",function(){
testNginxConfig.nginxProcess.stop();
})
})
});
import { Qenv } from 'qenv';
let testQenv = new Qenv(process.cwd(), path.join(process.cwd(), '.nogit'));
import * as smartnginx from '../ts';
let testSmartNginx: smartnginx.SmartNginx;
let testNginxZone01: smartnginx.NginxHost;
let testNginxZone02: smartnginx.NginxHost;
tap.test('should create a valid instance of SmartNginx', async () => {
testSmartNginx = new smartnginx.SmartNginx();
expect(testSmartNginx).to.be.instanceof(smartnginx.SmartNginx);
});
tap.test(`should produce an instance of NginxConfig`, async () => {
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test100.bleu.de',
destination: '192.192.192.191'
});
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test102.bleu.de',
destination: '192.192.192.192'
});
expect(testNginxZone01).to.be.instanceof(smartnginx.NginxHost);
console.log(testNginxZone01.configString);
});
tap.test('.addZone() should add a zone to NginxConfig Object', async () => {
testSmartNginx.addHost(testNginxZone01);
testSmartNginx.addHost(testNginxZone02);
});
tap.test('.deploy() should deploy a config from an instance', async () => {
await testSmartNginx.deploy();
});
tap.test('.stop() should end the process', async () => {
testSmartNginx.nginxProcess.stop();
});
tap.start();

View File

@ -1,6 +1,6 @@
import * as plugins from "./smartnginx.plugins";
import * as plugins from './smartnginx.plugins';
// classes
export * from "./smartnginx.classes.nginxconfig";
export * from "./smartnginx.classes.nginxprocess";
export * from "./smartnginx.classes.nginxhost";
export * from './smartnginx.classes.smartnginx';
export * from './smartnginx.classes.nginxprocess';
export * from './smartnginx.classes.nginxhost';

View File

@ -0,0 +1,5 @@
import * as plugins from './smartnginx.plugins';
export class CertHandler {
}

View File

@ -1,71 +0,0 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as snippets from "./smartnginx.snippets";
import { NginxHost } from "./smartnginx.classes.nginxhost";
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
let allConfigs: NginxConfig[] = [];
/**
* main class that manages a NginxInstance
*/
export class NginxConfig {
hosts: NginxHost[] = [];
cert: plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
nginxProcess: NginxProcess = new NginxProcess(this);
isDeployed: boolean = false;
constructor(optionsArg: plugins.cert.ICertConstructorOptions) {
this.cert = new plugins.cert.Cert({
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey,
sslDir: paths.nginxCertBase,
gitOriginRepo: optionsArg.gitOriginRepo,
testMode: optionsArg.testMode
});
};
// interact with Hosts
addHost(nginxHostArg: NginxHost){
this.hosts.push(nginxHostArg);
}
listHosts(): NginxHost[]{
return this.hosts;
};
removeHost(nginxHostArg: NginxHost) {
}
clean() {
this.hosts = [];
}
// handle deployment of hosts
deploy() {
let done = plugins.q.defer();
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
for (let config of allConfigs) {
config.isDeployed = false;
};
this.isDeployed = true;
// write base config
plugins.smartfile.memory.toFsSync(
snippets.getBaseConfigString(),
paths.nginxConfFile
);
// deploy hosts
let promiseArray = [];
for (let host of this.hosts) {
let hostDeployedPromise = host.deploy(this.cert);
hostDeployedPromise.then(() => {
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(hostDeployedPromise);
};
plugins.q.all(promiseArray)
.then(() => {
done.resolve();
});
return done.promise;
};
};

View File

@ -1,43 +1,47 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as snippets from "./smartnginx.snippets"
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
import * as snippets from './smartnginx.snippets';
import { SmartNginx } from './smartnginx.classes.smartnginx';
/**
* the host config data that NginxHost needs to create a valid instance
*/
export interface IHostConfigData {
hostName: string,
type: hostTypes,
destination: string
hostName: string;
destination: string;
}
export enum hostTypes {
reverseProxy,
static
reverseProxy
}
/**
* manages a single nginx host
*/
export class NginxHost {
hostName: string; // the host name e.g. domain name
type: hostTypes;
destination: string;
configString: string; // the actual host config file as string
constructor(optionsArg:IHostConfigData) {
this.hostName = optionsArg.hostName;
this.type = optionsArg.type;
this.destination = optionsArg.destination;
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
};
deploy(certInstanceArg: plugins.cert.Cert) {
let done = plugins.q.defer();
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + ".conf");
// writeConfig
plugins.smartfile.memory.toFsSync(this.configString, filePath);
// get cert
certInstanceArg.getDomainCert(this.hostName)
.then(done.resolve);
return done.promise;
};
};
/**
* smartnginxInstance this NginHost belongs to
*/
smartnginxInstance: SmartNginx
hostName: string; // the host name e.g. domain name
destination: string;
configString: string; // the actual host config file as string
constructor(smartnginxInstanceArg: SmartNginx, optionsArg: IHostConfigData) {
this.smartnginxInstance = smartnginxInstanceArg;
this.hostName = optionsArg.hostName;
this.destination = optionsArg.destination;
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
}
/**
*
* @param certInstanceArg
*/
async deploy() {
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + '.conf');
// writeConfig
plugins.smartfile.memory.toFsSync(this.configString, filePath);
}
}

View File

@ -1,74 +1,82 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
import { NginxHost } from "./smartnginx.classes.nginxhost";
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
import { SmartNginx } from './smartnginx.classes.smartnginx';
import { NginxHost } from './smartnginx.classes.nginxhost';
import { Smartshell } from '@pushrocks/smartshell';
/**
* manages a nginxprocess for an NginxConfig
*/
export class NginxProcess {
started: boolean = false;
nginxConfig:NginxConfig;
nginxChildProcess: plugins.childProcess.ChildProcess;
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
};
started: boolean = false;
nginxConfig: SmartNginx;
nginxChildProcess: plugins.childProcess.ChildProcess;
smartshellInstance = new Smartshell({
executor: 'bash'
});
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
}
/**
* start nginx
*/
start() {
let done = plugins.q.defer();
if (typeof this.nginxChildProcess == "undefined"){
this.nginxChildProcess = plugins.childProcess.exec(`nginx -c ${paths.nginxConfFile}`, function (error, stdout, stderr) {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
};
});
};
this.started = true;
plugins.beautylog.info("started Nginx!");
done.resolve();
return done.promise;
};
/**
* start nginx
*/
start() {
let done = plugins.smartpromise.defer();
if (typeof this.nginxChildProcess == 'undefined') {
this.nginxChildProcess = plugins.childProcess.exec(
`nginx -c ${paths.nginxConfFile}`,
function(error, stdout, stderr) {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
}
);
}
this.started = true;
plugins.smartlog.defaultLogger.info('started Nginx!');
done.resolve();
return done.promise;
}
/**
* reload config
*/
reloadConfig(){
let done = plugins.q.defer();
if(this.started == false){
this.start();
} else {
plugins.shelljs.exec("nginx -s reload");
};
plugins.beautylog.ok("NginxProcess has loaded the new config!")
done.resolve();
return done.promise;
};
/**
* reload config
*/
reloadConfig() {
let done = plugins.smartpromise.defer();
if (this.started == false) {
this.start();
} else {
this.smartshellInstance.exec('nginx -s reload');
}
plugins.smartlog.defaultLogger.info('NginxProcess has loaded the new config!');
done.resolve();
return done.promise;
}
/**
* stop the nginx instance
*/
stop() {
let done = plugins.q.defer();
if (typeof this.nginxChildProcess != "undefined") {
plugins.shelljs.exec("nginx -s quit");
this.started = false;
plugins.beautylog.info("stopped Nginx!");
} else {
plugins.beautylog.log("nginx already stopped!");
};
done.resolve();
return done.promise;
};
/**
* stop the nginx instance
*/
stop() {
let done = plugins.smartpromise.defer();
if (typeof this.nginxChildProcess != 'undefined') {
this.smartshellInstance.exec('nginx -s quit');
this.started = false;
plugins.smartlog.defaultLogger.info('stopped Nginx!');
} else {
plugins.smartlog.defaultLogger.info('nginx already stopped!');
}
done.resolve();
return done.promise;
}
/**
* checks if nginx is in path
*/
check(): boolean {
return;
};
/**
* checks if nginx is in path
*/
check(): boolean {
return;
}
}

View File

@ -0,0 +1,74 @@
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
import * as snippets from './smartnginx.snippets';
import { NginxHost } from './smartnginx.classes.nginxhost';
import { NginxProcess } from './smartnginx.classes.nginxprocess';
import { CertHandler } from './smartnginx.classes.certhandler';
let allConfigs: SmartNginx[] = [];
/**
* main class that manages a NginxInstance
*/
export class SmartNginx {
certHandler = new CertHandler();
hosts: NginxHost[] = [];
nginxProcess: NginxProcess = new NginxProcess(this);
isDeployed: boolean = false;
constructor() {
};
// ===================
// interact with Hosts
// ===================
/**
* add a host
* @param nginxHostArg
*/
addHost(nginxHostArg: NginxHost) {
this.hosts.push(nginxHostArg);
}
/**
* listHosts
*/
listHosts(): NginxHost[] {
return this.hosts;
}
/**
* remove a Host
* @param nginxHostArg
*/
removeHost(nginxHostArg: NginxHost) {}
/**
* clean all hosts
*/
clean() {
this.hosts = [];
}
/**
* deploy the current stack and restart nginx
*/
async deploy() {
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
for (let config of allConfigs) {
config.isDeployed = false;
}
this.isDeployed = true;
// write base config
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
// deploy hosts
let promiseArray = [];
for (let host of this.hosts) {
await host.deploy();
plugins.smartlog.defaultLogger.info(`Host ${host.hostName} deployed!`);
this.nginxProcess.reloadConfig();
};
}
}

View File

@ -1,10 +1,11 @@
import * as plugins from "./smartnginx.plugins"
import * as plugins from './smartnginx.plugins';
// directories
export let packageBase = plugins.path.join(__dirname,"../");
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig");
export let nginxHostFileBase = plugins.path.join(nginxConfigBase,"hosts");
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
export let packageBase = plugins.path.join(__dirname, '../');
export let nginxConfigBase = plugins.path.join(packageBase, 'nginxconfig');
export let nginxHostFileBase = plugins.path.join(nginxConfigBase, 'hosts');
export let nginxCertBase = plugins.path.join(nginxConfigBase, 'cert');
// files
export let nginxConfFile = plugins.path.join(nginxConfigBase,"nginx.conf");
export let nginxConfFile = plugins.path.join(nginxConfigBase, 'nginx.conf');

View File

@ -1,9 +1,17 @@
import "typings-global";
export import beautylog = require("beautylog");
export import cert = require("cert");
export import childProcess = require("child_process");
export import path = require("path");
export import q = require("q");
export import shelljs = require("shelljs");
export import smartfile = require("smartfile");
export import smartstring = require("smartstring");
import * as smartlog from '@pushrocks/smartlog';
import * as childProcess from 'child_process';
import * as path from 'path';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartshell from '@pushrocks/smartshell';
import * as smartfile from '@pushrocks/smartfile';
import * as smartstring from '@pushrocks/smartstring';
export {
smartlog,
childProcess,
path,
smartpromise,
smartshell,
smartfile,
smartstring
}

View File

@ -1,7 +1,7 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
export let getBaseConfigString = () => {
let baseConfig = plugins.smartstring.indent.normalize(`
let baseConfig = plugins.smartstring.indent.normalize(`
user www-data;
worker_processes auto;
pid /run/nginx.pid;
@ -68,12 +68,11 @@ export let getBaseConfigString = () => {
}
daemon off;
`);
return baseConfig;
}
return baseConfig;
};
export let getHostConfigString = (hostNameArg:string,destinationIpArg:string) => {
let hostConfig = plugins.smartstring.indent.normalize(`
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
let hostConfig = plugins.smartstring.indent.normalize(`
upstream ${hostNameArg} {
server ${destinationIpArg};
}
@ -99,6 +98,5 @@ export let getHostConfigString = (hostNameArg:string,destinationIpArg:string) =>
}
}
`);
return hostConfig;
return hostConfig;
};