Skip to content

Commit

Permalink
Merge pull request #22814 from mshima/skip_ci-devcontainer
Browse files Browse the repository at this point in the history
add devcontainer for jhipster development
  • Loading branch information
DanielFran authored Jul 12, 2023
2 parents 94451f2 + 7f4f7ba commit 298d5c5
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 27 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/java/.devcontainer/base.Dockerfile

# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
ARG VARIANT="17-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, defaults to generator-jhipster default node version.
ARG NODE_VERSION

# Copy required generator-jhipster resource to detect node and npm versions
COPY /package.json /tmp/generator-jhipster/
COPY /generators /tmp/generator-jhipster/generators
COPY /test-integration /tmp/generator-jhipster/test-integration

RUN /tmp/generator-jhipster/test-integration/scripts/99-print-node-version.sh
RUN export NODE_VERSION=${NODE_VERSION:-$(/tmp/generator-jhipster/test-integration/scripts/99-print-node-version.sh)}; \
su -p vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install $NODE_VERSION 2>&1";
RUN npm install -g npm@$(/tmp/generator-jhipster/test-integration/scripts/99-print-npm-version.sh); \
npm cache clean --force

# Remove generator-jhipster for final image
RUN rm -rf /tmp/generator-jhipster
50 changes: 50 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/java
{
"name": "generator-jhipster",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update the VARIANT arg to pick a Java version: 11, 17
// Append -bullseye or -buster to pin to an OS version.
// Use the -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "17-bullseye"

// Defaults to generator-jhipster's default node version.
//"NODE_VERSION": ""
}
},
"mounts": [
// If your system OS/Architecture doesn't matches the container one, you can uncomment the following line and create node_modules_container to keep local and containers node_module usable.
// "source=${localWorkspaceFolder}/node_modules_container,target=/workspaces/generator-jhipster/node_modules,type=bind,consistency=cached",
"source=${localWorkspaceFolder}/../jhipster-samples,target=/workspaces/jhipster-samples,type=bind,consistency=cached"
],

"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"java.jdt.ls.java.home": "/docker-java-home"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": ["eamodio.gitlens", "esbenp.prettier-vscode", "github.vscode-github-actions", "hbenl.vscode-mocha-test-adapter"]
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",

