@sumor/app-deployer
Advanced tools
Comparing version 1.0.2 to 1.0.3
16
cli.js
@@ -20,5 +20,12 @@ #! /usr/bin/env node | ||
program | ||
.command('config') | ||
.description('Config') | ||
.option('-t, --type [type]', 'Target configuration file type, such as yaml, json') | ||
.action(async (options) => { | ||
await entry.config(options) | ||
}) | ||
program | ||
.command('deploy') | ||
.description('Deploy') | ||
.option('-t, --type [type]', 'Target configuration file type, such as yaml, json') | ||
.action(async (options) => { | ||
@@ -28,2 +35,9 @@ await entry.deploy(options) | ||
program | ||
.command('monitor') | ||
.description('Monitor') | ||
.action(async (options) => { | ||
await entry.monitor(options) | ||
}) | ||
program.parse() |
65
index.js
@@ -1,16 +0,67 @@ | ||
import deployScope from './src/deploy/index.js' | ||
import loadConfig from './src/config/index.js' | ||
import updateSSL from './src/deploy/ssl/index.js' | ||
import monitoring from './src/monitor/index.js' | ||
import scale from './src/deploy/scale/index.js' | ||
import updateSite from './src/deploy/site/index.js' | ||
import getInstances from './src/deploy/instance/index.js' | ||
const config = async (options) => { | ||
const configData = await loadConfig(options) | ||
console.log('Config Data:') | ||
console.log(JSON.stringify(configData, null, 4)) | ||
} | ||
const deploy = async (options) => { | ||
options = options || {} | ||
options.root = options.root || process.cwd() | ||
const config = await loadConfig(options.root, options.type) | ||
await deployScope(config) | ||
const config = await loadConfig(options) | ||
const startTime = Date.now() | ||
console.log('正在启动部署') | ||
// 更新证书 | ||
console.log('\n\n ==================== 更新证书 ==================== \n') | ||
await updateSSL(config) | ||
// 获取服务器实例状态 | ||
console.log('\n\n ==================== 获取服务器实例状态 ==================== \n') | ||
const instances = await getInstances(config.server) | ||
for (const server in instances) { | ||
console.log(`服务器${server}现存实例列表`) | ||
for (const i in instances[server]) { | ||
console.log(`- ${instances[server][i]}`) | ||
} | ||
} | ||
// 部署应用 | ||
console.log('\n\n ==================== 部署应用 ==================== \n') | ||
await scale(config, instances) | ||
console.log('\n\n ==================== 实例情况 ==================== \n') | ||
console.log(instances) | ||
await updateSite(config, instances) | ||
console.log(`所有应用已完成部署 ${Date.now() - startTime}ms`) | ||
} | ||
const monitor = async (options) => { | ||
const config = await loadConfig(options) | ||
console.log('\n\n ==================== 获取服务器运行状态 ==================== \n') | ||
for (const server in config.server) { | ||
const system = await monitoring(config.server[server]) | ||
console.log(`服务器${server}运行状态`) | ||
console.log(system) | ||
} | ||
} | ||
export { | ||
deploy | ||
config, | ||
deploy, | ||
monitor | ||
} | ||
export default { | ||
deploy | ||
config, | ||
deploy, | ||
monitor | ||
} |
{ | ||
"name": "@sumor/app-deployer", | ||
"description": "A simple tool to deploy docker containers to a remote server.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"license": "MIT", | ||
@@ -50,11 +50,10 @@ "repository": "sumor-cloud/app-deployer", | ||
"test-config": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/config.test.js'", | ||
"test-ssl": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/ssl/*.test.js'", | ||
"test-monitor": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/monitor.test.js'", | ||
"test-site": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/site/**/*.test.js'", | ||
"test-scale-version": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/version/**/*.test.js'", | ||
"test-scale-scale": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/scale.test.js'", | ||
"test-deploy-ssl": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/ssl/*.test.js'", | ||
"test-deploy-site": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/site/**/*.test.js'", | ||
"test-deploy-version": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/version/**/*.test.js'", | ||
"test-deploy-scale": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/scale.test.js'", | ||
"test-utils": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/utils/*.test.js'", | ||
"test-docker": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/docker.test.js'", | ||
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --testMatch='**/test/**/*.test.js'", | ||
"push-tag": "git push --tags && git push", | ||
"push-tag": "git push && git push --tags", | ||
"publish-beta": "npm version prerelease --preid beta && npm run push-tag", | ||
@@ -61,0 +60,0 @@ "publish-release-patch": "npm version patch && npm run push-tag", |
@@ -5,3 +5,7 @@ import load from './load.js' | ||
export default async (root, type) => { | ||
export default async (options) => { | ||
options = options || {} | ||
const root = options.root || process.cwd() | ||
const type = options.type | ||
const config = await load(root, 'scope') || {} | ||
@@ -8,0 +12,0 @@ if (type) { |
import updateSite from '../site/index.js' | ||
import SSH from '../../ssh/index.js' | ||
import SSH from '../../utils/ssh/index.js' | ||
export default async (config, keep, server, cut) => { | ||
await updateSite(config, keep) | ||
export default async (config, instances, server, cut) => { | ||
await updateSite(config, instances) | ||
for (const id of cut) { | ||
@@ -7,0 +7,0 @@ console.log(`清除实例${id}`) |
import fse from 'fs-extra' | ||
import SSH from '../../ssh/index.js' | ||
import SSH from '../../utils/ssh/index.js' | ||
import clone from './version/setup/index.js' | ||
@@ -4,0 +4,0 @@ import buildNodeJS from './version/build/buildNodeJS.js' |
import fse from 'fs-extra' | ||
import SSH from '../../ssh/index.js' | ||
import SSH from '../../utils/ssh/index.js' | ||
import updateSite from '../site/index.js' | ||
@@ -4,0 +4,0 @@ import deployNode from './deployNode.js' |
import fse from 'fs-extra' | ||
import cmd from '../../../utils/cmd.js' | ||
import cmd from '../../../../utils/cmd.js' | ||
@@ -4,0 +4,0 @@ export default async (sourceFolder, targetFolder) => { |
@@ -1,2 +0,2 @@ | ||
import cmd from '../../../utils/cmd.js' | ||
import cmd from '../../../../utils/cmd.js' | ||
@@ -3,0 +3,0 @@ /* Example CMD [git branch -vva] output: |
@@ -1,2 +0,2 @@ | ||
import cmd from '../../../utils/cmd.js' | ||
import cmd from '../../../../utils/cmd.js' | ||
@@ -3,0 +3,0 @@ export default async (root, branch) => { |
@@ -1,2 +0,2 @@ | ||
import cmd from '../../../utils/cmd.js' | ||
import cmd from '../../../../utils/cmd.js' | ||
@@ -3,0 +3,0 @@ export default async (folder) => { |
import fse from 'fs-extra' | ||
import cmd from '../../../utils/cmd.js' | ||
import cmd from '../../../../utils/cmd.js' | ||
import stringifyUrl from './stringifyUrl.js' | ||
@@ -4,0 +4,0 @@ |
@@ -1,5 +0,5 @@ | ||
import SSH from '../../../ssh/index.js' | ||
import SSH from '../../../utils/ssh/index.js' | ||
import pages from './pages.js' | ||
export default async (server, nginxConfig, force) => { | ||
export default async (server, nginxConfig) => { | ||
const ssh = new SSH(server) | ||
@@ -15,5 +15,2 @@ const sitePath = '/usr/sumor-cloud/nginx' | ||
// if (force) { | ||
// await ssh.docker.remove(instanceId) | ||
// } | ||
await ssh.docker.remove(instanceId) | ||
@@ -30,3 +27,3 @@ | ||
const runConfig = [ | ||
'docker run -itd', | ||
'docker run -itd --restart=on-failure', | ||
`-v ${sitePath}/nginx.conf:/etc/nginx/nginx.conf`, | ||
@@ -33,0 +30,0 @@ `-v ${sitePath}/pages:/etc/nginx/pages`, |
@@ -1,2 +0,2 @@ | ||
import section from './formatter/section.js' | ||
import section from '../utils/formatter/section.js' | ||
@@ -3,0 +3,0 @@ export default () => section('server', [ |
@@ -1,3 +0,3 @@ | ||
import section from './formatter/section.js' | ||
import entity from './formatter/entity.js' | ||
import section from '../utils/formatter/section.js' | ||
import entity from '../utils/formatter/entity.js' | ||
@@ -11,3 +11,5 @@ export default (app) => { | ||
'proxy_set_header X-Forwarded-For': '$remote_addr', | ||
proxy_pass: `https://${app.name}_stream` | ||
proxy_pass: `https://${app.name}_stream`, | ||
proxy_ssl_server_name: 'on', | ||
proxy_ssl_name: '$host' | ||
}) | ||
@@ -27,8 +29,7 @@ } else { | ||
error_log: `/tmp/${app.name}_error.log`, | ||
ssl_certificate: `ssl/${app.domain}/domain.cer`, | ||
ssl_certificate: `ssl/${app.domain}/domain.crt`, | ||
ssl_certificate_key: `ssl/${app.domain}/domain.key`, | ||
ssl_client_certificate: `ssl/${app.domain}/ca.cer`, | ||
ssl_session_timeout: '5m', | ||
ssl_ciphers: 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4', | ||
ssl_protocols: 'TLSv1 TLSv1.1 TLSv1.2', | ||
ssl_ciphers: 'EECDH+AESGCM:EECDH+CHACHA20:ECDH+AESGCM:ECDH+AES256:DH+AESGCM:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS', | ||
ssl_protocols: 'TLSv1.2 TLSv1.3', | ||
ssl_prefer_server_ciphers: 'on' | ||
@@ -35,0 +36,0 @@ }), |
@@ -1,8 +0,8 @@ | ||
import entity from './formatter/entity.js' | ||
import connect from './formatter/connect.js' | ||
import entity from '../utils/formatter/entity.js' | ||
import connect from '../utils/formatter/connect.js' | ||
import httpServer from './httpServer.js' | ||
import section from './formatter/section.js' | ||
import section from '../utils/formatter/section.js' | ||
import upstream from './upstream.js' | ||
import httpsServer from './httpsServer.js' | ||
import property from './formatter/property.js' | ||
import property from '../utils/formatter/property.js' | ||
@@ -9,0 +9,0 @@ export default (apps) => { |
@@ -1,2 +0,2 @@ | ||
import section from './formatter/section.js' | ||
import section from '../utils/formatter/section.js' | ||
@@ -3,0 +3,0 @@ export default (name, items) => section(`upstream ${name}_stream`, items.map((obj) => { |
@@ -5,3 +5,3 @@ import generateConfig from './generateConfig/index.js' | ||
export default async (config, instances, force) => { | ||
export default async (config, instances) => { | ||
const site = {} | ||
@@ -36,4 +36,4 @@ for (const envApp of config.live) { | ||
await deployNginx(config.server[server], nginxConfig, force) | ||
await deployNginx(config.server[server], nginxConfig) | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import SSH from '../../ssh/index.js' | ||
import SSH from '../../utils/ssh/index.js' | ||
import fse from 'fs-extra' | ||
@@ -3,0 +3,0 @@ import os from 'os' |
@@ -9,3 +9,2 @@ import copySSL from './copySSL.js' | ||
for (const domain of domains) { | ||
console.log(`更新${domain}域名证书到${server}服务器`) | ||
await copySSL(info, domain) | ||
@@ -12,0 +11,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46423
1295
3