Skip to content

Commit d958032

Browse files
f-gallandAlexRuiz7
andcommitted
Build scripts and GH workflows artifacts naming fix (#112)
* Build scripts and GH workflows artifacts naming fix * Add git to dev docker image * Fixing jobs' inputs and outputs * remove name input from r_assemble.yml * Setting qualifier to 1 when not specified * Add revision flag to scripts and workflow * Fix copying of packages at assemble.sh * Use suffix variable instead of architecture * Fix suffix name in assemble.sh * Mix solutions to comply with the package naming convention * Remove unused code * Use correct name for assembled package Remove code no longer needed * Remove outdated comments --------- Co-authored-by: Álex Ruiz <[email protected]>
1 parent 6e15b18 commit d958032

File tree

6 files changed

+45
-23
lines changed

6 files changed

+45
-23
lines changed

.github/workflows/build.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ jobs:
3636
with:
3737
architecture: ${{ matrix.architecture }}
3838
distribution: ${{ matrix.distribution }}
39+
revision: ${{ inputs.revision }}
3940
name: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ inputs.revision }}-${{ matrix.architecture }}_${{ github.sha }}.${{ matrix.distribution }}
40-
# wazuh-indexer-min_4.8.0-rc1_x64_ff98475f.deb
41-
# TODO arm64 != amd64 (deb), x64 != x86_64 (rpm)
42-
# TODO use short SHA https://stackoverflow.com/a/59819441/13918537
4341

4442
assemble:
4543
needs: [version, build]
@@ -57,4 +55,3 @@ jobs:
5755
architecture: ${{ matrix.architecture }}
5856
distribution: ${{ matrix.distribution }}
5957
min: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ inputs.revision }}-${{ matrix.architecture }}_${{ github.sha }}.${{ matrix.distribution }}
60-
name: wazuh-indexer_${{ needs.version.outputs.version }}-${{ inputs.revision }}-${{ matrix.architecture }}_${{ github.sha }}.${{ matrix.distribution }}

.github/workflows/r_assemble.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ on:
1919
description: The name of the package to download.
2020
required: true
2121
type: string
22-
name:
23-
description: The name of the package to upload.
24-
required: true
25-
type: string
2622

2723
jobs:
2824
r_assemble:
@@ -57,6 +53,6 @@ jobs:
5753
- name: Upload artifact
5854
uses: actions/upload-artifact@v4
5955
with:
60-
name: ${{ inputs.name }}
56+
name: ${{ steps.get_name.outputs.name }}
6157
path: artifacts/dist/${{ steps.get_name.outputs.name }}
6258
if-no-files-found: error

.github/workflows/r_build.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ on:
1515
default: "x64"
1616
required: false
1717
type: string
18+
revision:
19+
type: string
1820
name:
21+
description: The name of the package to upload.
22+
required: true
1923
type: string
2024

2125
jobs:
@@ -37,13 +41,13 @@ jobs:
3741

3842
- name: Run `build.sh`
3943
run: |
40-
bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }}
44+
bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}
4145
42-
# The package's name is stored in artifacts/artifact_name.txt.
46+
# The package's name is stored in artifacts/artifact_min_name.txt.
4347
- name: Set package name
4448
id: get_name
4549
run: |
46-
echo "name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT
50+
echo "name=$(cat artifacts/artifact_min_name.txt)" >> $GITHUB_OUTPUT
4751
4852
- name: Upload artifact
4953
uses: actions/upload-artifact@v4

docker/images/wi-dev.Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ RUN gradle clean
66

77

88
FROM eclipse-temurin:17-jdk-alpine
9-
RUN addgroup -g 1000 wazuh-indexer && \
9+
RUN apk add git && \
10+
addgroup -g 1000 wazuh-indexer && \
1011
adduser -u 1000 -G wazuh-indexer -D -h /home/wazuh-indexer wazuh-indexer && \
1112
chmod 0775 /home/wazuh-indexer && \
1213
chown -R 1000:0 /home/wazuh-indexer
1314
USER wazuh-indexer
1415
COPY --from=builder --chown=1000:0 /home/wazuh-indexer/app /home/wazuh-indexer/app
1516
WORKDIR /home/wazuh-indexer/app
17+
RUN git config --global --add safe.directory /home/wazuh-indexer/app
1618
EXPOSE 9200 9300

scripts/assemble.sh

+13-7
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function clean() {
202202
rm -r "${OUTPUT}/tmp"
203203
echo "After execution, shell path is $(pwd)"
204204
# Store package's name to file. Used by GH Action.
205-
echo "${package_name}" >"${OUTPUT}/artifact_name.txt"
205+
echo "${ARTIFACT_PACKAGE_NAME}" >"${OUTPUT}/artifact_name.txt"
206206
}
207207

