Skip to content

Commit

Permalink
Modify action to allow uploading artifact to S3 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tostti authored Mar 20, 2024
1 parent c8fa56a commit f066302
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 18 deletions.
93 changes: 80 additions & 13 deletions .github/workflows/build_wazuh_dashboard_with_plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ on:
required: true
default: ''
DISTRIBUTION:
description: 'Distribution to build (deb | rpm | tar | all-platforms)'
type: choice
description: 'Distribution to build'
required: true
options:
- deb
- rpm
- all-platforms
S3UPLOAD:
description: 'Upload to S3'
type: boolean
required: true
default: ''

jobs:
build-plugins:
Expand Down Expand Up @@ -140,6 +148,7 @@ jobs:
echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV
echo "VERSION=$(yarn --silent wzd-version)" >> $GITHUB_ENV
echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download dashboard artifact
uses: actions/download-artifact@v3
Expand All @@ -159,13 +168,12 @@ jobs:
uses: actions/upload-artifact@v3
if: success()
with:
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64.deb
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/deb/output/wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64.deb
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{env.COMMIT_SHA}}.deb
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/deb/output/wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{ env.COMMIT_SHA}}.deb
retention-days: 30


build-rpm-package:
needs: [Build-base-package]
needs: [Build-base-package ]
if: ( contains(inputs.DISTRIBUTION, 'rpm') || contains(inputs.DISTRIBUTION, 'all-platforms') )
runs-on: ubuntu-latest
name: Build rpm package
Expand All @@ -188,6 +196,7 @@ jobs:
echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV
echo "VERSION=$(yarn --silent wzd-version)" >> $GITHUB_ENV
echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download dashboard artifact
uses: actions/download-artifact@v3
Expand All @@ -207,11 +216,10 @@ jobs:
uses: actions/upload-artifact@v3
if: success()
with:
name: wazuh-dashboard-${{ env.VERSION }}-${{ env.REVISION }}.x86_64.rpm
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/rpm/output/wazuh-dashboard-${{ env.VERSION }}-${{ env.REVISION }}.x86_64.rpm
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{env.COMMIT_SHA}}.rpm
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/rpm/output/wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{ env.COMMIT_SHA}}.rpm
retention-days: 30


test-package-deb:
needs: [build-deb-package]
runs-on: ubuntu-latest
Expand All @@ -233,18 +241,19 @@ jobs:
echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV
echo "VERSION=$(yarn --silent wzd-version)" >> $GITHUB_ENV
echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download deb package
uses: actions/download-artifact@v3
with:
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64.deb
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{env.COMMIT_SHA}}.deb
path: ${{ env.CURRENT_DIR }}/dev-tools/test-packages/deb

- name: Run test
run: |
cd ${{ env.CURRENT_DIR }}/dev-tools/test-packages
bash ./test-packages.sh \
-p wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64.deb
-p wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{env.COMMIT_SHA}}.deb
test-package-rpm:
Expand All @@ -268,15 +277,73 @@ jobs:
echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV
echo "VERSION=$(yarn --silent wzd-version)" >> $GITHUB_ENV
echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download rpm package
uses: actions/download-artifact@v3
with:
name: wazuh-dashboard-${{ env.VERSION }}-${{ env.REVISION }}.x86_64.rpm
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{env.COMMIT_SHA}}.rpm
path: ${{ env.CURRENT_DIR }}/dev-tools/test-packages/rpm

- name: Run test
run: |
cd ${{ env.CURRENT_DIR }}/dev-tools/test-packages
ls -lah ${{ env.CURRENT_DIR }}/dev-tools/test-packages/rpm
ls -lah
bash ./test-packages.sh \
-p wazuh-dashboard-${{ env.VERSION }}-${{ env.REVISION }}.x86_64.rpm
-p wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{env.COMMIT_SHA}}.rpm
upload-to-s3:
needs: [test-package-rpm, test-package-deb]
if: |
always() && inputs.S3UPLOAD && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
name: Upload to S3
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'

- name: Setup variables
run: |
echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV
echo "VERSION=$(yarn --silent wzd-version)" >> $GITHUB_ENV
echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_SECRET_KEY }}
aws-region: us-east-1

- name: Download deb package
if: contains(needs.test-package-deb.result, 'success')
uses: actions/download-artifact@v3
with:
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{env.COMMIT_SHA}}.deb
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/deb/

