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

Dockerize jscity #16

Open
wants to merge 4 commits 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
@@ -1 +1,3 @@
.vagrant

node_modules/
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,61 @@ cd /path-to-jscity-directory/js
```
* Start the application server using the command.
```sh
node server.js
npm start
```
* Using your browser, access the url below to open the jscity system:
```
http://localhost:8888/
```
* Select the system from the combobox and wait for the end of city design.

### Docker setup

If you would like it as a docker

```
docker-compose up jscity
```

then give it 15 seconds or so and `http://localhost:8888`

There are several docker-compose services

* `database` - just a stock mysql database so you don't have to install anything
* `database-migration` - run database migration script to create and seed the jscity database
* `jscity` - the web server itself
* `generator` - used to run the city generator. Typically you would run this with the `run` and not the `up` command.

#### Generate City

Note that this isn't as easy as running `run-generate.sh` - this script is meant to be run *inside the docker container* not outside of it.

The code to be scanned needs to be somewhere accessible to the generator docker container. You may mount additional volumes or simply place it in the cannonical location `js/backend/system/`.

If you were to simply `docker-compose run` the application it will start with a new instance of the `database` service so that your changes will be created and immediately discarded. To bypass that limitation first start the database and run any migrations (if this is not your first time you can just up `database`)

```
docker-compose up -d database-migration
```
and then run without creating additional dependencies.

Note that int he following examples we're just creating further versions of the jscity sample city

```
docker-compose run --rm --no-deps generator ./js/backend/system/metafora/ -c "Metafora Sample"
```

You may also append `--verbose` for more verbose output on the generation process.

##### Debugging

To debug `generator.js` you can pass in a `--debug` flag and don't forget to map port 9229

```
docker-compose run --rm -p 9229:9229 --no-deps generator ./js/backend/system/metafora/ -c "Metafora" --verbose --debug
```

This will start the script with the debugger and break on the very first line. You can navigate to `chrome://inspect/#devices` in Chrome to attach the debugger there.

### Vagrant setup

