Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs port #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
8 changes: 8 additions & 0 deletions cmd/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
command: 'compose <cmd>',
describe: 'shortcuts to running docker-compose directly',
builder: (yargs) => yargs
.commandDir('compose')
.usage('$0 <cmd> [args]')
.demandCommand(1, '')
}
10 changes: 10 additions & 0 deletions cmd/compose/down.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'down',
describe: 'stop all docker-compose service(s)',
handler: (argv) => {
child.spawnSync('docker-compose', ['down'], options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'exec',
describe: 'execute an arbitrary docker-compose command',
handler: (argv) => {
child.spawnSync('docker-compose', argv._.slice(1), options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/kill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'kill',
describe: 'kill one or more docker-compose service(s)',
handler: (argv) => {
child.spawnSync('docker-compose', argv._.slice(1), options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'logs',
describe: 'display container logs',
handler: (argv) => {
child.spawnSync('docker-compose', argv._.slice(1), options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/ps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'ps',
describe: 'list containers',
handler: (argv) => {
child.spawnSync('docker-compose', argv._.slice(1), options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/pull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'pull',
describe: 'update all docker images',
handler: (argv) => {
child.spawnSync('docker-compose', ['pull'], options)
}
}
17 changes: 17 additions & 0 deletions cmd/compose/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const child = require('child_process')
const env = require('../../lib/env')()
const options = { stdio: 'inherit' }

function net_init() {
const net = `${env.COMPOSE_PROJECT_NAME}_default`
child.spawnSync('docker', ['network', 'create', net], { stdio: 'ignore' })
}

module.exports = {
command: 'run',
describe: 'execute a docker-compose run command',
handler: (argv) => {
net_init()
child.spawnSync('docker-compose', ['run', '--rm', ...argv._.slice(2)], options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'top',
describe: 'display the running processes of a container',
handler: (argv) => {
child.spawnSync('docker-compose', argv._.slice(1), options)
}
}
10 changes: 10 additions & 0 deletions cmd/compose/up.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const child = require('child_process')
const options = { stdio: 'inherit' }

module.exports = {
command: 'up',
describe: 'start one or more docker-compose service(s)',
handler: (argv) => {
child.spawnSync('docker-compose', ['up', '-d', ...argv._.slice(2)], options)
}
}
8 changes: 8 additions & 0 deletions cmd/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
command: 'download <cmd>',
describe: 'fetch and update geographic data from source',
builder: (yargs) => yargs
.commandDir('download')
.usage('$0 <cmd> [args]')
.demandCommand(1, '')
}
23 changes: 23 additions & 0 deletions cmd/download/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const env = require('../../lib/env')()

module.exports = {
command: 'all',
describe: '(re)download all data',
handler: (argv) => {

// @todo: make this parallel
// like it was with the bash script

require('./wof').handler()
require('./oa').handler()
require('./osm').handler()

if (env.ENABLE_GEONAMES === 'true'){
require('./geonames').handler()
}

require('./tiger').handler()
require('./transit').handler()
require('./csv').handler()
}
}
9 changes: 9 additions & 0 deletions cmd/download/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'csv',
describe: '(re)download CSV data',
handler: (argv) => {
run({ _: ['compose', 'run', 'csv-importer', './bin/download'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/geonames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'geonames',
describe: '(re)download geonames data',
handler: (argv) => {
run({ _: ['compose', 'run', 'geonames', './bin/download'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/oa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'oa',
describe: '(re)download openaddresses data',
handler: (argv) => {
run({ _: ['compose', 'run', 'openaddresses', './bin/download'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/osm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'osm',
describe: '(re)download openstreetmap data',
handler: (argv) => {
run({ _: ['compose', 'run', 'openstreetmap', './bin/download'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/tiger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'tiger',
describe: '(re)download TIGER data',
handler: (argv) => {
run({ _: ['compose', 'run', 'interpolation', './bin/download-tiger'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/transit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'transit',
describe: '(re)download transit data',
handler: (argv) => {
run({ _: ['compose', 'run', 'transit', './bin/download'] })
}
}
9 changes: 9 additions & 0 deletions cmd/download/wof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'wof',
describe: '(re)download whosonfirst data',
handler: (argv) => {
run({ _: ['compose', 'run', 'whosonfirst', './bin/download'] })
}
}
8 changes: 8 additions & 0 deletions cmd/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
command: 'import <cmd>',
describe: 'import source data into elasticsearch',
builder: (yargs) => yargs
.commandDir('import')
.usage('$0 <cmd> [args]')
.demandCommand(1, '')
}
20 changes: 20 additions & 0 deletions cmd/import/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const env = require('../../lib/env')()

module.exports = {
command: 'all',
describe: '(re)import all data',
handler: (argv) => {

require('./wof').handler()
require('./oa').handler()
require('./osm').handler()
require('./polylines').handler()

if (env.ENABLE_GEONAMES === 'true'){
require('./geonames').handler()
}

require('./transit').handler()
require('./csv').handler()
}
}
9 changes: 9 additions & 0 deletions cmd/import/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'csv',
describe: '(re)import CSV data',
handler: (argv) => {
run({ _: ['compose', 'run', 'csv-importer', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/geonames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'geonames',
describe: '(re)import geonames data',
handler: (argv) => {
run({ _: ['compose', 'run', 'geonames', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/oa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'oa',
describe: '(re)import openaddresses data',
handler: (argv) => {
run({ _: ['compose', 'run', 'openaddresses', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/osm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'osm',
describe: '(re)import openstreetmap data',
handler: (argv) => {
run({ _: ['compose', 'run', 'openstreetmap', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/polylines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'polylines',
describe: '(re)import polylines data',
handler: (argv) => {
run({ _: ['compose', 'run', 'interpolation', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/transit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'transit',
describe: '(re)import transit data',
handler: (argv) => {
run({ _: ['compose', 'run', 'transit', './bin/start'] })
}
}
9 changes: 9 additions & 0 deletions cmd/import/wof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const run = require('../compose/run').handler

module.exports = {
command: 'wof',
describe: '(re)import whosonfirst data',
handler: (argv) => {
run({ _: ['compose', 'run', 'whosonfirst', './bin/start'] })
}
}
1 change: 0 additions & 1 deletion cmd/docker.sh → cmd_old/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ register 'compose' 'kill' 'kill one or more docker-compose service(s)' compose_k

function compose_down(){ docker-compose down; }
register 'compose' 'down' 'stop all docker-compose service(s)' compose_down

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const _ = require('lodash')
const dotenv = require('dotenv')

module.exports = () => {
let env = Object.create(process.env)
_.extend(env, dotenv.config().parsed)

return env
}
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "docker",
"version": "1.0.0",
"description": "This repository contains a framework for downloading/preparing and building the [Pelias Geocoder](https://github.com/pelias/pelias) using Docker and [Docker Compose](https://github.com/docker/compose#docker-compose).",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pelias/docker.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/pelias/docker/issues"
},
"homepage": "https://github.com/pelias/docker#readme",
"dependencies": {
"dotenv": "^8.2.0",
"lodash": "^4.17.15",
"yargs": "^15.1.0"
}
}
29 changes: 8 additions & 21 deletions pelias
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
#!/bin/bash
set -e
#!/usr/bin/env node

# OSX comes bundled with versions of readlink, sed, parallel etc which are not
# compatible with the linux tools. Force OSX users to install the GNU
# compatible versions (prefixed with 'g', such as 'greadlink', 'gsed' etc.).
export CMD_READLINK='readlink'
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -x "$(command -v greadlink)" ]; then
CMD_READLINK='greadlink';
else
2>&1 echo 'OSX: you must install the gnu standard tooling using:'
2>&1 echo 'brew install coreutils'
fi
fi

# resolve path to this file (following symlinks) and load libs
BASEDIR=$( dirname $( ${CMD_READLINK} -f "${BASH_SOURCE[0]}" ) )
for f in ${BASEDIR}/lib/* ${BASEDIR}/cmd/*; do source $f; done

# cli runner
cli "$@"
require('yargs')
.scriptName('pelias')
.commandDir('cmd')
.showHelpOnFail(true)
.demandCommand(1, '')
.help()
.parse()