Skip to content

Commit

Permalink
Merge branch 'jhipster:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
glutengo committed Sep 5, 2021
2 parents baeb775 + b57f1ef commit c407a66
Show file tree
Hide file tree
Showing 20 changed files with 932 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

# [2.0.0](https://github.com/jhipster/generator-jhipster-nodejs/tree/v2.0.0) - xx/xx/2021 released date

- ci-cd for nodejs application [issue #104](https://github.com/jhipster/generator-jhipster-nodejs/issues/104)
- Support JHipster primary key type for entity service and controller [issue #238](https://github.com/jhipster/generator-jhipster-nodejs/issues/238)
- Columns createdBy, createdDate, lastModifiedBy and lastModifiedDate should be filled automatically [issue #236](https://github.com/jhipster/generator-jhipster-nodejs/issues/236)
- Passwords should be hashed instead of encrypted [issue #234](https://github.com/jhipster/generator-jhipster-nodejs/issues/234)
- Remove in query user api the unencrypted password exposed [issue #232](https://github.com/jhipster/generator-jhipster-nodejs/issues/232)
- Support JHipster primary key type [issue #230](https://github.com/jhipster/generator-jhipster-nodejs/issues/230)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ However, it also ships with an `nhipster` CLI that you can use as a shortcut.

- `nhipster import-jdl my_file.jdl`

✅ Ci-cd generation

- `nhipster ci-cd`

For the last, in the **test-integration/samples/FOLDER_NAME-jdl** there are some examples of jdl models.

## Using Docker
Expand Down
5 changes: 5 additions & 0 deletions generators/ci-cd/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Description:
Creates pipeline scripts for various CI/CD tools based on the selected options

Example:
nhipster ci-cd
71 changes: 71 additions & 0 deletions generators/ci-cd/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint-disable consistent-return */
const chalk = require('chalk');
const CiCdGenerator = require('generator-jhipster/generators/ci-cd');

module.exports = class extends CiCdGenerator {
constructor(args, opts) {
super(args, { fromBlueprint: true, ...opts }); // fromBlueprint variable is important

const jhContext = (this.jhipsterContext = this.options.jhipsterContext);

if (!jhContext) {
this.error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprints nodejs')}`);
}

this.configOptions = jhContext.configOptions || {};
}

get initializing() {
const initPhaseFromJHipster = super._initializing();
const initNodeCiCdPhaseSteps = {
sayHello() {
this.log(chalk.white('🚀 Welcome to the NHipster CI/CD custom Sub-Generator 🚀'));
}
};
return { ...initPhaseFromJHipster, ...initNodeCiCdPhaseSteps };
}

get prompting() {
return super._prompting();
}

get configuring() {
// Here we are not overriding this phase and hence its being handled by JHipster
return super._configuring();
}

get loading() {
return super._loading();
}

get writing() {
return {
customWriting() {
if (this.pipeline === 'jenkins') {
this.template('jenkins/Jenkinsfile.ejs', 'Jenkinsfile');
this.template('jenkins/jenkins.yml.ejs', `${this.DOCKER_DIR}jenkins.yml`);
this.template('jenkins/idea.gdsl', `${this.SERVER_MAIN_RES_DIR}idea.gdsl`);
}
if (this.pipeline === 'gitlab') {
this.template('.gitlab-ci.yml.ejs', '.gitlab-ci.yml');
}
if (this.pipeline === 'circle') {
this.template('circle.yml.ejs', 'circle.yml');
}
if (this.pipeline === 'travis') {
this.template('travis.yml.ejs', '.travis.yml');
}
if (this.pipeline === 'azure') {
this.template('azure-pipelines.yml.ejs', 'azure-pipelines.yml');
}
if (this.pipeline === 'github') {
this.template('github-ci.yml.ejs', '.github/workflows/github-ci.yml');
}

if (this.cicdIntegrations.includes('publishDocker')) {
this.template('docker-registry.yml.ejs', `${this.DOCKER_DIR}docker-registry.yml`);
}
}
};
}
};
137 changes: 137 additions & 0 deletions generators/ci-cd/templates/.gitlab-ci.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<%#
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.
-%>
<%_ if (insideDocker) { _%>
image: jhipster/jhipster:v<%= jhipsterVersion %>
<%_ } _%>

# NHipster ci-cd

<%_ if (!skipServer) { _%>
stages:
- build
- test
- packaging
<%_ } _%>

before_script:
<%_ if (clientFramework === ANGULAR) { _%>
- export NG_CLI_ANALYTICS="false"
<%_ } _%>

server-compile:
stage: build
script:
- cd server && <%= clientPackageManager %> install
artifacts:
paths:
- server/node_modules

server-test:
stage: test
script:
- cd server && <%= clientPackageManager %> run test
artifacts:
reports:
junit: server/coverage/clover.xml
paths:
- server/coverage
expire_in: 1 day

<%_ if (!skipClient) { _%>
frontend-test:
stage: test
script:
- <%= clientPackageManager %> run webpack:test
artifacts:
reports:
junit: build/test-results/TESTS-results-jest.xml
paths:
- build/test-results
expire_in: 1 day
<%_ } _%>

<%_ if (!skipServer && cicdIntegrations.includes('sonar')) { _%>
#sonar-analyze:
# stage: analyze
# dependencies:
# - maven-test
# <%_ if (!skipClient) { _%>
# - frontend-test
# <%_ } _%>
# script:
# - cd server && <%= clientPackageManager %> run sonar:scanner
# allow_failure: true
<%_ } _%>

server-package:
stage: package
script:
- <%= clientPackageManager %> run build:app
artifacts:
paths:
- server/dist
expire_in: 1 day

<%_ if (cicdIntegrations.includes('heroku')) { _%>
#deploy-to-production:
# stage: deploy
# script:
# - ./mvnw -ntp com.heroku.sdk:heroku-maven-plugin:2.0.5:deploy -DskipTests -Pprod -Dheroku.buildpacks=heroku/jvm -Dheroku.appName=<%= herokuAppName %> -Dmaven.repo.local=$MAVEN_USER_HOME
# environment:
# name: production
# when: manual
<%_ } _%>

<%_ if (skipServer) { _%>
cache:
paths:
- node_modules/
stages:
- build
- test
- packaging
webpack-build:
stage: build
script:
- <%= clientPackageManager %> install
- <%= clientPackageManager %> run webpack:build
artifacts:
paths:
- build/
webpack-test:
stage: test
dependencies:
- webpack-build
script:
- <%= clientPackageManager %> run webpack:test
artifacts:
reports:
junit: build/test-results/TESTS-results-jest.xml
paths:
- build/test-results
expire_in: 1 day
webpack-prod:
stage: packaging
script:
- <%= clientPackageManager %> run webpack:prod
# - add cmd to zip the app folder build/resources/main/static
artifacts:
paths:
- build/
<%_ } _%>
69 changes: 69 additions & 0 deletions generators/ci-cd/templates/azure-pipelines.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<%#
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.
-%>
# NHipster ci-cd
jobs:
- job: Test
pool:
vmImage: 'Ubuntu 16.04'
variables:
NODE_VERSION: <%= NODE_VERSION %>
JHI_DISABLE_WEBPACK_LOGS: true
NG_CLI_ANALYTICS: "false"

steps:
#----------------------------------------------------------------------
# Install all tools and check configuration
#----------------------------------------------------------------------
- task: NodeTool@0
inputs:
versionSpec: '<%= NODE_VERSION %>'
displayName: 'TOOLS: install Node.js'
<%_ if (clientPackageManager === 'npm') { _%>
- script: sudo npm install -g npm
displayName: 'TOOLS: update NPM'
- script: sudo chown -R vsts:docker /home/vsts/.npm/
displayName: 'BUGS-FIX: change /home/vsts/.npm/ permission'
<%_ } else if (clientPackageManager === 'yarn') { _%>
- script: |
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH=$HOME/.yarn/bin:$PATH
displayName: 'TOOLS: install Yarn'
<%_ } _%>
- script: sudo /etc/init.d/mysql stop
displayName: 'TOOLS: stop MySQL'
#----------------------------------------------------------------------
# Tests
#----------------------------------------------------------------------
- script: <%= clientPackageManager %> install
displayName: 'INSTALL: launch <%= clientPackageManager %> install'
<%_ if (!skipServer) { _%>
- script: |
cd server
<%= clientPackageManager %> install
npm run -DskipTests
displayName: 'TESTS: backend'
<%_ } _%>
<%_ if (!skipClient) { _%>
- script: <%= clientPackageManager %> test
displayName: 'TESTS: frontend'
<%_ } _%>
<%_ if (!skipServer) { _%>
- script: cd server && npm run build
displayName: 'TESTS: packaging'
<%_ } _%>
59 changes: 59 additions & 0 deletions generators/ci-cd/templates/circle.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<%#
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.
-%>
# NHipster ci-cd
machine:
services:
- docker
java:
version: oraclejdk8
node:
version: <%= NODE_VERSION %>
dependencies:
cache_directories:
- node
- node_modules
<%_ if (clientPackageManager === 'yarn') { _%>
- $HOME/.yarn-cache
<%_ } _%>
override:
<%_ if (clientPackageManager === 'npm') { _%>
- npm install -g npm
- node -v
- npm -v
- npm install
<%_ } else if (clientPackageManager === 'yarn') { _%>
# Repo for Yarn
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- yarn install
<%_ } _%>
test:
override:
- cd server
- <%= clientPackageManager %> install
- <%= clientPackageManager %> test
<%_ if (!skipClient) { _%>
- <%= clientPackageManager %> run <%= frontTestCommand %>
<%_ } _%>
<%_ if (cicdIntegrations.includes('circle')) { _%>
# - ./mvnw -ntp com.heroku.sdk:heroku-maven-plugin:2.0.5:deploy -DskipTests -Pprod -Dheroku.buildpacks=heroku/jvm -Dheroku.appName=<%= herokuAppName %>
<%_ } else { _%>
- cd server && npm run build
<%_ } _%>

Loading

0 comments on commit c407a66

Please sign in to comment.