Expand Down
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.6'
services:
jscity:
image: node:13.0.1-stretch-slim
ports:
- '8888:8888'
- '9234:9234' # node debug port
volumes:
- '.:/app'
depends_on:
- database
- database-migration
working_dir: /app
command: 'npm start'
database:
image: mysql:8.0.18
ports:
- '3306:3306'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
database-migration:
image: mysql:8.0.18
depends_on:
- database
volumes:
- './sql:/sql'
environment:
CREATE_TEST_CITY: 1
command: 'bash -c "sleep 15 && mysql --host=database < ./sql/schema.sql"' #sleep to give the db time to come up
generator:
image: node:13.0.1-stretch-slim
ports:
- '9229:9229' # node debug port
volumes:
- '.:/app'
depends_on:
- database
- database-migration
working_dir: /app
entrypoint: './run-generator.sh'
4 changes: 2 additions & 2 deletions js/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"local": {
"connectionLimit": 200,
"waitForConnections": true,
"host": "localhost",
"host": "database",
"user": "jscity",
"password": "",
"password": "password",
"database": "jscity"
},
"amazon": {
Expand Down
1 change: 1 addition & 0 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
sSQL = mysql.format(sSQL, format);
connection.query(sSQL, function(err, rows, fields) {
if(err) {
console.log(err)
responseObj.message = msg('Internal Error. {FCBD}', err.message);
writeEnd(JSON.stringify(responseObj), "application/json", 500);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"node": ">= 0.12"
},
"scripts": {
"start": "node ./js/server.js"
"start": "node --inspect=0.0.0.0:9234 ./js/server.js"
}
}
3 changes: 2 additions & 1 deletion provision_script.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# provision_script.sh
##!/bin/bash

apt-get update
debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password'
Expand Down
12 changes: 12 additions & 0 deletions run-generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# Runs generator.js to parse a city. Meant to be run from inside the docker-compose but if you have the application configured outside of it can work as well.
# When the --debug flag is passed will start the node debugger and idle on the first line

if [[ $* == *--debug* ]]; then
echo "Starting node debugger on port 9229"
echo "Navigate to chrome://inspect/#devices to connect, if you do not see it there and are running this via docker make sure you remembered to map -p 9229:9229"
node --inspect-brk=0.0.0.0:9229 ./js/backend/generator.js "$@"
else
node ./js/backend/generator.js "$@"
fi
163 changes: 80 additions & 83 deletions sql/schema.sql
Original file line number Diff line number Diff line change
@@ -1,83 +1,80 @@
/*
SQLyog
MySQL - 5.6.26 : Database - jscity
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`jscity` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `jscity`;

/*Table structure for table `tb_building` */

DROP TABLE IF EXISTS `tb_building`;

CREATE TABLE `tb_building` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`height` int(11) unsigned NOT NULL DEFAULT '0',
`width` int(11) unsigned NOT NULL DEFAULT '0',
`color` varchar(10) NOT NULL,
`tooltip` varchar(255) NOT NULL,
`district_id` int(11) DEFAULT NULL,
`building_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fk_tb_construction_tb_district1` (`district_id`),
KEY `idx_fk_tb_building_tb_building1_idx` (`building_id`),
CONSTRAINT `fk_tb_building_tb_building1` FOREIGN KEY (`building_id`) REFERENCES `tb_building` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_tb_construction_tb_district1` FOREIGN KEY (`district_id`) REFERENCES `tb_district` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_building` */

insert into `tb_building`(`id`,`name`,`height`,`width`,`color`,`tooltip`,`district_id`,`building_id`) values (1,'A',27,25,'0x337AB7','A, LOC: 27 [28-54]',1,NULL),(2,'Anonymous function',29,5,'0x4CAE4C','Anonymous function, LOC: 29 [56-84]',1,NULL),(3,'C',12,2,'0x337AB7','C, LOC: 12 [57-68]',NULL,2),(4,'B',8,2,'0x337AB7','B, LOC: 8 [70-77]',NULL,2),(5,'C',12,2,'0x337AB7','C, LOC: 12 [28-39]',4,NULL),(6,'B',11,3,'0x337AB7','B, LOC: 11 [41-51]',4,NULL),(7,'Anonymous function',12,2,'0x4CAE4C','Anonymous function, LOC: 12 [59-70]',4,NULL),(8,'Anonymous function',11,3,'0x4CAE4C','Anonymous function, LOC: 11 [72-82]',4,NULL),(9,'C',12,2,'0x337AB7','C, LOC: 12 [28-39]',5,NULL),(10,'B',11,3,'0x337AB7','B, LOC: 11 [41-51]',5,NULL),(11,'C',75,2,'0x337AB7','C, LOC: 75 [28-102]',6,NULL),(12,'B',11,3,'0x337AB7','B, LOC: 11 [104-114]',6,NULL),(13,'A',3,1,'0x337AB7','A, LOC: 3 [43-45]',NULL,6),(14,'Anonymous function',3,1,'0x4CAE4C','Anonymous function, LOC: 3 [74-76]',NULL,8),(15,'A',3,1,'0x337AB7','A, LOC: 3 [43-45]',NULL,10),(16,'A',3,1,'0x337AB7','A, LOC: 3 [106-108]',NULL,12);

/*Table structure for table `tb_city` */

DROP TABLE IF EXISTS `tb_city`;

CREATE TABLE `tb_city` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`tooltip` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_city` */

insert into `tb_city`(`id`,`name`,`tooltip`) values (1,'Example City','Example City @ ./system/metafora/');

/*Table structure for table `tb_district` */

DROP TABLE IF EXISTS `tb_district`;

CREATE TABLE `tb_district` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`color` varchar(10) NOT NULL,
`tooltip` varchar(255) NOT NULL,
`city_id` int(11) DEFAULT NULL,
`district_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fk_tb_district_tb_city` (`city_id`),
KEY `fk_tb_district_tb_district1_idx` (`district_id`),
CONSTRAINT `fk_tb_district_tb_city` FOREIGN KEY (`city_id`) REFERENCES `tb_city` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_tb_district_tb_district1` FOREIGN KEY (`district_id`) REFERENCES `tb_district` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_district` */

insert into `tb_district`(`id`,`name`,`color`,`tooltip`,`city_id`,`district_id`) values (1,'index.js','0xD9534F','index.js, LOC: 57 [28-84]',1,NULL),(2,'distrito-b','0xF0AD4E','Folder: distrito-b',1,NULL),(3,'distrito-a','0xF0AD4E','Folder: distrito-a',1,NULL),(4,'index-2.js','0xD9534F','index-2.js, LOC: 55 [28-82]',NULL,2),(5,'index.js','0xD9534F','index.js, LOC: 30 [28-57]',NULL,2),(6,'index.js','0xD9534F','index.js, LOC: 93 [28-120]',NULL,3);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE IF NOT EXISTS `jscity`;

CREATE USER IF NOT EXISTS jscity IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON jscity.* TO jscity;

USE `jscity`;

/*Table structure for table `tb_building` */

DROP TABLE IF EXISTS `tb_building`;

CREATE TABLE `tb_building` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`height` int(11) unsigned NOT NULL DEFAULT '0',
`width` int(11) unsigned NOT NULL DEFAULT '0',
`color` varchar(10) NOT NULL,
`tooltip` varchar(255) NOT NULL,
`district_id` int(11) DEFAULT NULL,
`building_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fk_tb_construction_tb_district1` (`district_id`),
KEY `idx_fk_tb_building_tb_building1_idx` (`building_id`),
CONSTRAINT `fk_tb_building_tb_building1` FOREIGN KEY (`building_id`) REFERENCES `tb_building` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_tb_construction_tb_district1` FOREIGN KEY (`district_id`) REFERENCES `tb_district` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_building` */

insert into `tb_building`(`id`,`name`,`height`,`width`,`color`,`tooltip`,`district_id`,`building_id`) values (1,'A',27,25,'0x337AB7','A, LOC: 27 [28-54]',1,NULL),(2,'Anonymous function',29,5,'0x4CAE4C','Anonymous function, LOC: 29 [56-84]',1,NULL),(3,'C',12,2,'0x337AB7','C, LOC: 12 [57-68]',NULL,2),(4,'B',8,2,'0x337AB7','B, LOC: 8 [70-77]',NULL,2),(5,'C',12,2,'0x337AB7','C, LOC: 12 [28-39]',4,NULL),(6,'B',11,3,'0x337AB7','B, LOC: 11 [41-51]',4,NULL),(7,'Anonymous function',12,2,'0x4CAE4C','Anonymous function, LOC: 12 [59-70]',4,NULL),(8,'Anonymous function',11,3,'0x4CAE4C','Anonymous function, LOC: 11 [72-82]',4,NULL),(9,'C',12,2,'0x337AB7','C, LOC: 12 [28-39]',5,NULL),(10,'B',11,3,'0x337AB7','B, LOC: 11 [41-51]',5,NULL),(11,'C',75,2,'0x337AB7','C, LOC: 75 [28-102]',6,NULL),(12,'B',11,3,'0x337AB7','B, LOC: 11 [104-114]',6,NULL),(13,'A',3,1,'0x337AB7','A, LOC: 3 [43-45]',NULL,6),(14,'Anonymous function',3,1,'0x4CAE4C','Anonymous function, LOC: 3 [74-76]',NULL,8),(15,'A',3,1,'0x337AB7','A, LOC: 3 [43-45]',NULL,10),(16,'A',3,1,'0x337AB7','A, LOC: 3 [106-108]',NULL,12);

/*Table structure for table `tb_city` */

DROP TABLE IF EXISTS `tb_city`;

CREATE TABLE `tb_city` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`tooltip` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_city` */

insert into `tb_city`(`id`,`name`,`tooltip`) values (1,'Example City','Example City @ ./system/metafora/');

/*Table structure for table `tb_district` */

DROP TABLE IF EXISTS `tb_district`;

CREATE TABLE `tb_district` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`color` varchar(10) NOT NULL,
`tooltip` varchar(255) NOT NULL,
`city_id` int(11) DEFAULT NULL,
`district_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fk_tb_district_tb_city` (`city_id`),
KEY `fk_tb_district_tb_district1_idx` (`district_id`),
CONSTRAINT `fk_tb_district_tb_city` FOREIGN KEY (`city_id`) REFERENCES `tb_city` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_tb_district_tb_district1` FOREIGN KEY (`district_id`) REFERENCES `tb_district` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Data for the table `tb_district` */

insert into `tb_district`(`id`,`name`,`color`,`tooltip`,`city_id`,`district_id`) values (1,'index.js','0xD9534F','index.js, LOC: 57 [28-84]',1,NULL),(2,'distrito-b','0xF0AD4E','Folder: distrito-b',1,NULL),(3,'distrito-a','0xF0AD4E','Folder: distrito-a',1,NULL),(4,'index-2.js','0xD9534F','index-2.js, LOC: 55 [28-82]',NULL,2),(5,'index.js','0xD9534F','index.js, LOC: 30 [28-57]',NULL,2),(6,'index.js','0xD9534F','index.js, LOC: 93 [28-120]',NULL,3);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;