- name: Upload deb to S3
if: contains(needs.test-package-deb.result, 'success')
run: |
echo "Uploading deb package"
aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/deb/wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_amd64_${{env.COMMIT_SHA}}.deb s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/
- name: Download rpm package
if: contains(needs.test-package-rpm.result, 'success')
uses: actions/download-artifact@v3
with:
name: wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{env.COMMIT_SHA}}.rpm
path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/rpm

- name: Upload rpm to S3
if: contains(needs.test-package-rpm.result, 'success')
run: |
aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/rpm/wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x86_64_${{env.COMMIT_SHA}}.rpm s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/
Empty file modified dev-tools/build-packages/build-packages.sh
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion dev-tools/build-packages/deb/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target="wazuh-dashboard"
architecture=$1
revision=$2
version=$3
commit_sha=$4
directory_base="/usr/share/wazuh-dashboard"

# Build directories
Expand All @@ -23,6 +24,7 @@ pkg_name="${target}-${version}"
pkg_path="${build_dir}/${target}"
source_dir="${pkg_path}/${pkg_name}"
deb_file="${target}_${version}-${revision}_${architecture}.deb"
final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.deb"

mkdir -p ${source_dir}/debian

Expand All @@ -48,4 +50,4 @@ debuild --no-lintian -b -uc -us \
-eREVISION="${revision}"

cd ${pkg_path} && sha512sum ${deb_file} >/tmp/${deb_file}.sha512
mv ${pkg_path}/${deb_file} /tmp/
mv ${pkg_path}/${deb_file} /tmp/${final_name}
6 changes: 4 additions & 2 deletions dev-tools/build-packages/deb/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build_docker="yes"
# Constants
deb_amd64_builder="deb_dashboard_builder_amd64"
deb_builder_dockerfile="${current_path}/docker"
commit_sha=$(git rev-parse --short HEAD)

# Paths
current_path="$( cd $(dirname $0) ; pwd -P )"
Expand Down Expand Up @@ -103,7 +104,8 @@ build_deb() {
docker run -t --rm ${volumes} \
-v ${current_path}/../..:/root:Z \
${container_name} ${architecture} \
${revision} ${version} || return 1
${revision} ${version} ${commit_sha}\
|| return 1

echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}."

Expand All @@ -117,7 +119,7 @@ build_deb() {
build() {
build_name="${deb_amd64_builder}"
file_path="../${deb_builder_dockerfile}/${architecture}"
build_deb ${build_name} ${file_path} || return 1
build_deb ${build_name} ${file_path} ${commit_sha}|| return 1
return 0
}

Expand Down
3 changes: 3 additions & 0 deletions dev-tools/build-packages/rpm/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target="wazuh-dashboard"
architecture=$1
revision=$2
version=$3
commit_sha=$4
directory_base="/usr/share/wazuh-dashboard"

# Build directories
Expand All @@ -24,6 +25,7 @@ pkg_name=${target}-${version}
pkg_path="${rpm_build_dir}/RPMS/${architecture}"
file_name="${target}-${version}-${revision}"
rpm_file="${file_name}.${architecture}.rpm"
final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm"

mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

Expand All @@ -48,3 +50,4 @@ cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_
cd ${pkg_path} && sha512sum ${rpm_file} >/tmp/${rpm_file}.sha512

find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /tmp/ \;
mv /tmp/${rpm_file} /tmp/${final_name}
6 changes: 4 additions & 2 deletions dev-tools/build-packages/rpm/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build_docker="yes"
# Constants
rpm_x86_builder="rpm_dashboard_builder_x86"
rpm_builder_dockerfile="${current_path}/docker"
commit_sha=$(git rev-parse --short HEAD)

# Paths
current_path="$( cd $(dirname $0) ; pwd -P )"
Expand Down Expand Up @@ -106,7 +107,8 @@ build_rpm() {
docker run -t --rm ${volumes} \
-v ${current_path}/../..:/root:Z \
${container_name} ${architecture} \
${revision} ${version} || return 1
${revision} ${version} ${commit_sha} \
|| return 1

echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}."

Expand All @@ -120,7 +122,7 @@ build_rpm() {
build() {
build_name="${rpm_x86_builder}"
file_path="../${rpm_builder_dockerfile}/${architecture}"
build_rpm ${build_name} ${file_path} || return 1
build_rpm ${build_name} ${file_path} ${commit_sha}|| return 1
return 0
}

Expand Down

0 comments on commit f066302

Please sign in to comment.