Skip to content

Commit

Permalink
Add workflow for package generation (#65)
Browse files Browse the repository at this point in the history
* Ignore artifacts folder

* Update build script

- Updated to v2.11.0 version.
- Skipped compilation of the plugins
- The artifact nameis sent to a text file, to access it easily in
GitHub Actions.

* Add GH action to build min packages

* Remove commented code

* Remove unused code
  • Loading branch information
AlexRuiz7 committed Mar 8, 2024
1 parent dcb9b6e commit 8efc6e1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 32 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build slim packages

# This workflow runs when any of the following occur:
# - Run manually
on:
workflow_dispatch:


# Used to run locally using https://github.com/nektos/act
env:
ACT:
VERSION: 2.11.0
SNAPSHOT: false
PLATFORM: linux
BUILD: bash scripts/build.sh


jobs:
build:
runs-on: ubuntu-latest
# Permissions to upload the package
permissions:
packages: write
contents: read
strategy:
matrix:
# act is resource-heavy. Avoid running parallel builds with it:
# DISTRIBUTION: [ rpm ]
# ARCHITECTURE: [ x64 ]
DISTRIBUTION: [ tar, rpm, deb ]
ARCHITECTURE: [ x64, arm64 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11

- name: Setup Gradle
uses: gradle/[email protected]

- name: Execute build script
run: |
$BUILD -v $VERSION -s $SNAPSHOT -p $PLATFORM -a ${{ matrix.ARCHITECTURE }} -d ${{ matrix.DISTRIBUTION }}
# The package name is stored in the artifacts/artifact_name.txt file
- name: Read package name
id: package_name
run: |
echo $(ls -la)
echo "package_name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT
echo "$(cat artifacts/artifact_name.txt)"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package_name.outputs.package_name }}
path: artifacts/dist/${{ steps.package_name.outputs.package_name }}
if-no-files-found: error

# assemble:
# release:
19 changes: 0 additions & 19 deletions .github/workflows/gradle_build.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# build files
artifacts/

# intellij files
.idea/
Expand Down
34 changes: 21 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ fi

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

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

# Build project and publish to maven local.
echo "Building and publishing OpenSearch project to Maven Local"
./gradlew publishToMavenLocal -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

# Publish to existing test repo, using this to stage release versions of the artifacts that can be released from the same build.
echo "Publishing OpenSearch to Test Repository"
./gradlew publishNebulaPublicationToTestRepository -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

# Copy maven publications to be promoted
echo "Copying Maven publications to $OUTPUT/maven/org"
cp -r ./build/local-test-repo/org/opensearch "${OUTPUT}"/maven/org

# Assemble distribution artifact
Expand All @@ -103,6 +107,20 @@ case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
TARGET="$PLATFORM-arm64-$PACKAGE"
SUFFIX="$PLATFORM-arm64"
;;
linux-deb-x64)
PACKAGE="deb"
EXT="deb"
TYPE="packages"
TARGET="deb"
SUFFIX="amd64"
;;
linux-deb-arm64)
PACKAGE="deb"
EXT="deb"
TYPE="packages"
TARGET="arm64-deb"
SUFFIX="arm64"
;;
linux-rpm-x64)
PACKAGE="rpm"
EXT="rpm"
Expand Down Expand Up @@ -142,20 +160,10 @@ echo "Building OpenSearch for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
./gradlew :distribution:$TYPE:$TARGET:assemble -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

# Copy artifact to dist folder in bundle build output
echo "Copying artifact to ${OUTPUT}/dist"
[[ "$SNAPSHOT" == "true" ]] && IDENTIFIER="-SNAPSHOT"
ARTIFACT_BUILD_NAME=`ls distribution/$TYPE/$TARGET/build/distributions/ | grep "opensearch-min.*$SUFFIX.$EXT"`
# [WAZUH] Used by the GH workflow to upload the artifact
echo "$ARTIFACT_BUILD_NAME" > "$OUTPUT/artifact_name.txt"
mkdir -p "${OUTPUT}/dist"
cp distribution/$TYPE/$TARGET/build/distributions/$ARTIFACT_BUILD_NAME "${OUTPUT}"/dist/$ARTIFACT_BUILD_NAME

echo "Building core plugins..."
mkdir -p "${OUTPUT}/core-plugins"
cd plugins
../gradlew assemble -Dbuild.snapshot="$SNAPSHOT" -Dbuild.version_qualifier=$QUALIFIER
cd ..
for plugin in plugins/*; do
PLUGIN_NAME=$(basename "$plugin")
if [ -d "$plugin" ] && [ "examples" != "$PLUGIN_NAME" ]; then
PLUGIN_ARTIFACT_BUILD_NAME=`ls "$plugin"/build/distributions/ | grep "$PLUGIN_NAME.*$IDENTIFIER.zip"`
cp "$plugin"/build/distributions/"$PLUGIN_ARTIFACT_BUILD_NAME" "${OUTPUT}"/core-plugins/"$PLUGIN_ARTIFACT_BUILD_NAME"
fi
done

0 comments on commit 8efc6e1

Please sign in to comment.