From c44900409c4ab66281e85669ff98d15462442f7d Mon Sep 17 00:00:00 2001 From: vcerenu Date: Tue, 17 Dec 2024 10:11:02 -0300 Subject: [PATCH 1/3] Move action into repository for non verified creator code --- .github/free-disk-space/action.yml | 244 +++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 .github/free-disk-space/action.yml diff --git a/.github/free-disk-space/action.yml b/.github/free-disk-space/action.yml new file mode 100644 index 00000000..fdd4fb0b --- /dev/null +++ b/.github/free-disk-space/action.yml @@ -0,0 +1,244 @@ +name: "Free Disk Space (Ubuntu)" +description: "A configurable GitHub Action to free up disk space on an Ubuntu GitHub Actions runner." + +# See: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#branding + +inputs: + android: + description: "Remove Android runtime" + required: false + default: "true" + dotnet: + description: "Remove .NET runtime" + required: false + default: "true" + haskell: + description: "Remove Haskell runtime" + required: false + default: "true" + + # option inspired by: + # https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh + large-packages: + description: "Remove large packages" + required: false + default: "true" + + docker-images: + description: "Remove Docker images" + required: false + default: "true" + + # option inspired by: + # https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159 + tool-cache: + description: "Remove image tool cache" + required: false + default: "false" + + swap-storage: + description: "Remove swap storage" + required: false + default: "true" + +runs: + using: "composite" + steps: + - shell: bash + run: | + + # ====== + # MACROS + # ====== + + # macro to print a line of equals + # (silly but works) + printSeparationLine() { + str=${1:=} + num=${2:-80} + counter=1 + output="" + while [ $counter -le $num ] + do + output="${output}${str}" + counter=$((counter+1)) + done + echo "${output}" + } + + # macro to compute available space + # REF: https://unix.stackexchange.com/a/42049/60849 + # REF: https://stackoverflow.com/a/450821/408734 + getAvailableSpace() { echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}'); } + + # macro to make Kb human readable (assume the input is Kb) + # REF: https://unix.stackexchange.com/a/44087/60849 + formatByteCount() { echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000'); } + + # macro to output saved space + printSavedSpace() { + saved=${1} + title=${2:-} + + echo "" + printSeparationLine '*' 80 + if [ ! -z "${title}" ]; then + echo "=> ${title}: Saved $(formatByteCount $saved)" + else + echo "=> Saved $(formatByteCount $saved)" + fi + printSeparationLine '*' 80 + echo "" + } + + # macro to print output of dh with caption + printDH() { + caption=${1:-} + + printSeparationLine '=' 80 + echo "${caption}" + echo "" + echo "$ dh -h /" + echo "" + df -h / + echo "$ dh -a /" + echo "" + df -a / + echo "$ dh -a" + echo "" + df -a + printSeparationLine '=' 80 + } + + + + # ====== + # SCRIPT + # ====== + + # Display initial disk space stats + + AVAILABLE_INITIAL=$(getAvailableSpace) + AVAILABLE_ROOT_INITIAL=$(getAvailableSpace '/') + + printDH "BEFORE CLEAN-UP:" + echo "" + + + # Option: Remove Android library + + if [[ ${{ inputs.android }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo rm -rf /usr/local/lib/android || true + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Android library" + fi + + # Option: Remove .NET runtime + + if [[ ${{ inputs.dotnet }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + # https://github.community/t/bigger-github-hosted-runners-disk-space/17267/11 + sudo rm -rf /usr/share/dotnet || true + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED ".NET runtime" + fi + + # Option: Remove Haskell runtime + + if [[ ${{ inputs.haskell }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo rm -rf /opt/ghc || true + sudo rm -rf /usr/local/.ghcup || true + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Haskell runtime" + fi + + # Option: Remove large packages + # REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh + + if [[ ${{ inputs.large-packages }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo apt-get remove -y '^aspnetcore-.*' || echo "::warning::The command [sudo apt-get remove -y '^aspnetcore-.*'] failed to complete successfully. Proceeding..." + sudo apt-get remove -y '^dotnet-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^dotnet-.*' --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y '^llvm-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^llvm-.*' --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y 'php.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y 'php.*' --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y '^mongodb-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mongodb-.*' --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y '^mysql-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mysql-.*' --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-sdk --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get remove -y google-cloud-cli --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-cli --fix-missing] failed to complete successfully. Proceeding..." + sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed to complete successfully. Proceeding..." + sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed to complete successfully. Proceeding..." + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Large misc. packages" + fi + + # Option: Remove Docker images + + if [[ ${{ inputs.docker-images }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo docker image prune --all --force || true + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Docker images" + fi + + # Option: Remove tool cache + # REF: https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159 + + if [[ ${{ inputs.tool-cache }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Tool cache" + fi + + # Option: Remove Swap storage + + if [[ ${{ inputs.swap-storage }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo swapoff -a || true + sudo rm -f /mnt/swapfile || true + free -h + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Swap storage" + fi + + + + # Output saved space statistic + + AVAILABLE_END=$(getAvailableSpace) + AVAILABLE_ROOT_END=$(getAvailableSpace '/') + + echo "" + printDH "AFTER CLEAN-UP:" + + echo "" + echo "" + + echo "/dev/root:" + printSavedSpace $((AVAILABLE_ROOT_END - AVAILABLE_ROOT_INITIAL)) + echo "overall:" + printSavedSpace $((AVAILABLE_END - AVAILABLE_INITIAL)) \ No newline at end of file From 9eff6cd98a558d73a675baead119d5a021013ef0 Mon Sep 17 00:00:00 2001 From: vcerenu Date: Tue, 17 Dec 2024 10:11:46 -0300 Subject: [PATCH 2/3] Move action into repository for non verified creator code --- .github/workflows/deployment-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deployment-test.yml b/.github/workflows/deployment-test.yml index 6a62a2f7..09e297eb 100644 --- a/.github/workflows/deployment-test.yml +++ b/.github/workflows/deployment-test.yml @@ -221,7 +221,7 @@ jobs: ref: ${{ inputs.BRANCH_VERSION }} - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main + uses: ./.github/free-disk-space - name: free disk space run: | From a727851b99e0af9e185010d572d9564d711dd06f Mon Sep 17 00:00:00 2001 From: vcerenu Date: Tue, 17 Dec 2024 10:12:44 -0300 Subject: [PATCH 3/3] Test commit - will be deleted after PR test --- wazuh/indexer_stack/wazuh-dashboard/dashboard-deploy.yaml | 2 +- wazuh/indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml | 2 +- wazuh/wazuh_managers/wazuh-master-sts.yaml | 2 +- wazuh/wazuh_managers/wazuh-worker-sts.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wazuh/indexer_stack/wazuh-dashboard/dashboard-deploy.yaml b/wazuh/indexer_stack/wazuh-dashboard/dashboard-deploy.yaml index dc409dd6..a38ef059 100644 --- a/wazuh/indexer_stack/wazuh-dashboard/dashboard-deploy.yaml +++ b/wazuh/indexer_stack/wazuh-dashboard/dashboard-deploy.yaml @@ -32,7 +32,7 @@ spec: secretName: dashboard-certs containers: - name: wazuh-dashboard - image: 'wazuh/wazuh-dashboard:5.0.0' + image: 'wazuh/wazuh-dashboard:4.9.2' resources: limits: cpu: 500m diff --git a/wazuh/indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml b/wazuh/indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml index a0a43622..fc3c76d9 100644 --- a/wazuh/indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml +++ b/wazuh/indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml @@ -59,7 +59,7 @@ spec: privileged: true containers: - name: wazuh-indexer - image: 'wazuh/wazuh-indexer:5.0.0' + image: 'wazuh/wazuh-indexer:4.9.2' resources: limits: cpu: 500m diff --git a/wazuh/wazuh_managers/wazuh-master-sts.yaml b/wazuh/wazuh_managers/wazuh-master-sts.yaml index b7cf2438..d84de588 100644 --- a/wazuh/wazuh_managers/wazuh-master-sts.yaml +++ b/wazuh/wazuh_managers/wazuh-master-sts.yaml @@ -41,7 +41,7 @@ spec: fsGroup: 101 containers: - name: wazuh-manager - image: 'wazuh/wazuh-manager:5.0.0' + image: 'wazuh/wazuh-manager:4.9.2' resources: limits: cpu: 400m diff --git a/wazuh/wazuh_managers/wazuh-worker-sts.yaml b/wazuh/wazuh_managers/wazuh-worker-sts.yaml index 92557b86..9a780f29 100644 --- a/wazuh/wazuh_managers/wazuh-worker-sts.yaml +++ b/wazuh/wazuh_managers/wazuh-worker-sts.yaml @@ -48,7 +48,7 @@ spec: fsGroup: 101 containers: - name: wazuh-manager - image: 'wazuh/wazuh-manager:5.0.0' + image: 'wazuh/wazuh-manager:4.9.2' resources: limits: cpu: 400m