// Configure tool-specific properties.
// "customizations": {},

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
coverage
generators/**/templates
node_modules
node_modules_container
test-integration
docs
test/templates
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
node_modules_container
coverage
.idea
*.iml
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
node_modules_container
docs
.git
jdl/**/.jhipster/**
Expand Down
58 changes: 50 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,46 @@ Go to the [generator-jhipster project](https://github.com/jhipster/generator-jhi

[Please read the GitHub forking documentation for more information](https://help.github.com/articles/fork-a-repo)

### Set NPM to use the cloned project
### Set `jhipster` command to use the cloned project

Since v8 `generator-jhipster` is written in typescript.
To run it you need to compile to javascript or use a just-in-time compilation.

#### Runnning jit executable

The executable is located at `bin/jhipster.cjs`.
You can alias it to `jhipster` command:

```shell
alias jhipster="GLOBAL_PATH/generator-jhipster/bin/jhipster.cjs"
```

#### Globally linked compiled package

In your cloned `generator-jhipster` project, run `npm ci` and then run `npm link`.

`npm ci` will do a clean installation of all the project dependencies.
`npm ci` will do a clean installation of all the project dependencies and compile sources.
`npm run build` can be used to compile sources after each change.

`npm link` will make a symbolic link from the global `node_modules` version to point to this folder, so when we run `jhipster`, you will now use the development version of JHipster.

### Test generating applications

For testing, you will want to generate an application, and there is a specific issue here: for each application, JHipster installs a local version of itself. This is made to enable several applications to each use a specific JHipster version (application A uses JHipster 3.1.0, and application B uses JHipster 3.2.0).

To overcome this you need to run `npm link generator-jhipster` on the generated project folder as well, so that the local version has a symbolic link to the development version of JHipster.
Also add the option `--skip-jhipster-dependencies` to generate the application ignoring the JHipster dependencies (otherwise a released version will be installed each time npm install/ci is called). You can later on re-add the dependency with the command `jhipster --no-skip-jhipster-dependencies`.

To put it in a nutshell, you need to:

1. run `npm link` on the `generator-jhipster` project (link globally)
1. run `npm link` on the `generator-jhipster` project (link globally) or configure jit executable
2. run `jhipster --skip-jhipster-dependencies` on the generated application folder

You can execute `jhipster --install-path` to check where jhipster is being executed from.

You can test your setup by making a small change in your cloned generator, and running again on an existing JHipster project:

For projects with jhipster third party library (i.e. react-jhipster, ng-jhipster, etc.) you need to run `npm link` on the library project as well, then npm link the original framework (i.e. react) from the generated project to the library project `cd react-jhipster && npm link <path-to-generated-project>/node_modules/react`.
For projects with jhipster third party library (i.e. react-jhipster, etc.) you need to run `npm link` on the library project as well, then npm link the original framework (i.e. react) from the generated project to the library project `cd react-jhipster && npm link <path-to-generated-project>/node_modules/react`.

```shell
jhipster
Expand Down Expand Up @@ -289,23 +306,48 @@ Run every test with lint/prettier
`npm test`
Run every test without lint/prettier
`npx mocha`
`npx esmocha`
Update every test snapshot
`npm run update-snapshots`
Run specific tests
`npx mocha <path>`
`npx esmocha <path>`
Run specific tests in series (improved error reporting)
`npx mocha <path> --no-parallel`
`npx esmocha <path> --no-parallel`
Update specific test snapshot
`npm run update-snapshot -- <path>` or `npx mocha <path> --no-parallel --updateSnapshot`
`npm run update-snapshot -- <path>` or `npx esmocha <path> --no-parallel --update-snapshot`
Fixing lint and prettier errors
`npm run lint-fix`
## DX using vscode
`generator-jhipster` add a series of vscode configurations for a better developer experience.
### Development Containers
Container is built using java, node and npm recommended by `generator-jhipster`.
Once up, you should have the stack maintainers recommends.
### Execution shortcuts
Shortcuts are provided to easily generate integration tests samples.
- go to `Execute and Debug`.
- select the sample's github workflow.
- run the shortcut.
- select the sample.
- sample is generated at `../jhipster-samples/` folder relative the `generator-jhipster` folder.

Some daily builds samples are available too.

### Generators tests

At test tab you can run and debug individual test.

## Running integration tests locally

You can run the builds locally by following below commands
Expand Down
43 changes: 24 additions & 19 deletions generators/server/templates/.devcontainer/devcontainer.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,39 @@
// Update the VARIANT arg to pick a Java version: 17, 19
// Append -bullseye or -buster to pin to an OS version.
// Use the -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "17",
"VARIANT": "<%= JAVA_VERSION %>-bullseye",
// Options
"INSTALL_MAVEN": "<%= buildToolMaven %>",
"INSTALL_GRADLE": "<%= buildToolGradle %>",
"NODE_VERSION": "lts/*"
// maven and gradle wrappers are used by default, we don't need them installed globally
// "INSTALL_MAVEN": "<%= buildToolMaven %>",
// "INSTALL_GRADLE": "<%= buildToolGradle %>",
"NODE_VERSION": "<%= nodeVersion %>"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"java.home": "/docker-java-home"
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"java.jdt.ls.java.home": "/docker-java-home"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
<%_ if(clientFrameworkAngular) { _%>
"angular.ng-template",
"angular.ng-template",
<%_ } _%>
<%_ if(!skipClient) { _%>
"christian-kohler.npm-intellisense",
"firsttris.vscode-jest-runner",
"ms-vscode.vscode-typescript-tslint-plugin",
"dbaeumer.vscode-eslint",
"christian-kohler.npm-intellisense",
"firsttris.vscode-jest-runner",
"ms-vscode.vscode-typescript-tslint-plugin",
"dbaeumer.vscode-eslint",
<%_ } _%>
"vscjava.vscode-java-pack",
"pivotal.vscode-boot-dev-pack",
"esbenp.prettier-vscode"
],
"vscjava.vscode-java-pack",
"pivotal.vscode-boot-dev-pack",
"esbenp.prettier-vscode"
],
},
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
Expand Down
6 changes: 6 additions & 0 deletions test-integration/scripts/99-print-npm-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e
source $(dirname $0)/00-init-env.sh

echo $JHI_NPM_VERSION

0 comments on commit 298d5c5

Please sign in to comment.