From 454b03529b2f554c4cd9214917b45415eef6bd91 Mon Sep 17 00:00:00 2001 From: Kostis Papazafeiropoulos Date: Sat, 28 Sep 2024 19:31:11 +0000 Subject: [PATCH] Use prebuilt mc binary in place of docker image Signed-off-by: Kostis Papazafeiropoulos --- .github/workflows/test.yml | 43 +++++++++++++++++++++++++ Dockerfile | 5 --- action.yml | 64 ++++++++++++++++++++++++++++++++------ entrypoint.sh | 58 ---------------------------------- 4 files changed, 97 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5203ebb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,43 @@ +name: Test action + +on: push + +jobs: + upload: + runs-on: self-hosted + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Generate test files + run: | + mkdir -p files + echo "Minio Test 1" > files/test1.txt + echo "Minio Test 2" > files/test2.txt + + - name: Test single file upload + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./files/test1.txt" + remote-path: "github/minio/" + + - name: Test wildcard with extension upload + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./files/*.txt" + remote-path: "github/minio/" + + - name: Test wildcard upload + uses: ./ + with: + url: https://s3.nubificus.com + access-key: ${{ secrets.AWS_ACCESS_KEY }} + secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + local-path: "./files/*" + remote-path: "github/minio/" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 7e631b6..0000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM cloudkernels/mc - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index 70c2742..3d53137 100644 --- a/action.yml +++ b/action.yml @@ -24,13 +24,57 @@ inputs: required: false runs: - using: 'docker' - image: 'Dockerfile' - entrypoint: '/entrypoint.sh' - args: - - ${{ inputs.url }} - - ${{ inputs.access-key }} - - ${{ inputs.secret-key }} - - ${{ inputs.local-path }} - - ${{ inputs.remote-path }} - - ${{ inputs.policy }} + using: composite + steps: + - name: Setup mc + working-directory: /usr/local/bin + run: | + [ -n "$(which mc)" ] && exit 0 + arch=$(dpkg --print-architecture | sed 's/armhf/arm/g') + sudo wget --progres=dot:binary \ + "https://dl.min.io/client/mc/release/linux-${arch}/mc" + sudo chmod +x mc + shell: bash + + - name: Setup s3 alias + run: | + mc alias set s3 "${{ inputs.url }}" \ + "${{ inputs.access-key }}" "${{ inputs.secret-key }}" + shell: bash + + - name: Upload objects + run: | + local_path=${{ inputs.local-path }} + echo "lp: $local_path" + if [ "${local_path#*'*'}" != "$local_path" ]; then + # Handle local_files with wildcards + local_dir=$(dirname "$local_path") + local_files=$(basename "$local_path") + path_depth=$(echo "$local_dir" | awk -F"/" '{print NF-1}') + echo "ld: $local_dir" + echo "lf: $local_files" + echo "pd: $path_depth" + echo "-----------" + IFS=$'\n' + for p in $(find "$local_dir" \ + -name "$local_files" -maxdepth "$path_depth"); do + echo "p: $p" + echo "-----------" + #mc cp -r "$p" "s3/${{ inputs.remote-path }}" + done + unset IFS + else + mc cp -r "$local_path" "s3/${{ inputs.remote-path }}" + fi + shell: bash + + - name: Set policy + run: | + if [ "${{ inputs.policy }}" = 1 ] ; then + echo "Will make ${{ inputs.remote-path }} public" + mc anonymous -r set download "s3/${{ inputs.remote-path }}" + else + echo "Will make ${{ inputs.remote-path }} private" + mc anonymous -r set private "s3/${{ inputs.remote-path }}" || true + fi + shell: bash diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 6328bd7..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -LOG_NAME="minio" - -info() { - [ -t 1 ] && [ -n "$TERM" ] \ - && echo "$(tput setaf 2)[$LOG_NAME]$(tput sgr0) $*" \ - || echo "[$LOG_NAME] $*" -} - -err() { - [ -t 2 ] && [ -n "$TERM" ] \ - && echo -e "$(tput setaf 1)[$LOG_NAME]$(tput sgr0) $*" 1>&2 \ - || echo -e "[$LOG_NAME] $*" 1>&2 -} - -die() { - err "$@" - exit 1 -} - -ok_or_die() { - if [ $? -ne 0 ]; then - die "$1" - fi -} - -if [[ $# -lt 5 ]] ; then - die "Usage: $0 url access_key secret_key local_path remote_path" -fi - -url=$1 -access_key=$2 -secret_key=$3 -local_path=$4 -remote_path=$5 - -info "Will upload $local_path to $remote_path" - -mc alias set s3 "$url" "$access_key" "$secret_key" -ok_or_die "Could not set mc alias" - -IFS=$'\n' -for p in $(eval ls -d -1 "$local_path"); do - mc cp -r "$p" s3/"$remote_path"; -done -unset IFS -ok_or_die "Could not upload object" - -if [[ $# -eq 6 ]] ; then - if [[ $6 -eq 1 ]] ; then - info "Will make $remote_path public" - mc anonymous -r set download s3/"$remote_path" - else - info "Will make $remote_path private" - mc anonymous -r set private s3/"$remote_path" || true - fi -fi