208208
# ====
@@ -228,7 +228,7 @@ function assemble_tar() {
228228
cd ..
229229
tar -cvf "${archive_name}-${SUFFIX}.${EXT}" "${archive_name}"
230230
cd ../../..
231-
cp "${TMP_DIR}/${archive_name}-${SUFFIX}.${EXT}" "${OUTPUT}/dist/"
231+
cp "${TMP_DIR}/${archive_name}-${SUFFIX}.${EXT}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"
232232

233233
clean
234234
}
@@ -272,8 +272,10 @@ function assemble_rpm() {
272272

273273
# Move to the root folder, copy the package and clean.
274274
cd ../../..
275+
275276
package_name="wazuh-indexer-${version}-1.${SUFFIX}.${EXT}"
276-
cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/"
277+
278+
cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"
277279

278280
clean
279281
}
@@ -319,9 +321,9 @@ function assemble_deb() {
319321

320322
# Move to the root folder, copy the package and clean.
321323
cd ../../..
322-
package_name="wazuh-indexer_${version}_${SUFFIX}.${EXT}"
324+
package_name="wazuh-indexer_${version}_${SUFFIX}.${EXT}"
323325
# debmake creates the package one level above
324-
cp "${TMP_DIR}/../${package_name}" "${OUTPUT}/dist/"
326+
cp "${TMP_DIR}/../${package_name}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"
325327

326328
clean
327329
}
@@ -333,8 +335,12 @@ function main() {
333335
parse_args "${@}"
334336

335337
echo "Assembling wazuh-indexer for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
336-
# wazuh-indexer-min_4.9.0-1-x64_78fcc3db6a5b470294319e48b58c3d715bee39d1.rpm
337-
ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min.*.$EXT")
338+
339+
ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT")
340+
341+
ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/min_/}
342+
343+
338344

339345
# Create temporal directory and copy the min package there for extraction
340346
TMP_DIR="${OUTPUT}/tmp/${TARGET}"

scripts/build.sh

+20-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ function usage() {
1919
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
2020
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
2121
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
22+
echo -e "-d REVISION\t[Optional] Package revision, default is '1'."
2223
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
2324
echo -e "-h help"
2425
}
2526

26-
while getopts ":h:v:q:s:o:p:a:d:" arg; do
27+
while getopts ":h:v:q:s:o:p:a:d:r:" arg; do
2728
case $arg in
2829
h)
2930
usage
@@ -50,6 +51,9 @@ while getopts ":h:v:q:s:o:p:a:d:" arg; do
5051
d)
5152
DISTRIBUTION=$OPTARG
5253
;;
54+
r)
55+
REVISION=$OPTARG
56+
;;
5357
:)
5458
echo "Error: -${OPTARG} requires an argument"
5559
usage
@@ -91,6 +95,7 @@ cp -r ./build/local-test-repo/org/opensearch "${OUTPUT}"/maven/org
9195
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
9296
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=$(uname -m)
9397
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
98+
[ -z "$REVISION" ] && REVISION="1"
9499

95100
case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
96101
linux-tar-x64|darwin-tar-x64)
@@ -162,8 +167,20 @@ echo "Building OpenSearch for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
162167
# Copy artifact to dist folder in bundle build output
163168
echo "Copying artifact to ${OUTPUT}/dist"
164169
# [[ "$SNAPSHOT" == "true" ]] && IDENTIFIER="-SNAPSHOT"
170+
171+
165172
ARTIFACT_BUILD_NAME=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min.*$SUFFIX.$EXT")
173+
174+
GIT_COMMIT=$(git rev-parse --short HEAD)
175+
176+
WI_VERSION=$(<VERSION)
177+
178+
179+
ARTIFACT_PACKAGE_NAME=wazuh-indexer-min_"$WI_VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
180+
166181
# [WAZUH] Used by the GH workflow to upload the artifact
167-
echo "$ARTIFACT_BUILD_NAME" > "$OUTPUT/artifact_name.txt"
182+
183+
echo "$ARTIFACT_PACKAGE_NAME" > "$OUTPUT/artifact_min_name.txt"
184+
168185
mkdir -p "${OUTPUT}/dist"
169-
cp "distribution/$TYPE/$TARGET/build/distributions/$ARTIFACT_BUILD_NAME" "${OUTPUT}/dist/$ARTIFACT_BUILD_NAME"
186+
cp "distribution/$TYPE/$TARGET/build/distributions/$ARTIFACT_BUILD_NAME" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"

0 commit comments

Comments
 (0)