Skip to content

Commit

Permalink
Set revision to 0 by default.
Browse files Browse the repository at this point in the history
- Reduce inputs for scripts.
- Add script to generate packages' naming convention.
- Make scripts self-aware of the OpenSearch version.
  • Loading branch information
AlexRuiz7 committed Mar 21, 2024
1 parent 2905dbe commit 280aa47
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 27 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
description: "Revision"
type: string
required: true
default: "1"
default: "0"
upload:
description: "Upload ?"
type: bool
Expand Down Expand Up @@ -49,8 +49,8 @@ jobs:
with:
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
revision: ${{ github.event_name == 'push' && '1' || inputs.revision }}
name: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}
revision: ${{ github.event_name == 'push' && '0' || inputs.revision }}
name: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}

assemble:
needs: [version, commit_sha, build]
Expand All @@ -67,7 +67,8 @@ jobs:
with:
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
min: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}
revision: ${{ github.event_name == 'push' && '0' || inputs.revision }}
min: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}

test:
needs: [version, commit_sha, assemble]
Expand All @@ -77,13 +78,13 @@ jobs:
os: [{ suffix: "amd64", ext: "deb" }, { suffix: "x86_64", ext: "rpm" }]
uses: ./.github/workflows/r_test.yml
with:
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}

upload:
needs: [version, commit_sha, test]
# Upload only on 'workflow_dispatch' event and if 'upload=true'
if: ${{ github.event_name == 'push' && inputs.upload }}
uses: ./.github/workflows/r_upload.yml
with:
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}
secrets: inherit
7 changes: 6 additions & 1 deletion .github/workflows/r_assemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
default: "x64"
required: true
type: string
revision:
description: "Any string or number used to extend the package's identifier."
type: string
required: true
default: "0"
min:
description: "The name of the package to download."
required: true
Expand Down Expand Up @@ -45,7 +50,7 @@ jobs:
- name: Run `assemble.sh`
run: |
bash scripts/assemble.sh -v ${{ vars.OPENSEARCH_VERSION }} -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }}
bash scripts/assemble.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} r ${{ inputs.revision }}
# The package's name is stored in artifacts/artifact_name.txt.
- name: Set package name
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/r_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
description: "Any string or number used to extend the package's identifier."
type: string
required: true
default: "1"
default: "0"
name:
description: "The name of the package to upload."
required: true
Expand All @@ -44,7 +44,7 @@ jobs:

- name: Run `build.sh`
run: |
bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}
bash scripts/build.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}
# The package's name is stored in artifacts/artifact_min_name.txt.
- name: Set package name
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/rpm/wazuh-indexer.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

Name: wazuh-indexer
Version: %{_version}
Release: 1
Release: %{_release}
License: Apache-2.0
Summary: An open source distributed and RESTful search engine
URL: https://www.wazuh.com/
Expand Down
30 changes: 14 additions & 16 deletions scripts/assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-v VERSION\t[Required] OpenSearch version."
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-r REVISION\t[Optional] Package revision, default is '0'."
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
echo -e "-h help"
}
Expand All @@ -62,15 +62,12 @@ function usage() {
# ====
function parse_args() {

while getopts ":h:v:o:p:a:d:" arg; do
while getopts ":h:o:p:a:d:r:" arg; do
case $arg in
h)
usage
exit 1
;;
v)
VERSION=$OPTARG
;;
o)
OUTPUT=$OPTARG
;;
Expand All @@ -83,6 +80,9 @@ function parse_args() {
d)
DISTRIBUTION=$OPTARG
;;
r)
REVISION=$OPTARG
;;
:)
echo "Error: -${OPTARG} requires an argument"
usage
Expand All @@ -95,12 +95,6 @@ function parse_args() {
esac
done

if [ -z "$VERSION" ]; then
echo "Error: You must specify the OpenSearch version"
usage
exit 1
fi

[ -z "$OUTPUT" ] && OUTPUT=artifacts

# Assemble distribution artifact
Expand All @@ -109,6 +103,7 @@ function parse_args() {
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=$(uname -m)
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
[ -z "$REVISION" ] && REVISION="0"

case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
linux-tar-x64 | darwin-tar-x64)
Expand Down Expand Up @@ -213,12 +208,14 @@ function enable_performance_analyzer_rca() {
# Install plugins
# ====
function install_plugins() {
local version
version=$(bash scripts/upstream_version.sh)
echo "Install plugins"
maven_repo_local="$HOME/maven"
for plugin in "${plugins[@]}"; do
plugin_from_maven="org.opensearch.plugin:${plugin}:$VERSION.0"
mvn -Dmaven.repo.local=$maven_repo_local org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact=$plugin_from_maven:zip
OPENSEARCH_PATH_CONF=$PATH_CONF "${PATH_BIN}/opensearch-plugin" install --batch --verbose "file:${maven_repo_local}/org/opensearch/plugin/${plugin}/$VERSION.0/${plugin}-$VERSION.0.zip"
plugin_from_maven="org.opensearch.plugin:${plugin}:${version}.0"
mvn -Dmaven.repo.local="${maven_repo_local}" org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact="${plugin_from_maven}:zip"
OPENSEARCH_PATH_CONF=$PATH_CONF "${PATH_BIN}/opensearch-plugin" install --batch --verbose "file:${maven_repo_local}/org/opensearch/plugin/${plugin}/${version}.0/${plugin}-${version}.0.zip"
done
}

Expand Down Expand Up @@ -305,6 +302,7 @@ function assemble_rpm() {
--define "_topdir ${topdir}" \
--define "_version ${version}" \
--define "_architecture ${SUFFIX}" \
--define "_release ${REVISION}" \
${spec_file}

# Move to the root folder, copy the package and clean.
Expand Down Expand Up @@ -359,7 +357,7 @@ function assemble_deb() {
--invoke debuild \
--package wazuh-indexer \
--native \
--revision 1 \
--revision "${REVISION}" \
--upstreamversion "${version}"

# Move to the root folder, copy the package and clean.
Expand All @@ -381,7 +379,7 @@ function main() {

ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT")

ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/min_/}
ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/-min/}

# Create temporal directory and copy the min package there for extraction
TMP_DIR="${OUTPUT}/tmp/${TARGET}"
Expand Down
153 changes: 153 additions & 0 deletions scripts/baptizer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash

set -e

function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-r REVISION\t[Optional] Package revision, default is '0'."
echo -e "-m MIN\t[Optional] Use naming convention for minimal packages, default is 'false'."
echo -e "-x RELEASE\t[Optional] Use release naming convention, default is 'false'."
echo -e "-h help"
}

# ====
# Parse arguments
# ====
function parse_args() {

while getopts ":h:p:a:d:r:mx" arg; do
case $arg in
h)
usage
exit 1
;;
p)
PLATFORM=$OPTARG
;;
a)
ARCHITECTURE=$OPTARG
;;
d)
DISTRIBUTION=$OPTARG
;;
r)
REVISION=$OPTARG
;;
m)
IS_MIN=true
;;
x)
IS_RELEASE=true
;;
:)
echo "Error: -${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done

