Skip to content

Commit a69ab75

Browse files
AlexRuiz7Desvelao
andauthored
Enhance and fix some GitHub actions workflows (#4680) (#4695)
- Create a reusable workflow that uses the prebuit Docker images of development mode to mount the plugin source code and run a command. - Create a workflow to build a package on demand - Create a workflow to check the unit test with jest. Enhanced to use the expected platform. - Create a wildcard workflow to run a command in a development mode * Remove .github/workflows/check-code-integrity.yml Co-authored-by: Alex Ruiz Becerra <alejandro.ruiz.becerra@wazuh.com> (cherry picked from commit abee739) Co-authored-by: Antonio <34042064+Desvelao@users.noreply.github.com>
1 parent 1d38390 commit a69ab75

7 files changed

+335
-117
lines changed

.github/workflows/build.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow builds a production-ready package from the given Git reference.
2+
# Any branch, tag or commit SHA existing in the origin can be used.
3+
#
4+
# This workflow is based on the `dev-environment` workflow.
5+
6+
name: Build
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
reference:
12+
required: true
13+
type: string
14+
default: master
15+
description: Source code reference (branch, tag or commit SHA)
16+
17+
jobs:
18+
# Build an app package from the given source code reference.
19+
build:
20+
name: Build app package
21+
uses: ./.github/workflows/dev-environment.yml
22+
with:
23+
reference: ${{ github.event.inputs.reference }}
24+
command: 'yarn build'
25+
archive_name: 'wazuh-package'
26+
archive_path: './wazuh/build'
27+
secrets: inherit

.github/workflows/create-wazuh-packages.yml

-44
This file was deleted.

.github/workflows/dev-environment.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# This workflow downloads the source code at the given git reference
2+
# (branch, tag or commit), an sets up an environment (Kibana or OpenSearch)
3+
# to run this code and a command (build, test, ...).
4+
#
5+
# This workflow is used as a base for other workflows.
6+
7+
name: Base workflow - Environment
8+
9+
on:
10+
workflow_call:
11+
inputs:
12+
reference:
13+
required: true
14+
type: string
15+
default: master
16+
description: Source code reference (branch, tag or commit SHA).
17+
command:
18+
required: true
19+
type: string
20+
default: 'yarn build'
21+
description: Command to run in the environment
22+
docker_run_extra_args:
23+
type: string
24+
default: ''
25+
description: Additional paramaters for the docker run command.
26+
required: false
27+
artifact_name:
28+
type: string
29+
default: ''
30+
description: Artifact name (will be automatically suffixed with .zip)
31+
required: false
32+
artifact_path:
33+
type: string
34+
default: ''
35+
description: Folder to include in the archive.
36+
required: false
37+
notify_jest_coverage_summary:
38+
type: boolean
39+
default: false
40+
required: false
41+
42+
jobs:
43+
# Deploy the plugin in a development environment and run a command
44+
# using a pre-built Docker image, hosted in Quay.io.
45+
deploy_and_run_command:
46+
name: Deploy and run command
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Step 01 - Download the plugin's source code
50+
uses: actions/checkout@v3
51+
with:
52+
ref: ${{ inputs.reference }}
53+
path: wazuh
54+
55+
# Fix source code ownership so the internal user of the Docker
56+
# container is also owner.
57+
- name: Step 02 - Change code ownership
58+
run: sudo chown 1000:1000 -R wazuh;
59+
60+
- name: Step 03 - Set up the environment and run the command
61+
run: |
62+
# Detect which platform to use from source code
63+
platform=kbn;
64+
echo "Detecting platform [kbn, osd]...";
65+
find wazuh/opensearch_dashboards.json && { platform=osd; };
66+
echo "Platform is $platform";
67+
68+
# Read the platform version from the package.json file
69+
echo "Reading the platform version from the package.json...";
70+
# Support plugins whose version is defined under pluginPlatform or Kibana properties
71+
platform_version=$(jq -r '.pluginPlatform.version, .kibana.version | select(. != null)' wazuh/package.json);
72+
echo "Plugin platform version: $platform_version";
73+
74+
# Set the environment variable to the correct platform
75+
[ "$platform" = "kbn" ] && { docker_env_plugin_platform="KIBANA_VERSION"; };
76+
[ "$platform" = "osd" ] && { docker_env_plugin_platform="OPENSEARCH_DASHBOARDS_VERSION"; };
77+
78+
# Up the environment and run the command
79+
docker run -t --rm \
80+
-e ${docker_env_plugin_platform}=${platform_version} \
81+
-v `pwd`/wazuh:/home/node/kbn/plugins/wazuh \
82+
${{ inputs.docker_run_extra_args }} \
83+
quay.io/wazuh/${platform}-dev:${platform_version} \
84+
bash -c '
85+
yarn config set registry https://registry.yarnpkg.com;
86+
cd /home/node/kbn/plugins/wazuh && yarn && ${{ inputs.command }};
87+
'
88+
89+
- name: Step 04 - Upload artifact to GitHub
90+
if: ${{ inputs.artifact_name && inputs.artifact_path }}
91+
uses: actions/upload-artifact@v3
92+
with:
93+
name: ${{ inputs.artifact_name }}
94+
path: ${{ inputs.artifact_path }}
95+
96+
- name: Step 05 - Upload coverage results to GitHub
97+
if: ${{ inputs.notify_jest_coverage_summary && github.event_name == 'pull_request' }}
98+
uses: AthleticNet/comment-test-coverage@1.2.2
99+
with:
100+
token: ${{ secrets.GITHUB_TOKEN }}
101+
path: ./wazuh/target/test-coverage/coverage-summary.json
102+
title: "Code coverage (Jest)"

.github/workflows/playground.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow allows you to deploy a development environment and run any
2+
# npm / yarn available command for testing purposes.
3+
# Any branch, tag or commit SHA existing in the origin can be used.
4+
#
5+
# This workflow is based on the `dev-environment` workflow.
6+
7+
name: Playground
8+
9+
on:
10+
workflow_dispatch:
11+
inputs:
12+
reference:
13+
required: true
14+
type: string
15+
default: master
16+
description: Source code reference (branch, tag or commit SHA).
17+
command:
18+
required: true
19+
type: string
20+
default: 'yarn test:jest'
21+
description: Command to run in the environment
22+
docker_run_extra_args:
23+
type: string
24+
default: ''
25+
description: Additional paramaters for the docker run command.
26+
required: false
27+
artifact_name:
28+
type: string
29+
default: ''
30+
description: Artifact name (will be automatically suffixed with .zip)
31+
required: false
32+
artifact_path:
33+
type: string
34+
default: ''
35+
description: Folder to include in the archive.
36+
required: false
37+
38+
jobs:
39+
deploy_and_run_command:
40+
name: Deploy and run command
41+
uses: ./.github/workflows/dev-environment.yml
42+
with:
43+
reference: ${{ github.event.inputs.reference }}
44+
command: ${{ github.event.inputs.command }}
45+
docker_run_extra_args: ${{ github.event.inputs.docker_run_extra_args }}
46+
artifact_name: ${{ github.event.inputs.artifact_name }}
47+
artifact_path: ${{ github.event.inputs.artifact_path }}
48+
secrets: inherit

.github/workflows/unit-test.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow run the unit tests of the app using Jest.
2+
# Any branch, tag or commit SHA existing in the origin can be used.
3+
#
4+
# This workflow is based on the `dev-environment` workflow.
5+
#
6+
# Jest is a third-party software https://jestjs.io/
7+
8+
9+
name: Run unit test
10+
11+
on:
12+
workflow_dispatch:
13+
inputs:
14+
reference:
15+
required: true
16+
type: string
17+
default: master
18+
description: Source code reference (branch, tag or commit SHA)
19+
command:
20+
required: true
21+
type: choice
22+
default: 'yarn test:jest'
23+
description: Select the type of test to run.
24+
options:
25+
- 'yarn test:jest'
26+
pull_request:
27+
branches:
28+
- 'master'
29+
- '*.*-*.*'
30+
- '*.*-*.*-wzd'
31+
32+
jobs:
33+
# Run unit tests with Jest
34+
test:
35+
name: Run unit tests
36+
uses: ./.github/workflows/dev-environment.yml
37+
with:
38+
reference: ${{ github.event.inputs.reference }}
39+
command: ${{ github.event.inputs.command || 'yarn test:jest' }}
40+
notify_jest_coverage_summary: true
41+
secrets: inherit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# This is a basic workflow that is manually triggered
2+
# @deprecated Official Wazuh images must be used instead: https://hub.docker.com/r/wazuh/wazuh
3+
4+
name: Manual workflow build and push docker image
5+
6+
# Controls when the action will run. Workflow runs when manually triggered using the UI
7+
# or API.
8+
on:
9+
workflow_dispatch:
10+
# Inputs the workflow accepts.
11+
inputs:
12+
build-manager-image:
13+
type: boolean
14+
description: 'Build manager image'
15+
required: false
16+
wazuh-manager-version:
17+
description: 'Wazuh manager version'
18+
default: 'v4.3.8'
19+
required: false
20+
elastic-manager-version:
21+
description: 'Elastic manager version'
22+
default: '7.17.0'
23+
required: false
24+
25+
build-agent-image:
26+
type: boolean
27+
description: 'Build agent image'
28+
required: false
29+
wazuh-agent-version:
30+
description: 'Wazuh agent version'
31+
default: 'v4.3.8'
32+
required: false
33+
elastic-agent-version:
34+
description: 'Elastic manager version'
35+
default: '7.17.0'
36+
required: false
37+
38+
build-cypress-image:
39+
type: boolean
40+
description: 'Build cypress image'
41+
required: false
42+
ubuntu-cypress-branch:
43+
description: 'Ubuntu cypress branch: Branch in which the image will be created, this branch must correspond to the wazuh-kibana-app project. It will take the tests written in the wazuh-kibana-app/test/cypress directory.'
44+
default: 'main'
45+
required: false
46+
image-cypress-version:
47+
description: 'Image cypress version'
48+
default: '3.0.0'
49+
required: false
50+
51+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
52+
jobs:
53+
job-build-manager-image:
54+
if: ${{ github.event.inputs.build-manager-image == 'true' }}
55+
name: Run build and push manager image
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Step 01 - Download wazuh-kibana-app
59+
uses: actions/checkout@v2
60+
with:
61+
path: wazuh-kibana-app
62+
- name: Step 02 - Login to quay.io
63+
run: |
64+
docker login -u=${{ secrets.QUAYIO_USERNAME }} -p=${{ secrets.QUAYIO_TOKEN }} quay.io
65+
- name: Step 03 - Build image
66+
run: |
67+
cd ${{ github.workspace }}/wazuh-kibana-app/test/cypress/images/wazuh_manager_filebeat_sources_cmake
68+
docker build -t quay.io/wazuh/wazuh-manager-image:${{ github.event.inputs.wazuh-manager-version }}-${{ github.event.inputs.elastic-manager-version }} \
69+
--build-arg WAZUH_VERSION=${{ github.event.inputs.wazuh-manager-version }} \
70+
--build-arg FILEBEAT_VERSION=${{ github.event.inputs.elastic-manager-version }} \
71+
--build-arg FILEBEAT_WAZUH_TEMPLATE_URL=https://raw.githubusercontent.com/wazuh/wazuh/4.0/extensions/elasticsearch/7.x/wazuh-template.json \
72+
--build-arg FILEBEAT_WAZUH_MODULE_URL=https://packages.wazuh.com/4.x/filebeat/wazuh-filebeat-0.1.tar.gz .
73+
- name: Step 04 - Push image to quay.io
74+
run: |
75+
docker push quay.io/wazuh/wazuh-manager-image:${{ github.event.inputs.wazuh-manager-version }}-${{ github.event.inputs.elastic-manager-version }}
76+
77+
job-build-agent-image:
78+
if: ${{ github.event.inputs.build-agent-image == 'true' }}
79+
name: Run build and push agent image
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Step 01 - Download wazuh-kibana-app
83+
uses: actions/checkout@v2
84+
with:
85+
path: wazuh-kibana-app
86+
- name: Step 02 - Login to quay.io
87+
run: |
88+
docker login -u=${{ secrets.QUAYIO_USERNAME }} -p=${{ secrets.QUAYIO_TOKEN }} quay.io
89+
- name: Step 03 - Build image
90+
run: |
91+
cd ${{ github.workspace }}/wazuh-kibana-app/test/cypress/images/wazuh_agent_ubuntu_sources_cmake
92+
docker build -t quay.io/wazuh/wazuh-agent-image:${{ github.event.inputs.wazuh-agent-version }} \
93+
--build-arg WAZUH_VERSION=${{ github.event.inputs.wazuh-agent-version }} .
94+
- name: Step 04 - Push image to quay.io
95+
run: |
96+
docker push quay.io/wazuh/wazuh-agent-image:${{ github.event.inputs.wazuh-agent-version }}
97+
98+
job-build-cypress-image:
99+
if: ${{ github.event.inputs.build-cypress-image == 'true' }}
100+
name: Run build and push cypress image
101+
runs-on: ubuntu-latest
102+
steps:
103+
- name: Step 01 - Download wazuh-kibana-app
104+
uses: actions/checkout@v2
105+
with:
106+
path: wazuh-kibana-app
107+
- name: Step 02 - Login to quay.io
108+
run: |
109+
docker login -u=${{ secrets.QUAYIO_USERNAME }} -p=${{ secrets.QUAYIO_TOKEN }} quay.io
110+
- name: Step 03 - Build image
111+
run: |
112+
cd ${{ github.workspace }}/wazuh-kibana-app/test/cypress/images/ubuntu-cypress
113+
docker build -t quay.io/wazuh/wazuh-ubuntu-cypress:${{ github.event.inputs.image-cypress-version }} \
114+
--build-arg UBUNTU_CYPRESS_BRANCH=${{ github.event.inputs.ubuntu-cypress-branch }} .
115+
- name: Step 04 - Push image to quay.io
116+
run: |
117+
docker push quay.io/wazuh/wazuh-ubuntu-cypress:${{ github.event.inputs.image-cypress-version }}

0 commit comments

Comments
 (0)