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

Add dockerized yarn runner #5305

Merged
merged 9 commits into from
Mar 23, 2023
Merged

Add dockerized yarn runner #5305

merged 9 commits into from
Mar 23, 2023

Conversation

AlexRuiz7
Copy link
Member

Description

This pull request adds a runner, which essentially is a dockerized environment to run any supported yarn command, for example to run the unit tests of the app, or to build it.

The runner is meant to be run locally, uses our development images, and its usage is properly documented.

The preferred way to run it is using the Node scripts, which automatically generates the environment. However, the docker-compose project can be started directly, in such case, the launch parameters must be provided.

Issues Resolved

None

Evidence

  • Build
    image
  • Tests
    image
    image

Test

Run the runner using the different ways to do it:

Using the script (automatic environment generation):

node scripts/runner build
node scripts/runner test [<jest_cli_options>]
yarn build:runner
yarn test:jest:runner [<jest_cli_options>]

The information available in the package.json is used to generate the environment, such as the platform version. This can be overridden using environment variables. See the docker-compose.yml for more information.

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@AlexRuiz7 AlexRuiz7 requested a review from a team as a code owner March 17, 2023 13:40
@AlexRuiz7 AlexRuiz7 self-assigned this Mar 17, 2023
@AlexRuiz7 AlexRuiz7 added type/enhancement Enhancement issue automation automation labels Mar 17, 2023
@github-actions
Copy link
Contributor

Code coverage (Jest) % values
Statements 8.82% ( 3260 / 36932 )
Branches 4.52% ( 1296 / 28650 )
Functions 7.66% ( 701 / 9145 )
Lines 8.88% ( 3143 / 35366 )

Copy link
Member

@yenienserrano yenienserrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: ✔️
Test: ✔️

Screenshot

Build:

image

image

Test:

image

image

image

@Desvelao
Copy link
Member

Desvelao commented Mar 23, 2023

Wazuh dashboard

Legend:
⚫: none
🟢: pass
🟡: warning
🔴: fail
⚪: not applicable

Other

Test Result
Build a package using the dockerized runner through node scripts/runner build 🟢
Run the jest tests using the dockerized runner through node scripts/runner test 🟢
Build a package using the dockerized runner through yarn build:runner 🟢
Run the jest tests using the dockerized runner through yarn test:jest:runner 🟢

Details

🟢 Build a package using the dockerized runner through node scripts/runner build
[vagrant@localhost wazuh-kibana-app]$ node scripts/runner build
APP: osd
VERSION: 2.6.0
REPO: /home/vagrant/wazuh-kibana-app
CMD: plugin-helpers build
ARGS: --opensearch-dashboards-version=2.6.0
 Container runner  Created

Attaching to runner

runner  | yarn install v1.22.19

runner  | [1/4] Resolving packages...

runner  | success Already up-to-date.

runner  | Done in 0.32s.

runner  | yarn run v1.22.19

runner  | $ node ../../scripts/plugin_helpers build --opensearch-dashboards-version=2.6.0

runner  |  info Loaded config file from [/home/node/kbn/plugins/wazuh/.opensearch_dashboards-plugin-helpers.json]
runner  |  info deleting the build and target directories

runner  |  info running @osd/optimizer

runner  |  │ info initialized, 0 bundles cached

runner  |  │ info starting worker [1 bundle]

runner  |  │ warn worker stderr Browserslist: caniuse-lite is outdated. Please run:
runner  |  │ warn worker stderr   npx browserslist@latest --update-db
runner  |  │ warn worker stderr   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

runner  |  │ succ 1 bundles compiled successfully after 470.9 sec

runner  |  info copying assets from `public/assets` to build

runner  |  info copying server source into the build and converting with babel

runner  | Browserslist: caniuse-lite is outdated. Please run:
runner  |   npx browserslist@latest --update-db
runner  |   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

runner  |  info running yarn to install dependencies

runner  |  info compressing plugin into [wazuh-2.6.0.zip]

runner  |  info cleaning up compression temporary artifacts

runner  | Done in 489.01s.

runner exited with code 0
[vagrant@localhost wazuh-kibana-app]$ ls build/
wazuh-2.6.0.zip
🟢 Run the jest tests using the dockerized runner through node scripts/runner test
[vagrant@localhost wazuh-kibana-app]$ node scripts/runner test
APP: osd
VERSION: 2.6.0
REPO: /home/vagrant/wazuh-kibana-app
CMD: test:jest
ARGS: --runInBand
...
runner  | Test Suites: 6 skipped, 63 passed, 63 of 69 total
runner  | Tests:       36 skipped, 901 passed, 937 total
runner  | Snapshots:   37 passed, 37 total
runner  | Time:        207.171 s
runner  | Ran all test suites.

runner  | Done in 210.12s.

