diff --git a/.idea/runConfigurations/Dockerfile.xml b/.idea/runConfigurations/Dockerfile.xml new file mode 100644 index 0000000..8e96d17 --- /dev/null +++ b/.idea/runConfigurations/Dockerfile.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e4a3399 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:stable-slim + +WORKDIR /app + +RUN apt-get -y update && \ + apt-get install -y \ + lftp + +COPY init.sh /app/init.sh +COPY LICENSE README.md /app/ + +ENTRYPOINT ["/app/init.sh"] +#RUN ["/bin/sh", "/app/init.sh"] diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..f6e01ce --- /dev/null +++ b/action.yml @@ -0,0 +1,41 @@ +name: 'ftp-deployment-action' +author: 'Israel Roldan ' +description: >- + FTP Deployment: + This GitHub action copy the files via FTP from your Git project to your server in a specific path. +inputs: + server: + description: 'FTP Server' + required: true + user: + description: 'FTP User' + required: true + password: + description: 'FTP Password' + required: true + ssl_allow: + description: 'Allow SSL encryption' + required: false + default: 'false' + use_feat: + description: 'Use FEAT: Determining what extended features the FTP server supports' + required: false + default: 'false' + delete: + description: 'Delete all the files inside of the remote directory.' + required: false + default: 'false' + local_dir: + description: 'Local directory' + required: false + default: '' + remote_dir: + description: 'Remote directory' + required: false + default: '' +runs: + using: 'docker' + image: 'Dockerfile' +branding: + color: 'blue' + icon: 'upload-cloud' diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..30a1a0a --- /dev/null +++ b/init.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# TODO: Add list of excluded delete files in two formats, string separated by space and file. + +INPUT_SERVER=rovisoft.net +INPUT_USER=saint_seiya_kotz@rovisoft.net +INPUT_PASSWORD=OpYfgb5coLyd +INPUT_SSL_ALLOW=false +INPUT_USE_FEAT=false +INPUT_DELETE=true +#INPUT_LOCAL_DIR="" +INPUT_REMOTE_DIR="" + +FTP_SETTINGS='set ftp:ssl-allow '${INPUT_SSL_ALLOW}'; set ftp:use-feat '${INPUT_USE_FEAT}';' +FILE_LIST=remote_ftp_list_$(date "+%s").tmp + +if [ -z "${INPUT_REMOTE_DIR}" ]; then + INPUT_REMOTE_DIR="./" +else + INPUT_REMOTE_DIR="./${INPUT_REMOTE_DIR}/" +fi + +if [ "${INPUT_DELETE}" = "true" ]; then + echo "Deleting from the Server the files and directories with 'lftp'." + echo -e " Path: ${INPUT_REMOTE_DIR}\n" + + rm -f "${FILE_LIST}" + + lftp \ + -u ${INPUT_USER},${INPUT_PASSWORD} \ + ${INPUT_SERVER} \ + -e "${FTP_SETTINGS} renlist > ${FILE_LIST}; quit;" + + sed -i 's/^\.$/..\n/g' "${FILE_LIST}" + sed -i ':begin;N;$!b begin;s/\.\.\n//gm' "${FILE_LIST}" + + DELETE_ITEMS="" + while read -r LINE; do + if [ -n "$LINE" ]; then + DELETE_ITEMS=${DELETE_ITEMS}"${INPUT_REMOTE_DIR}$LINE " + fi + done <"${FILE_LIST}" + + rm -f "${FILE_LIST}" + + lftp \ + -u ${INPUT_USER},${INPUT_PASSWORD} \ + ${INPUT_SERVER} \ + -e "${FTP_SETTINGS} glob rm -rf ${DELETE_ITEMS} 2>/dev/null; quit;" +fi + +pwd +ls -lha .