From 89bbd3ead28f7e30e61b3ff860eb53cf1b1f77a0 Mon Sep 17 00:00:00 2001 From: Kostis Papazafeiropoulos Date: Fri, 27 Sep 2024 20:34:21 +0000 Subject: [PATCH] Use prebuilt mc binary in place of docker image Signed-off-by: Kostis Papazafeiropoulos --- Dockerfile | 5 ---- action.yml | 45 ++++++++++++++++++++++++++++-------- entrypoint.sh | 63 --------------------------------------------------- 3 files changed, 36 insertions(+), 77 deletions(-) delete mode 100644 Dockerfile delete mode 100755 entrypoint.sh 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 4ebac66..ac5c1d6 100644 --- a/action.yml +++ b/action.yml @@ -21,12 +21,39 @@ inputs: required: true runs: - using: 'docker' - image: 'Dockerfile' - entrypoint: '/entrypoint.sh' - args: - - ${{ inputs.url }} - - ${{ inputs.access-key }} - - ${{ inputs.secret-key }} - - ${{ inputs.local-path }} - - ${{ inputs.remote-path }} + using: composite + steps: + - name: Setup mc + working-directory: /usr/local/bin + run: | + [ -n "$(which mc)" ] && exit 0 + arch=$(dpkg --print-architecture) + sudo wget --progres=dot:mega \ + "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: Download objects + run: | + remote_path=${{ inputs.remote-path }} + if [ "${remote_path#*'*'}" != "$remote_path" ]; then + # Handle remote_dir with wildcard + remote_dir=$(dirname "$remote_path") + remote_files=$(basename "$remote_path") + path_depth=$(echo "$remote_dir" | awk -F"/" '{print NF-1}') + IFS=$'\n' + for p in $(mc find "s3/$remote_dir" \ + --name "$remote_files" --maxdepth "$path_depth"); do + mc cp -r "$p" "${{ inputs.local-path }}"; + done + unset IFS + else + mc cp -r "s3/$remote_path ${{ inputs.local-path }}" + fi + shell: bash diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 5ea944b..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,63 +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 [[ $# -ne 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 fetch $remote_path to $local_path" - -mc alias set s3 "$url" "$access_key" "$secret_key" -ok_or_die "Could not set mc alias" - -if [ "${remote_path#*'*'}" != "$remote_path" ]; then - # Handle remote_dir with wildcard - remote_dir=$(dirname "$remote_path") - remote_files=$(basename "$remote_path") - path_depth=$(echo "$remote_dir" | awk -F"/" '{print NF-1}') - IFS=$'\n' - for p in $(mc find "s3/$remote_dir" \ - --name "$remote_files" --maxdepth "$path_depth"); do - mc cp -r "$p" "$local_path"; - done - unset IFS -else - mc cp -r "s3/$remote_path $local_path" -fi -ok_or_die "Could not fetch object" - -# Fix owner of local path -LOCAL_UID="${ACTION_UID:-"$(stat -c %u .)"}" -LOCAL_GID="${ACTION_GID:-"$(stat -c %g .)"}" -info "Setting owner/group of $local_path to ${LOCAL_UID:-root}:${LOCAL_GID:-root}" -chown -R "${LOCAL_UID:-root}:${LOCAL_GID:-root}" "$local_path"