runner exited with code 0
🟢 Build a package using the dockerized runner through yarn build:runner
[vagrant@localhost wazuh-kibana-app]$ yarn build:runner
yarn run v1.22.19
$ node scripts/runner build
APP: osd
VERSION: 2.6.0
REPO: /home/vagrant/wazuh-kibana-app
CMD: plugin-helpers build
ARGS: --opensearch-dashboards-version=2.6.0
 Container runner  Created

Attaching to runner

runner  | yarn install v1.22.19

runner  | [1/4] Resolving packages...

runner  | success Already up-to-date.

runner  | Done in 0.32s.

runner  | yarn run v1.22.19

runner  | $ node ../../scripts/plugin_helpers build --opensearch-dashboards-version=2.6.0

runner  |  info Loaded config file from [/home/node/kbn/plugins/wazuh/.opensearch_dashboards-plugin-helpers.json]
runner  |  info deleting the build and target directories

runner  |  info running @osd/optimizer

runner  |  │ info initialized, 0 bundles cached

runner  |  │ info starting worker [1 bundle]

runner  |  │ warn worker stderr Browserslist: caniuse-lite is outdated. Please run:
runner  |  │ warn worker stderr   npx browserslist@latest --update-db
runner  |  │ warn worker stderr   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

runner  |  │ succ 1 bundles compiled successfully after 480.9 sec

runner  |  info copying assets from `public/assets` to build

runner  |  info copying server source into the build and converting with babel

runner  | Browserslist: caniuse-lite is outdated. Please run:
runner  |   npx browserslist@latest --update-db
runner  |   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

runner  |  info running yarn to install dependencies

runner  |  info compressing plugin into [wazuh-2.6.0.zip]

runner  |  info cleaning up compression temporary artifacts

runner  | Done in 499.52s.

runner exited with code 0

Done in 500.90s.
[vagrant@localhost wazuh-kibana-app]$ ls build/
wazuh-2.6.0.zip
🟢 Run the jest tests using the dockerized runner through yarn test:jest:runner
[vagrant@localhost wazuh-kibana-app]$ yarn test:jest:runner
yarn run v1.22.19
$ node scripts/runner test
APP: osd
VERSION: 2.6.0
REPO: /home/vagrant/wazuh-kibana-app
CMD: test:jest
ARGS: --runInBand
...
runner  | Test Suites: 6 skipped, 63 passed, 63 of 69 total
runner  | Tests:       36 skipped, 901 passed, 937 total
runner  | Snapshots:   37 passed, 37 total
runner  | Time:        211.848 s
runner  | Ran all test suites.

runner  | Done in 214.59s.

runner exited with code 0

Copy link
Member

@Desvelao Desvelao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review:

🟢 code
🟢 test #5305 (comment)

@AlexRuiz7 AlexRuiz7 merged commit c7d97f2 into 4.5 Mar 23, 2023
@AlexRuiz7 AlexRuiz7 deleted the tools/add-runner branch March 23, 2023 10:24
@github-actions
Copy link
Contributor

The backport to 4.5-7.10 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.5-7.10 4.5-7.10
# Navigate to the new working tree
cd .worktrees/backport-4.5-7.10
# Create a new branch
git switch --create backport-5305-to-4.5-7.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c7d97f2d71fbe772541918953e79310d196dce50
# Push it to GitHub
git push --set-upstream origin backport-5305-to-4.5-7.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.5-7.10

Then, create a pull request where the base branch is 4.5-7.10 and the compare/head branch is backport-5305-to-4.5-7.10.

@github-actions
Copy link
Contributor

The backport to 4.5-7.16 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.5-7.16 4.5-7.16
# Navigate to the new working tree
cd .worktrees/backport-4.5-7.16
# Create a new branch
git switch --create backport-5305-to-4.5-7.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c7d97f2d71fbe772541918953e79310d196dce50
# Push it to GitHub
git push --set-upstream origin backport-5305-to-4.5-7.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.5-7.16

Then, create a pull request where the base branch is 4.5-7.16 and the compare/head branch is backport-5305-to-4.5-7.16.

AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
Add dockerized yarn runner (#5305)

* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
AlexRuiz7 added a commit that referenced this pull request Mar 23, 2023
Add dockerized yarn runner (#5305)

* Add Dockerized Jest runner

* Add possibility to pass Jest CLI options to the runner

* Fix buildJestArgs function to actually include default Jest options

Duplicated values are also dropped now

* Refactor the test runner to allow building packages

* Extend documentation of the runner

* Formatter and bug fix

Fixes a bug where the environment variables were not read

* Fix docker compose command

* Allow passing additional arguments which do not start with --

---------

Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com>
(cherry picked from commit c7d97f2)
@AlexRuiz7 AlexRuiz7 mentioned this pull request Mar 28, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants