diff --git a/CHANGELOG.md b/CHANGELOG.md index e1cdedb6..380dbcc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ # [1.1.0](https://github.com/jhipster/generator-jhipster-nodejs/tree/v1.1.0) +- Docker support for mysql, mssql and postgresql [issue #137](https://github.com/jhipster/generator-jhipster-nodejs/issues/137) - Create a nhipster command line [issue #143](https://github.com/jhipster/generator-jhipster-nodejs/issues/143) - Enhancement suggestions list tasks for 1.1.0 version [issue #136](https://github.com/jhipster/generator-jhipster-nodejs/issues/136) - Support enum fields entity generation without giving conflicts in sqlite dev database [issue #74](https://github.com/jhipster/generator-jhipster-nodejs/issues/74) diff --git a/generators/common/templates/README.md.ejs b/generators/common/templates/README.md.ejs index 9a7aa4e1..a18bca09 100644 --- a/generators/common/templates/README.md.ejs +++ b/generators/common/templates/README.md.ejs @@ -85,7 +85,17 @@ The `<%= clientPackageManager %> run` command will list all of the scripts avail You can use Docker to improve your JHipster development experience. A number of docker-compose configuration are available in the [src/main/docker](src/main/docker) folder to launch required third party services. You can also fully dockerize your application and all the services that it depends on. -For this run: +<% if (databaseType !== 'no') { %> +For example, to start a <%= prodDatabaseType %> database in a docker container, run: + + docker-compose -f src/main/docker/<%= prodDatabaseType %>.yml up -d + +To stop it and remove the container, run: + + docker-compose -f src/main/docker/<%= prodDatabaseType %>.yml down +<% } %> + +For the entire app run: ``` docker-compose -f src/main/docker/app.yml up -d diff --git a/generators/server/files.js b/generators/server/files.js index 8220e89f..d0f9c18a 100644 --- a/generators/server/files.js +++ b/generators/server/files.js @@ -115,6 +115,20 @@ const serverFiles = { 'src/main/docker/realm-config/jhipster-users-0.json' ] } + ], + db: [ + { + condition: generator => generator.prodDatabaseType === 'mysql', + templates: ['src/main/docker/mysql.yml'] + }, + { + condition: generator => generator.prodDatabaseType === 'mssql', + templates: ['src/main/docker/mssql.yml'] + }, + { + condition: generator => generator.prodDatabaseType === 'postgresql', + templates: ['src/main/docker/postgresql.yml'] + } ] }; diff --git a/generators/server/templates/src/main/docker/mssql.yml.ejs b/generators/server/templates/src/main/docker/mssql.yml.ejs new file mode 100644 index 00000000..b9c8c5d8 --- /dev/null +++ b/generators/server/templates/src/main/docker/mssql.yml.ejs @@ -0,0 +1,30 @@ +<%# + Copyright 2013-2020 the original author or authors from the JHipster project. + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +version: '<%= DOCKER_COMPOSE_FORMAT_VERSION %>' +services: + <%= baseName.toLowerCase() %>-mssql: + image: <%= DOCKER_MSSQL %> + # volumes are not supported on macOS + # volumes: + # - ~/volumes/jhipster/tempdb/mssql/:/var/opt/mssql/data/ + environment: + - ACCEPT_EULA=Y + - MSSQL_PID=Express + - SA_PASSWORD=yourStrong(!)Password + - MSSQL_DATABASE=<%= baseName %> + - MSSQL_SLEEP=60 + ports: + - 1433:1433 + command: /bin/bash -c '/opt/mssql/bin/sqlservr & echo "wait $$MSSQL_SLEEP sec for DB to start "; sleep $$MSSQL_SLEEP; /opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -d tempdb -q "EXIT(CREATE DATABASE $$MSSQL_DATABASE)"; wait;' diff --git a/generators/server/templates/src/main/docker/mysql.yml.ejs b/generators/server/templates/src/main/docker/mysql.yml.ejs new file mode 100644 index 00000000..bbfc240d --- /dev/null +++ b/generators/server/templates/src/main/docker/mysql.yml.ejs @@ -0,0 +1,27 @@ +<%# + Copyright 2013-2020 the original author or authors from the JHipster project. + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +version: '<%= DOCKER_COMPOSE_FORMAT_VERSION %>' +services: + <%= baseName.toLowerCase() %>-mysql: + image: <%= DOCKER_MYSQL %> + # volumes: + # - ~/volumes/jhipster/<%= baseName %>/mysql/:/var/lib/mysql/ + environment: + - MYSQL_USER=root + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_DATABASE=<%= baseName.toLowerCase() %> + ports: + - 3306:3306 + command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp diff --git a/generators/server/templates/src/main/docker/postgresql.yml.ejs b/generators/server/templates/src/main/docker/postgresql.yml.ejs new file mode 100644 index 00000000..76c05f29 --- /dev/null +++ b/generators/server/templates/src/main/docker/postgresql.yml.ejs @@ -0,0 +1,26 @@ +<%# + Copyright 2013-2020 the original author or authors from the JHipster project. + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +version: '<%= DOCKER_COMPOSE_FORMAT_VERSION %>' +services: + <%= baseName.toLowerCase() %>-postgresql: + image: <%= DOCKER_POSTGRESQL %> + # volumes: + # - ~/volumes/jhipster/<%= baseName %>/postgresql/:/var/lib/postgresql/data/ + environment: + - POSTGRES_USER=<%= baseName %> + - POSTGRES_PASSWORD= + - POSTGRES_HOST_AUTH_METHOD=trust + ports: + - 5432:5432 diff --git a/test/server.spec.js b/test/server.spec.js index 46fa0af9..cc324b3a 100644 --- a/test/server.spec.js +++ b/test/server.spec.js @@ -29,6 +29,10 @@ function commonAssertion() { assert.file(`${SERVER_NODEJS_DIR}e2e/app.e2e-spec.ts`); assert.file(`${SERVER_NODEJS_DIR}e2e/user.e2e-spec.ts`); assert.file(`${SERVER_NODEJS_DIR}e2e/jest.e2e.config.json`); + assert.file('src/main/docker/app.yml'); + assert.file('src/main/docker/mysql.yml'); + assert.noFile('src/main/docker/mssql.yml'); + assert.noFile('src/main/docker/postgresql.yml'); } const commonPrompt = { @@ -75,4 +79,23 @@ describe('Subgenerator server of nodejs JHipster blueprint', () => { assert.noFile(`${SERVER_NODEJS_DIR}src/security/payload.interface.ts`); }); }); + + describe('3-Database mssql test', () => { + before(done => { + getPreCondition() + .withPrompts({ + baseName: 'sampleMSsql', + applicationType: 'monolith', + prodDatabaseType: 'mssql', + authenticationType: 'jwt' + }) + .on('end', done); + }); + + it('app exists with docker mssql.yml', () => { + assert.noFile('src/main/docker/mysql.yml'); + assert.noFile('src/main/docker/postgresql.yml'); + assert.file('src/main/docker/mssql.yml'); + }); + }); });