Skip to content

Commit

Permalink
Merge pull request #146 from jhipster/feature/add-docker-sql
Browse files Browse the repository at this point in the history
added docker database feature
  • Loading branch information
Angelo Manganiello authored Jun 9, 2020
2 parents 21bdaa6 + d699343 commit 7484c95
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion generators/common/templates/README.md.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions generators/server/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
]
};

Expand Down
30 changes: 30 additions & 0 deletions generators/server/templates/src/main/docker/mssql.yml.ejs
Original file line number Diff line number Diff line change
@@ -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;'
27 changes: 27 additions & 0 deletions generators/server/templates/src/main/docker/mysql.yml.ejs
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions generators/server/templates/src/main/docker/postgresql.yml.ejs
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions test/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 7484c95

Please sign in to comment.