Skip to content

Commit

Permalink
Merge pull request #725 from jc21/develop
Browse files Browse the repository at this point in the history
v2.7.0
  • Loading branch information
jc21 committed Nov 18, 2020
2 parents cf8812c + 657ee73 commit 1c43cc2
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 103 deletions.
10 changes: 0 additions & 10 deletions .jenkins/config-mysql.json

This file was deleted.

11 changes: 0 additions & 11 deletions .jenkins/config-sqlite.json

This file was deleted.

2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.2
2.7.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center">
<img src="https://nginxproxymanager.com/github.png">
<br><br>
<img src="https://img.shields.io/badge/version-2.6.2-green.svg?style=for-the-badge">
<img src="https://img.shields.io/badge/version-2.7.0-green.svg?style=for-the-badge">
<a href="https://hub.docker.com/repository/docker/jc21/nginx-proxy-manager">
<img src="https://img.shields.io/docker/stars/jc21/nginx-proxy-manager.svg?style=for-the-badge">
</a>
Expand Down
87 changes: 86 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

const logger = require('./logger').global;

function appStart () {
async function appStart () {
// Create config file db settings if environment variables have been set
await createDbConfigFromEnvironment();

const migrate = require('./migrate');
const setup = require('./setup');
const app = require('./app');
const apiValidator = require('./lib/validator/api');
const internalCertificate = require('./internal/certificate');
const internalIpRanges = require('./internal/ip_ranges');


return migrate.latest()
.then(setup)
.then(() => {
Expand Down Expand Up @@ -39,6 +43,87 @@ function appStart () {
});
}

async function createDbConfigFromEnvironment(){
return new Promise((resolve, reject) => {
const envMysqlHost = process.env.DB_MYSQL_HOST;
const envMysqlPort = process.env.DB_MYSQL_PORT;
const envMysqlUser = process.env.DB_MYSQL_USER;
const envMysqlName = process.env.DB_MYSQL_NAME;
const envSqliteFile = process.env.DB_SQLITE_FILE;
if ((envMysqlHost && envMysqlPort && envMysqlUser && envMysqlName) || envSqliteFile) {
const fs = require('fs');
const filename = (process.env.NODE_CONFIG_DIR || './config') + '/' + (process.env.NODE_ENV || 'default') + '.json';
let configData = {};

try {
configData = require(filename);
} catch (err) {
// do nothing
}

if (configData.database && configData.database.engine && !configData.database.fromEnv) {
logger.info('Manual db configuration already exists, skipping config creation from environment variables');
resolve();
return;
}

if (envMysqlHost && envMysqlPort && envMysqlUser && envMysqlName) {
const newConfig = {
fromEnv: true,
engine: 'mysql',
host: envMysqlHost,
port: envMysqlPort,
user: envMysqlUser,
password: process.env.DB_MYSQL_PASSWORD,
name: envMysqlName,
};

if (JSON.stringify(configData.database) === JSON.stringify(newConfig)) {
// Config is unchanged, skip overwrite
resolve();
return;
}

logger.info('Generating MySQL db configuration from environment variables');
configData.database = newConfig;

} else {
const newConfig = {
fromEnv: true,
engine: 'knex-native',
knex: {
client: 'sqlite3',
connection: {
filename: envSqliteFile
}
}
};
if (JSON.stringify(configData.database) === JSON.stringify(newConfig)) {
// Config is unchanged, skip overwrite
resolve();
return;
}

logger.info('Generating Sqlite db configuration from environment variables');
configData.database = newConfig;
}

// Write config
fs.writeFile(filename, JSON.stringify(configData, null, 2), (err) => {
if (err) {
logger.error('Could not write db config to config file: ' + filename);
reject(err);
} else {
logger.info('Wrote db configuration to config file: ' + filename);
resolve();
}
});
} else {
// resolve();
}
});
}

try {
appStart();
} catch (err) {
Expand Down
7 changes: 7 additions & 0 deletions backend/internal/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ const internalCertificate = {
return saved_row;
});
});
}).catch(async (error) => {
// Delete the certificate from the database if it was not created successfully
await certificateModel
.query()
.deleteById(certificate.id);

throw error;
});
} else {
return certificate;
Expand Down
16 changes: 10 additions & 6 deletions docker/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ services:
fullstack-mysql:
image: ${IMAGE}:ci-${BUILD_NUMBER}
environment:
- NODE_ENV=development
- FORCE_COLOR=1
NODE_ENV: "development"
FORCE_COLOR: 1
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "npm"
DB_MYSQL_PASSWORD: "npm"
DB_MYSQL_NAME: "npm"
volumes:
- npm_data:/data
- ../.jenkins/config-mysql.json:/app/config/development.json
expose:
- 81
- 80
Expand All @@ -20,11 +24,11 @@ services:
fullstack-sqlite:
image: ${IMAGE}:ci-${BUILD_NUMBER}
environment:
- NODE_ENV=development
- FORCE_COLOR=1
NODE_ENV: "development"
FORCE_COLOR: 1
DB_SQLITE_FILE: "/data/database.sqlite"
volumes:
- npm_data:/data
- ../.jenkins/config-sqlite.json:/app/config/development.json
expose:
- 81
- 80
Expand Down
14 changes: 10 additions & 4 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ services:
networks:
- nginx_proxy_manager
environment:
- NODE_ENV=development
- FORCE_COLOR=1
- DEVELOPMENT=true
#- DISABLE_IPV6=true
NODE_ENV: "development"
FORCE_COLOR: 1
DEVELOPMENT: "true"
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "npm"
DB_MYSQL_PASSWORD: "npm"
DB_MYSQL_NAME: "npm"
# DB_SQLITE_FILE: "/data/database.sqlite"
# DISABLE_IPV6: "true"
volumes:
- npm_data:/data
- le_data:/etc/letsencrypt
Expand Down
27 changes: 9 additions & 18 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,7 @@ footer: MIT Licensed | Copyright © 2016-present jc21.com
- [Docker Install documentation](https://docs.docker.com/install/)
- [Docker-Compose Install documentation](https://docs.docker.com/compose/install/)

2. Create a config file for example
```json
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}
```

3. Create a docker-compose.yml file similar to this:
2. Create a docker-compose.yml file similar to this:

```yml
version: '3'
Expand All @@ -70,8 +56,13 @@ services:
- '80:80'
- '81:81'
- '443:443'
environment:
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "npm"
DB_MYSQL_PASSWORD: "npm"
DB_MYSQL_NAME: "npm"
volumes:
- ./config.json:/app/config/production.json
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
db:
Expand All @@ -85,13 +76,13 @@ services:
- ./data/mysql:/var/lib/mysql
```

4. Bring up your stack
3. Bring up your stack

```bash
docker-compose up -d
```

5. Log in to the Admin UI
4. Log in to the Admin UI

When your docker container is running, connect to it on port `81` for the admin interface.
Sometimes this can take a little bit because of the entropy of keys.
Expand Down

0 comments on commit 1c43cc2

Please sign in to comment.