[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=$(uname -m)
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
[ -z "$REVISION" ] && REVISION="0"
[ -z "$IS_MIN" ] && IS_MIN=false
[ -z "$IS_RELEASE" ] && IS_RELEASE=false

case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
linux-tar-x64 | darwin-tar-x64)
EXT="tar.gz"
SUFFIX="$PLATFORM-x64"
;;
linux-tar-arm64 | darwin-tar-arm64)
EXT="tar.gz"
SUFFIX="$PLATFORM-arm64"
;;
linux-deb-x64)
EXT="deb"
SUFFIX="amd64"
;;
linux-deb-arm64)
EXT="deb"
SUFFIX="arm64"
;;
linux-rpm-x64)
EXT="rpm"
SUFFIX="x86_64"
;;
linux-rpm-arm64)
EXT="rpm"
SUFFIX="aarch64"
;;
windows-zip-x64)
EXT="zip"
SUFFIX="$PLATFORM-x64"
;;
windows-zip-arm64)
EXT="zip"
SUFFIX="$PLATFORM-arm64"
;;
*)
echo "Unsupported platform-distribution-architecture combination: $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
exit 1
;;
esac

}

# ====
# Naming convention for release packages
# ====
function get_release_name() {
if [ "$EXT" = "rpm" ]; then
PACKAGE_NAME=wazuh-indexer-"$VERSION"-"$REVISION"."$SUFFIX"."$EXT"
else
PACKAGE_NAME=wazuh-indexer_"$VERSION"-"$REVISION"_"$SUFFIX"."$EXT"
fi
}

# ====
# Naming convention for pre-release packages
# ====
# TODO wazuh-indexer_$VERSION != wazuh-indexer-$VERSION
function get_devel_name() {
if "$IS_MIN"; then
PACKAGE_NAME=wazuh-indexer-min_"$VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
else
PACKAGE_NAME=wazuh-indexer_"$VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
fi
}

# ====
# Naming convention control function
# ====
function get_package_name() {
if "$IS_RELEASE"; then
get_release_name
else
get_devel_name
fi
}

# ====
# Main function
# ====
function main() {
parse_args "${@}"

get_package_name
echo "$PACKAGE_NAME"
}

GIT_COMMIT=$(git rev-parse --short HEAD)
VERSION=$(<VERSION)
main "${@}"
3 changes: 2 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function usage() {
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-d REVISION\t[Optional] Package revision, default is '1'."
echo -e "-r REVISION\t[Optional] Package revision, default is '0'."
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
echo -e "-h help"
}
Expand Down Expand Up @@ -66,6 +66,7 @@ while getopts ":h:q:s:o:p:a:d:r:b:" arg; do
done

[ -z "$OUTPUT" ] && OUTPUT=artifacts
[ -z "$SNAPSHOT" ] && SNAPSHOT=false

echo "Creating output directory $OUTPUT/maven/org/opensearch if it doesn't already exist"
mkdir -p "$OUTPUT/maven/org/opensearch"
Expand Down

0 comments on commit 280aa47

Please sign in to comment.