-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto_compose, generate docker_compose file via mdeprc
- Loading branch information
Showing
11 changed files
with
245 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* eslint-disable no-use-before-define, no-template-curly-in-string */ | ||
const jsYaml = require('js-yaml'); | ||
const os = require('os'); | ||
const fs = require('fs'); | ||
const hyperid = require('hyperid'); | ||
const merge = require('lodash.merge'); | ||
const path = require('path'); | ||
|
||
const SERVICE_MAP = { | ||
redis, | ||
redisCluster, | ||
redisSentinel, | ||
postgres, | ||
rabbitmq, | ||
}; | ||
|
||
exports.SERVICE_MAP = SERVICE_MAP; | ||
exports.command = 'compose'; | ||
exports.desc = 'prepares docker-compose file based on config'; | ||
exports.handler = (argv) => { | ||
const getId = hyperid({ fixedLength: true, urlSafe: true }); | ||
|
||
// Header of the file | ||
const compose = {}; | ||
compose.version = '3'; | ||
compose.networks = {}; | ||
compose.services = {}; | ||
|
||
// Identification | ||
if (Array.isArray(argv.services) && argv.services.length) { | ||
for (const service of argv.services) { | ||
const ctor = SERVICE_MAP[service]; | ||
if (ctor === undefined) { | ||
throw new Error(`no support for ${service}, please add it to @makeomatic/deploy`); | ||
} | ||
|
||
ctor(compose, argv); | ||
} | ||
} | ||
|
||
// add default tester service | ||
tester(compose, argv); | ||
|
||
// finalize and push out to tmp | ||
const dir = os.tmpdir(); | ||
const filename = `docker-compose.${getId()}.yml`; | ||
const location = `${dir}/${filename}`; | ||
|
||
// write out the file | ||
fs.writeFileSync(location, jsYaml.safeDump(compose)); | ||
|
||
// rewrite location of docker-compose | ||
argv.docker_compose = location; | ||
}; | ||
|
||
/** | ||
* Prepares tester declaration | ||
*/ | ||
function tester(compose, argv) { | ||
compose.services.tester = merge({ | ||
image: argv.tester_image || `makeomatic/node:${argv.node}-${argv.tester_flavour}`, | ||
hostname: 'tester', | ||
working_dir: '/src', | ||
volumes: ['${PWD}:/src'], | ||
environment: { | ||
NODE_ENV: 'test', | ||
}, | ||
command: 'tail -f /dev/null', | ||
}, argv.extras.tester); | ||
} | ||
|
||
function redisCluster(compose, argv) { | ||
compose.services.redisCluster = merge({ | ||
image: 'makeomatic/redis-cluster:3.2.9', | ||
hostname: 'redis-cluster', | ||
}, argv.extras.redisCluster); | ||
} | ||
|
||
function redis(compose, argv) { | ||
compose.services.redis = merge({ | ||
image: 'redis:4.0.11-alpine', | ||
hostname: 'redis', | ||
expose: ['6379'], | ||
}, argv.extras.redis); | ||
} | ||
|
||
function redisSentinel(compose, argv) { | ||
redis(compose, argv); | ||
|
||
const entrypoint = path.resolve(__dirname, '../../../templates/redis-sentinel.sh'); | ||
compose.services.redisSentinel = merge({ | ||
image: 'redis:4.0.11-alpine', | ||
hostname: 'redis-sentinel', | ||
expose: ['26379'], | ||
depends_on: ['redis'], | ||
volumes: [`${entrypoint}:/entrypoint.sh:ro`], | ||
command: '/bin/sh /entrypoint.sh redis', | ||
}, argv.extras.redisSentinel); | ||
} | ||
|
||
function postgres(compose, argv) { | ||
compose.services.postgres = merge({ | ||
image: 'postgres:10.4-alpine', | ||
hostname: 'postgres', | ||
}, argv.extras.postgres); | ||
} | ||
|
||
function rabbitmq(compose, argv) { | ||
compose.services.rabbitmq = merge({ | ||
image: 'rabbitmq:3.7.8-management-alpine', | ||
hostname: 'rabbitmq', | ||
}, argv.extras.rabbitmq); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
# some settings | ||
dir="/etc/redis-sentinel" | ||
configuration="${dir}/redis-sentinel.conf" | ||
hostname=$1 | ||
|
||
if [ ! -f "$configuration" ] | ||
then | ||
mkdir -p $dir | ||
apk --no-cache --quiet add bind-tools | ||
ip=$(dig ${hostname} +short) | ||
echo "sentinel myid 6050271ee52c6a1f3302b44fe6793f2e3e0de356" > $configuration | ||
echo "sentinel monitor mservice $ip 6379 1" >> $configuration | ||
echo "sentinel down-after-milliseconds mservice 60000" >> $configuration | ||
echo "sentinel config-epoch mservice 0" >> $configuration | ||
echo "# Generated by CONFIG REWRITE" >> $configuration | ||
echo "port 26379" >> $configuration | ||
echo "dir \"/data\"" >> $configuration | ||
echo "protected-mode no" >> $configuration | ||
echo "sentinel leader-epoch mservice 4" >> $configuration | ||
echo "sentinel current-epoch 4" >> $configuration | ||
chown -R $(id -u redis):$(id -g redis) $dir | ||
fi | ||
|
||
exec redis-server /etc/redis-sentinel/redis-sentinel.conf --sentinel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3286,6 +3286,14 @@ husky@^1.1.2: | |
run-node "^1.0.0" | ||
slash "^2.0.0" | ||
|
||
hyperid@^1.4.1: | ||
version "1.4.1" | ||
resolved "https://registry.yarnpkg.com/hyperid/-/hyperid-1.4.1.tgz#5df41b25a86171661b37534c3404655ae7657d29" | ||
integrity sha512-rtuRoJyEPZZEGN25T1PC2/IYxdApJEYbBB+8e7vZMFnfhZV7HobkpUr7z1gZvcxqleg4OVg0YrMEtfmIoV85gQ== | ||
dependencies: | ||
uuid "^3.2.1" | ||
uuid-parse "^1.0.0" | ||
|
||
[email protected], iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13: | ||
version "0.4.24" | ||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" | ||
|
@@ -7666,7 +7674,12 @@ util.promisify@^1.0.0: | |
define-properties "^1.1.2" | ||
object.getownpropertydescriptors "^2.0.3" | ||
|
||
uuid@^3.3.2: | ||
uuid-parse@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/uuid-parse/-/uuid-parse-1.0.0.tgz#f4657717624b0e4b88af36f98d89589a5bbee569" | ||
integrity sha1-9GV3F2JLDkuIrzb5jYlYmlu+5Wk= | ||
|
||
uuid@^3.2.1, uuid@^3.3.2: | ||
version "3.3.2" | ||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" | ||
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== | ||
|